class RailsScript::Generators::InstallGenerator

Public Instance Methods

copy_files() click to toggle source
# File lib/generators/rails_script/install/install_generator.rb, line 6
def copy_files
  template 'base.js.coffee', 'app/assets/javascripts/base.js.coffee'
  template 'global.js.coffee', 'app/assets/javascripts/global.js.coffee'
end
create_controllers() click to toggle source
# File lib/generators/rails_script/install/install_generator.rb, line 19
def create_controllers
  generate 'rails_script:controller'
end
insert_layout_javascript() click to toggle source
# File lib/generators/rails_script/install/install_generator.rb, line 23
      def insert_layout_javascript
        say <<-RUBY
In order to complete installation, you must add the following JavaScript snippet before the CLOSING body tag in your application layout.

ERB:
<script>
jQuery(function() {
    window.$this = new (App.\#{controller_path.split(/\/|_/).map(&:capitalize).join('')} || App.Base)();
    if (typeof $this.\#{action_name} === 'function') {
      return $this.\#{action_name}.call();
    }
});
</script>

HAML:
:javascript
  jQuery(function() {
    window.$this = new (App.\#{controller_path.split(/\/|_/).map(&:capitalize).join('')} || App.Base)();
    if (typeof $this.\#{action_name} === 'function') {
      return $this.\#{action_name}.call();
    }
  });
        RUBY
      end
insert_load_order() click to toggle source
# File lib/generators/rails_script/install/install_generator.rb, line 11
def insert_load_order
  if File.exist?('app/assets/javascripts/application.js')
    inject_into_file 'app/assets/javascripts/application.js',  "\n//= require base", before: "\n//= require_tree ."
  elsif File.exist?('app/assets/javascripts/application.js.coffee')
    inject_into_file 'app/assets/javascripts/application.js.coffee', "\n#= require base", before: "\n#= require_tree ."
  end
end