Sha256: be5f813883867d7a81fffacac235e147c74051ad5fce6d838b1237c4ee84bd52

Contents?: true

Size: 1.83 KB

Versions: 7

Compression:

Stored size: 1.83 KB

Contents

require 'generators/ember/model_generator'

module Ember
  module Generators
    class ScaffoldGenerator < ModelGenerator
      source_root File.expand_path("../../templates", __FILE__)
      desc "Scaffolds a new Ember CRUD"

      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_route_files
        create_resource_files_for(:route, 'js.es6')
        inject_into_router_file(file_name)
      end

      def create_template_files
        create_resource_files_for(:template, 'hbs')
        template "scaffold/template.hbs", File.join(app_path, 'templates', "#{file_name.pluralize}.hbs")
        template "scaffold/template/form.hbs", File.join(app_path, 'templates', file_name.pluralize, 'form.hbs')
      end

      private

      def create_resource_files_for(type, extension)
        dir = type.to_s.pluralize
        resource = file_name.pluralize

        [:edit, :index, :new, :show].each do |action|
          template "scaffold/#{type}/#{action}.#{extension}", File.join(app_path, dir, "#{resource}/#{action}.#{extension}")
        end
      end

      def inject_into_router_file(name)
        router_file = "#{config_path}/router.js.es6"
        js = <<-JS

  this.resource('#{name.pluralize}', function() {
    this.route('new');
    this.route('show', {path: ':#{file_name.singularize}_id'});
    this.route('edit', {path: ':#{file_name.singularize}_id/edit'});
  });
 JS
        inject_into_file(router_file, :after => /^.*Router.map\(function\(\) \{*$/) do
          js.rstrip
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ember-appkit-rails-0.4.0 lib/generators/ember/scaffold_generator.rb
ember-appkit-rails-0.3.2 lib/generators/ember/scaffold_generator.rb
ember-appkit-rails-0.3.1 lib/generators/ember/scaffold_generator.rb
ember-appkit-rails-0.3.0 lib/generators/ember/scaffold_generator.rb
ember-appkit-rails-0.2.2 lib/generators/ember/scaffold_generator.rb
ember-appkit-rails-0.2.1 lib/generators/ember/scaffold_generator.rb
ember-appkit-rails-0.2.0 lib/generators/ember/scaffold_generator.rb