Sha256: 1764465cd0efd8df2d15d479939f0e0f5360ac1490db2efe6c6e7d23c9bada1a

Contents?: true

Size: 1.59 KB

Versions: 5

Compression:

Stored size: 1.59 KB

Contents

# 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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rtml-2.0.4 rails_generators/widget/widget_generator.rb
rtml-2.0.3 rails_generators/widget/widget_generator.rb
rtml-2.0.2 rails_generators/widget/widget_generator.rb
rtml-2.0.1 rails_generators/widget/widget_generator.rb
rtml-2.0.0.alpha.1 rails_generators/widget/widget_generator.rb