Sha256: 8f4389b8cd73341dff7bff8969846dfac77aa13d0f14b494a52a4ba26bcdfa54

Contents?: true

Size: 1.42 KB

Versions: 2

Compression:

Stored size: 1.42 KB

Contents

module Backbone
  module Generators
    class InstallGenerator < Rails::Generators::Base
      source_root File.expand_path("../templates", __FILE__)
  
      desc "This generator installs backbone.js with a default folder layout in app/assets/javascripts/backbone"
          
      class_option :skip_git, :type => :boolean, :aliases => "-G", :default => false,
                              :desc => "Skip Git ignores and keeps"
                                      
      def inject_backbone
        inject_into_file "app/assets/javascripts/application.js", :before => "//= require_tree" do
          "//= require underscore\n//= require backbone\n//= require backbone_rails_sync\n//= require backbone_datalink\n//= require backbone/#{application_name}\n"
        end
      end
    
      def create_dir_layout
        %W{routers models views templates}.each do |dir|
          empty_directory "app/assets/javascripts/backbone/#{dir}" 
          create_file "app/assets/javascripts/backbone/#{dir}/.gitkeep" unless options[:skip_git]
        end
      end
    
      def create_app_file
        template "app.coffee", "app/assets/javascripts/backbone/#{application_name}.js.coffee"
      end
    
      protected
        def application_name
          if defined?(Rails) && Rails.application
            Rails.application.class.name.split('::').first.underscore
          else
            "application"
          end
        end
     
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails-backbone-0.5.1 lib/generators/backbone/install/install_generator.rb
rails-backbone-0.5.0 lib/generators/backbone/install/install_generator.rb