class Jskit::Generators::InstallGenerator
Public Instance Methods
add_js_to_manifest()
click to toggle source
# File lib/generators/jskit/install/install_generator.rb, line 14 def add_js_to_manifest add_rails_jskit if manifest? end
append_jskit_to_application_layout()
click to toggle source
# File lib/generators/jskit/install/install_generator.rb, line 18 def append_jskit_to_application_layout send("append_jskit_method_to_application_layout_#{layout_extension}") unless jskit_method_exists? end
copy_controllers()
click to toggle source
# File lib/generators/jskit/install/install_generator.rb, line 10 def copy_controllers template "app/assets/javascripts/controllers/application_controller.js" end
create_controllers_directory()
click to toggle source
# File lib/generators/jskit/install/install_generator.rb, line 6 def create_controllers_directory empty_directory "app/assets/javascripts/controllers" end
create_initializer()
click to toggle source
# File lib/generators/jskit/install/install_generator.rb, line 22 def create_initializer template "config/initializers/rails_jskit.rb" end
Private Instance Methods
add_rails_jskit()
click to toggle source
# File lib/generators/jskit/install/install_generator.rb, line 28 def add_rails_jskit return if rails_jskit? if require_tree? gsub_file(js_manifest, /\/\/= require_tree \./, "//= require rails_jskit\n//= require_tree ./controllers\n") else append_to_file(js_manifest, "//= require rails_jskit\n//= require_tree ./controllers\n") end end
append_jskit_method_to_application_layout_erb()
click to toggle source
# File lib/generators/jskit/install/install_generator.rb, line 69 def append_jskit_method_to_application_layout_erb insert_into_file layout_file, jskit_method_snippet, before: "</body>" end
append_jskit_method_to_application_layout_haml()
click to toggle source
# File lib/generators/jskit/install/install_generator.rb, line 73 def append_jskit_method_to_application_layout_haml append_to_file layout_file, jskit_method_snippet end
application_js()
click to toggle source
# File lib/generators/jskit/install/install_generator.rb, line 97 def application_js File.read js_manifest end
body_indentation()
click to toggle source
# File lib/generators/jskit/install/install_generator.rb, line 56 def body_indentation if layout_file_content.match(/^(\s+)%body/) indentation = layout_file_content.match(/^(\s+)%body/)[1] else indentation = "" end "#{indentation} " end
js_manifest()
click to toggle source
# File lib/generators/jskit/install/install_generator.rb, line 81 def js_manifest "app/assets/javascripts/application.js" end
jskit_method_exists?()
click to toggle source
# File lib/generators/jskit/install/install_generator.rb, line 48 def jskit_method_exists? !!layout_file_content.match(/\= jskit/) end
jskit_method_snippet()
click to toggle source
# File lib/generators/jskit/install/install_generator.rb, line 37 def jskit_method_snippet method = case layout_extension when :erb "<%= jskit %>" when :haml "= jskit" end "\n#{body_indentation}#{method}\n" end
layout_extension()
click to toggle source
# File lib/generators/jskit/install/install_generator.rb, line 77 def layout_extension File.extname(layout_file).gsub(/^\./, "").to_sym end
layout_file()
click to toggle source
# File lib/generators/jskit/install/install_generator.rb, line 65 def layout_file @layout_file ||= Dir["app/views/layouts/application.html*"].first end
layout_file_content()
click to toggle source
# File lib/generators/jskit/install/install_generator.rb, line 52 def layout_file_content File.exists?(layout_file) ? File.read(layout_file) : "" end
manifest?()
click to toggle source
# File lib/generators/jskit/install/install_generator.rb, line 85 def manifest? File.exists? js_manifest end
rails_jskit?()
click to toggle source
# File lib/generators/jskit/install/install_generator.rb, line 93 def rails_jskit? !!application_js.match(/\/\/= require rails_jskit/) end
require_tree?()
click to toggle source
# File lib/generators/jskit/install/install_generator.rb, line 89 def require_tree? !!application_js.match(/\/\/= require_tree \./) end