Sha256: bc1b74a4fa7fd0b2b0995153b03599d5dbc11e81eec03604252f4048e2bc4444

Contents?: true

Size: 949 Bytes

Versions: 4

Compression:

Stored size: 949 Bytes

Contents

module RailsScript
  module Generators
    class ControllerGenerator < ::Rails::Generators::Base
      source_root File.expand_path("../templates", __FILE__)
      argument :controller_name, type: :string, default: ''
      hook_for :controller

      def generate_file
        if controller_name.blank?
          Rails.application.eager_load!
          controllers = ApplicationController.descendants.map(&:to_s)
          controllers.each{ |c| c.gsub!('Controller', '') }
        else
          controllers = [controller_name]
        end

        controllers.each do |controller|
          if !File.exist?("app/assets/javascripts/#{controller.underscore}.js.coffee")
            template 'javascript.js.coffee', "app/assets/javascripts/#{controller.underscore}.js.coffee"
            gsub_file "app/assets/javascripts/#{controller.underscore}.js.coffee", 'Example', controller.gsub('::', '')
          end
        end
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
rails_script-0.0.3 lib/generators/rails_script/controller/controller_generator.rb
rails_script-0.0.2 lib/generators/rails_script/controller/controller_generator.rb
rails-script-0.0.1 lib/generators/rails_script/controller/controller_generator.rb
rails_script-0.0.1 lib/generators/rails_script/controller/controller_generator.rb