Changeset 824
- Timestamp:
- 11/02/07 23:09:30 (1 year ago)
- Files:
-
- trunk/app_generators/merb/templates/config/merb_init.rb (modified) (1 diff)
- trunk/app_generators/merb/templates/script/generate (modified) (1 diff)
- trunk/lib/merb/generators/merb_generator_helpers.rb (modified) (2 diffs)
- trunk/merb_generators/merb_controller/merb_controller_generator.rb (modified) (1 diff)
- trunk/merb_generators/merb_controller/templates/controller.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/app_generators/merb/templates/config/merb_init.rb
r544 r824 15 15 # Load environment-specific configuration 16 16 require File.join(MERB_ROOT, 'config', 'environments', MERB_ENV) 17 18 # Set the scope for generators used in this app 19 # The first generator matched will be used, where the generators are 20 # searched in the following order. 21 # If you are using an ORM plugin, that should come first, 22 # then merb, then the test framework you want. 23 # 24 # Example 25 # 26 # To use data_mapper, merb and rspec 27 # [:data_mapper, :merb, :rspec] 28 # 29 # To use active_record, merb and test_unit 30 # [:active_record, :merb, :test_unit] 31 # 32 # To use plain merb without an ORM and rspec 33 # [:merb, :rspec] 34 Merb::GENERATOR_SCOPE = [:merb, :rspec] trunk/app_generators/merb/templates/script/generate
r720 r824 25 25 # Default is to use rspec generators in gems. To change this to 26 26 # Test::Unit use [:merb, :test_unit] 27 RubiGen::Base.use_component_sources! [:merb, :rspec]27 RubiGen::Base.use_component_sources! Merb::GENERATOR_SCOPE 28 28 RubiGen::Scripts::Generate.new.run(ARGV) trunk/lib/merb/generators/merb_generator_helpers.rb
r804 r824 39 39 "app/models/#{model_filename}.rb", 40 40 :assigns => { :class_name => @class_name, 41 :table_attributes => model_attributes}41 :table_attributes => model_attributes} 42 42 43 43 # Check to see if a scope has been set for which test framework to use. … … 240 240 end 241 241 242 # Pass the following options are available to this generatrs 243 class ControllerGeneratorBase < RubiGen::Base 244 245 default_options :author => nil 246 247 attr_reader :name, :class_name, :file_name 248 249 def initialize(runtime_args, runtime_options = {}) 250 super 251 usage if args.empty? 252 @name = args.shift 253 @class_name = @name.camel_case.pluralize 254 @file_name = @name.snake_case.pluralize 255 @engine = runtime_options[:engine] || "erb" # set by subclasses only 256 @template_actions = runtime_options[:actions] || %w[index] # Used by subclasses only 257 @test_generator = runtime_options[:test_stub_generator] || "merb_controller_test" 258 extract_options 259 end 260 261 def manifest 262 record do |m| 263 264 # ensure there are no other definitions of this model already defined. 265 m.class_collisions(@class_name) 266 267 m.directory "app/controllers" 268 m.template "controller.rb", "app/controllers/#{file_name}.rb", :assigns => {:actions => @template_actions} 269 270 m.directory "app/views/#{file_name}" 271 272 # Include templates if they exist 273 @template_actions.each do |the_action| 274 template_name = "#{the_action}.html.#{@engine}" 275 template_path = "/" + source_path(spec.name).split("/")[0..-2].join("/") 276 277 if File.exists?(File.join(template_path,template_name)) 278 m.template template_name, "app/views/#{file_name}/#{template_name}" 279 end 280 end 281 282 m.directory "app/helpers/" 283 m.template "helper.rb", "app/helpers/#{file_name}_helper.rb" 284 m.dependency @test_generator, [name], :destination => destination_root 285 end 286 end 287 288 protected 289 def banner 290 <<-EOS 291 Creates a Merb controller 292 293 USAGE: #{$0} #{spec.name} name" 294 EOS 295 end 296 297 def add_options!(opts) 298 # opts.separator '' 299 # opts.separator 'Options:' 300 # For each option below, place the default 301 # at the top of the file next to "default_options" 302 # opts.on("-a", "--author=\"Your Name\"", String, 303 # "Some comment about this option", 304 # "Default: none") { |options[:author]| } 305 # opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.") 306 end 307 308 def extract_options 309 # for each option, extract it into a local variable (and create an "attr_reader :author" at the top) 310 # Templates can access these value via the attr_reader-generated methods, but not the 311 # raw instance variable value. 312 # @author = options[:author] 313 end 314 end 315 242 316 end 243 317 end trunk/merb_generators/merb_controller/merb_controller_generator.rb
r707 r824 1 class MerbControllerGenerator < RubiGen::Base 1 require 'merb/generators/merb_generator_helpers' 2 3 class MerbControllerGenerator < Merb::GeneratorHelpers::ControllerGeneratorBase 4 5 def initialize(*args) 6 runtime_options = args.last.is_a?(Hash) ? args.pop : {} 7 name, *actions = args.flatten 8 runtime_options[:actions] = actions.empty? ? %w[index] : actions 9 super( [name], runtime_options ) 10 end 2 11 3 default_options :author => nil 4 5 attr_reader :name, :class_name, :file_name 6 7 def initialize(runtime_args, runtime_options = {}) 8 super 9 usage if args.empty? 10 @name = args.shift 11 @class_name = @name.camel_case 12 @file_name = @name.snake_case 13 extract_options 12 def self.superclass 13 RubiGen::Base 14 14 end 15 16 def manifest17 record do |m|18 m.directory "app/controllers"19 m.template "controller.rb", "app/controllers/#{file_name}.rb"20 21 m.directory "app/views/#{file_name}"22 m.template "index.html.erb", "app/views/#{file_name}/index.html.erb"23 24 m.directory "app/helpers/"25 m.template "helper.rb", "app/helpers/#{file_name}_helper.rb"26 m.dependency "merb_controller_test", [name], :destination => destination_root27 end28 end29 30 protected31 def banner32 <<-EOS33 Creates a Merb controller34 35 USAGE: #{$0} #{spec.name} name"36 EOS37 end38 39 def add_options!(opts)40 # opts.separator ''41 # opts.separator 'Options:'42 # For each option below, place the default43 # at the top of the file next to "default_options"44 # opts.on("-a", "--author=\"Your Name\"", String,45 # "Some comment about this option",46 # "Default: none") { |options[:author]| }47 # opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")48 end49 15 50 def extract_options51 # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)52 # Templates can access these value via the attr_reader-generated methods, but not the53 # raw instance variable value.54 # @author = options[:author]55 end56 16 end trunk/merb_generators/merb_controller/templates/controller.rb
r704 r824 1 class <%= class_name %> < Application 2 def index 1 class <%= class_name.pluralize %> < Application 2 <% actions.each do |action| -%> 3 4 def <%= action %> 3 5 render 4 6 end 7 <% end -%> 5 8 end
