Sha256: ec2fa7e397f410578a755d4a5ad0a18d0227bc19e5e55d7af435de092277c6a8

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

#encoding: utf-8
require 'rails/generators/rails/scaffold/scaffold_generator'

#Let this templates selected firstly! Just apply this default temmplate overriding to ns:scaffold 
#Don't pollute the rails default generators in user's projects!
Rails::Generators.templates_path.unshift File::expand_path('../templates', __FILE__)
#默认设置如下选项 --no-migration --no-template_engine
Rails::Generators.options[:active_record][:migration] = false
Rails::Generators.options[:rails][:template_engine] = false
#puts "====options: #{Rails::Generators.options.inspect}"

class Ns::ScaffoldGenerator < Rails::Generators::ScaffoldGenerator
  #移除一些不必要的generator引用 
  remove_hook_for :assets 
  remove_hook_for :stylesheet_engine
  remove_class_option :stylesheet_engine
  remove_class_option :stylesheets

  desc "Dump field mapping to a yml file..."
  def dump_field_mapping
    the_model = Object.const_get(class_name)
    mapping_file = the_model.dump_mapping
    say("   Generated field mapping for model: #{name}...", :green)
    say("   You can configure it in #{mapping_file}.", :green)
  end
  
  desc "Modify the route to add some action support"
  def reroute
    #TODO MOVE dev interface TO this gem controller
    gsub_file('config/routes.rb', /^\s*resources :#{plural_name}$/) do
      <<-Doc 
  resources :#{plural_name}, :except=>[:edit] 
      Doc
    end
  end 
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ns_service_pack-0.1.8 lib/generators/ns/scaffold/scaffold_generator.rb
ns_service_pack-0.1.7 lib/generators/ns/scaffold/scaffold_generator.rb
ns_service_pack-0.1.6 lib/generators/ns/scaffold/scaffold_generator.rb