# Description: # Generates an RTML Widget. See the Rtml::Widget class documentation for more # information. # # Example: # ./script/generate widget Thing [entry_point_1 entry_point_2] # # This will create: # lib/rtml/widgets/thing.rb # # And Test::Unit tests: # test/unit/rtml/widgets/thing_test.rb # # -or- # # RSpec and/or Cucumber tests: # spec/rtml/widgets/thing_spec.rb # features/rtml/widgets/thing.feature # class WidgetGenerator < Rails::Generator::NamedBase attr_reader :entry_points, :human_name def manifest @entry_points = args.dup @entry_points << class_name.underscore.sub(/^.*\//, '') if @entry_points.empty? @human_name = file_name.humanize record do |m| m.directory "lib/rtml/widgets" m.template 'default_widget.erb', "lib/rtml/widgets/#{file_name}.rb" if File.directory?(File.join(RAILS_ROOT, "spec")) || File.directory?(File.join(RAILS_ROOT, "features")) if File.directory?(File.join(RAILS_ROOT, "spec")) m.directory "spec/rtml/widgets" m.template "default_widget_spec.erb", "spec/rtml/widgets/#{file_name}_spec.rb" end if File.directory?(File.join(RAILS_ROOT, "features")) m.directory "features/rtml/widgets" m.template "default_widget.feature.erb", "features/rtml/widgets/#{file_name}.feature" end else # we only need Rails unit tests neither cucumber nor rspec is available. m.directory "test/unit/rtml/widgets" m.template 'default_widget_test.erb', "test/unit/rtml/widgets/#{file_name}_test.rb" end end end end