Sha256: f7c6b69c73e2725b910c702bddb99f9638d8ee3f998574c75f62066c24bee656

Contents?: true

Size: 1.28 KB

Versions: 4

Compression:

Stored size: 1.28 KB

Contents

require 'generators/ember/generator_helpers'

module Ember
  module Generators
    class ResourceGenerator < ::Rails::Generators::NamedBase
      include Ember::Generators::GeneratorHelpers

      source_root File.expand_path("../../templates", __FILE__)

      desc "Creates a new Ember.js router, controller, view and template"

      class_option :skip_route, :type => :boolean, :default => false, :desc => "Don't create route"
      class_option :array, :type => :boolean, :default => false, :desc => "Create an Ember.ArrayController to represent multiple objects"
      class_option :object, :type => :boolean, :default => false, :desc => "Create an Ember.ObjectController to represent a single object"

      def create_resource_files
        unless options[:skip_route]
          invoke('ember:route', [ name.pluralize ], options)
          inject_into_router_file(name)
        end
        invoke('ember:controller', [ name.pluralize ], options)
        invoke('ember:template', [ name.pluralize ], options)
      end

      private

      def inject_into_router_file(name)
        router_file = "#{config_path}/router.js.es6"
        inject_into_file(router_file, :after => /^.*Router.map\(function\(\) \{*$/) do
          "\n  this.resource('#{name.pluralize}');"
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ember-appkit-rails-0.4.0 lib/generators/ember/resource_generator.rb
ember-appkit-rails-0.3.2 lib/generators/ember/resource_generator.rb
ember-appkit-rails-0.3.1 lib/generators/ember/resource_generator.rb
ember-appkit-rails-0.3.0 lib/generators/ember/resource_generator.rb