Sha256: f3d224c33ae86929a46a2962e320ed71325b14352de04b07de85832601bb6efa

Contents?: true

Size: 1.54 KB

Versions: 5

Compression:

Stored size: 1.54 KB

Contents

# This generator builds a single RTML Action for your application. Note that
# the controller should extend RtmlController instead of ApplicationController,
# which is something this generator does NOT do for you.
#
#   * app/rtml_actions/[controller_path]/[action_name].rb
#     - the RTML Action itself
#
#   * app/views/[controller_path]/[action_name]/[screen_name].rtml.erb
#     - the view generated for this particular screen
# 
# Usage (from your Rails application root):
#
#   ruby script/generate rtml_action controller_name action_name [screen_names]
#
# Screen names are optional, and an :idle screen will be generated if omitted.
#
class RtmlActionGenerator < Rails::Generator::NamedBase
  attr_reader :action_name, :screen_names, :controller_path, :controller_name, :view_path, :action_path

  def initialize(*a, &b)
    super(*a, &b)
    @controller_name = name.camelize
    @controller_path = name.underscore
    @action_name = args.shift
    @screen_names = args.empty? ? ['idle'] : args
    @view_path = "app/views/#{controller_path}/#{action_name}"
    @action_path = "app/rtml_actions/#{controller_path}"
  end

  def manifest
    record do |m|
      m.directory action_path
      m.directory view_path

      m.template "action.erb", "#{action_path}/#{action_name}.rb"

      screen_names.each do |screen_name|
        m.template "view.erb",   "#{view_path}/#{screen_name}.rtml.erb", :assigns => { :screen_name => screen_name }
      end
    end
  end

  protected
    def banner
      <<-EOS
Creates a ...

USAGE: #{$0} #{spec.name} name
EOS
    end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rtml-2.0.4 rails_generators/rtml_action/rtml_action_generator.rb
rtml-2.0.3 rails_generators/rtml_action/rtml_action_generator.rb
rtml-2.0.2 rails_generators/rtml_action/rtml_action_generator.rb
rtml-2.0.1 rails_generators/rtml_action/rtml_action_generator.rb
rtml-2.0.0.alpha.1 rails_generators/rtml_action/rtml_action_generator.rb