Sha256: 8ac0e3a2706488bffaed4315bc3af62869c98c6554fe7d34093b5824321bd1bd

Contents?: true

Size: 1.06 KB

Versions: 8

Compression:

Stored size: 1.06 KB

Contents

require 'generators/batman/common'
module Batman
  module Generators
    class ControllerGenerator < ::Rails::Generators::NamedBase
      include Common
      requires_app_name

      desc "This generator creates a Batman controller"
      argument :actions, :type => :array, :default => [], :banner => "action action"


      RESERVED_JS_WORDS = %w{
        break case catch continue debugger default delete do else finally for 
        function if in instanceof new return switch this throw try typeof var void while with 
      }

      def validate_no_reserved_words
        actions.each do |action|
          if RESERVED_JS_WORDS.include? action
             raise Thor::Error, "The name '#{action}' is reserved by javascript " <<
                                "Please choose an alternative action name and run this generator again."
          end
        end
      end

      def create_batman_controller
        with_app_name do
          template "controller.coffee", "#{js_path}/controllers/#{plural_name.downcase}_controller.js.coffee"
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
batman-rails-0.0.9 lib/generators/batman/controller_generator.rb
batman-rails-0.0.8 lib/generators/batman/controller_generator.rb
batman-rails-0.0.6 lib/generators/batman/controller_generator.rb
batman-rails-0.0.5 lib/generators/batman/controller_generator.rb
batman-rails-0.0.4 lib/generators/batman/controller_generator.rb
batman-rails-0.0.3 lib/generators/batman/controller_generator.rb
batman-rails-0.0.2 lib/generators/batman/controller_generator.rb
batman-rails-0.0.1 lib/generators/batman/controller_generator.rb