Sha256: 1d777f22dfdc7c02707fbd629f734fb261a9d59bc16507f1e1e0459ec69da847

Contents?: true

Size: 1.5 KB

Versions: 2

Compression:

Stored size: 1.5 KB

Contents

require 'generators/thorax/resource_helpers'

module Thorax
  module Generators
    class RouterGenerator < Rails::Generators::NamedBase
      include Thorax::Generators::ResourceHelpers

      source_root File.expand_path("../templates", __FILE__)
      desc "This generator creates a thorax router with views and templates for the provided actions"

      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_router_files
        template 'router.coffee', File.join(thorax_path, "routers", class_path, "#{file_name}.js.coffee")
      end

      def create_view_files
         actions.each do |action|
           @action = action
           @view_path = File.join(thorax_path, "views", plural_name, "#{@action}.js.coffee")
           @hbs_path = File.join(template_path, plural_name, "#{@action}.hbs")

           template "view.coffee", @view_path
           template "template.hbs", @hbs_path
         end
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
thorax-rails-1.0.0 lib/generators/thorax/router/router_generator.rb
thorax-rails-0.1.8 lib/generators/thorax/router/router_generator.rb