Sha256: 2f5bc8cece5b71b3590c314ab8024f0d2744e2f7561123911026283852b4fe5b

Contents?: true

Size: 1.57 KB

Versions: 2

Compression:

Stored size: 1.57 KB

Contents

module RailsScript
  module Generators
    class InstallGenerator < ::Rails::Generators::Base
      source_root File.expand_path("../templates", __FILE__)

      def copy_files
        template 'base.js.coffee', 'app/assets/javascripts/base.js.coffee'
        template 'global.js.coffee', 'app/assets/javascripts/global.js.coffee'
      end

      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

      def create_controllers
        generate 'rails_script:controller'
      end

      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

    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
rails-script-0.0.1 lib/generators/rails_script/install/install_generator.rb
rails_script-0.0.1 lib/generators/rails_script/install/install_generator.rb