Created
May 26, 2013 19:43
-
-
Save lukemelia/5653804 to your computer and use it in GitHub Desktop.
converting from our connect_controllers style to needs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/env ruby | |
require 'rubygems' | |
require 'active_support' | |
require 'active_support/core_ext/string' | |
cc_map = { | |
page: ['feedEntries', 'mediaWell', 'videosWell', 'crowdPicsImages', 'user', 'videos'], | |
cover: ['yapp'], | |
pageEdit: ['page'], | |
coverEdit: ['cover'], | |
subpageEdit: ['yapp', 'subpage', 'page'], | |
more: ['yapp'], | |
feeds: ['page'], | |
feedEntries: ['feeds', 'page'], | |
crowdPicsImages: ['page', 'crowdPicsWell', 'user'], | |
videos: ['page'], | |
belowPageEditorProgress: ['page'], | |
pageTabBar: ['yapp', 'page'], | |
subpageTabBar: ['yapp', 'page'], | |
moreTabBar: ['yapp', 'page'], | |
pageTitleBar: ['page'], | |
pageEditTitleBar: ['page', 'pageEdit'], | |
coverEditTitleBar: ['cover', 'coverEdit'], | |
subpageTitleBar: ['subpage'], | |
subpageEditTitleBar: ['subpage', 'subpageEdit'], | |
pageControls: ['page', 'cover', 'coverEdit'], | |
saveReminder: ['user', 'authPopup'] | |
} | |
def filename(controller_name) | |
filename = "app/lib/controllers/#{controller_name.to_s.underscore}.coffee" | |
if controller_name =~ /TitleBar/ | |
filename = "app/lib/controllers/title_bar.coffee" | |
end | |
if controller_name =~ /TabBar/ | |
filename = "app/lib/controllers/tab_bar.coffee" | |
end | |
filename | |
end | |
def add_needs_line(lines, controller_name, needs_controller_names) | |
class_name = 'Editor.' + controller_name.to_s.camelize + 'Controller' | |
line = lines.detect do |line| | |
line =~ /#{class_name}/ | |
end | |
class_line_index = lines.index(line) | |
needs_line = " needs: #{needs_controller_names.inspect}" | |
lines.insert(class_line_index + 1, needs_line) | |
end | |
def rewrite_controller_property_line(lines, needs_controller_name) | |
line = lines.detect do |line| | |
line =~ /^\s+#{needs_controller_name}Controller:/ | |
end | |
line.replace(" #{needs_controller_name}Controller: Em.computed.alias('controllers.#{needs_controller_name}')") | |
end | |
cc_map.keys.each do |controller_name| | |
puts "Processing #{controller_name}..." | |
needs_controller_names = cc_map[controller_name] | |
path = filename(controller_name) | |
exists = File.exist?(path) | |
if !exists | |
puts controller_name.to_s + ': ' + path + ' ' + (exists ? 'Y' : 'x') | |
end | |
lines = File.read(path).split("\n") | |
add_needs_line(lines, controller_name, needs_controller_names) | |
needs_controller_names.each do |needs_controller_name| | |
rewrite_controller_property_line(lines, needs_controller_name) | |
end | |
File.open(path, 'w') do |f| | |
f.write(lines.join("\n")) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment