Module: Rtml

Defined in:
lib/rtml.rb,
lib/rtml/version.rb,
lib/rtml/configuration.rb

Defined Under Namespace

Modules: DSL, InheritedInstanceVariables, TmlizedConditions, VERSION, Widgets Classes: Configuration, Widget

Class Method Summary collapse

Class Method Details

.action(name, controller, &block) ⇒ Object

Defines a single RTML action.

Examples:

Rtml.action :index, :controller => :rtml do
  def index
    # . . .
  end
end


31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rtml.rb', line 31

def action(name, controller, &block)
  case controller
    when Array then controllers = controller
    when String, Symbol, ActionController::Base then controllers = [ controller ]
    when Hash then controllers = [ controller.delete(:controller) ] || controller.delete(:controllers)
    else raise ArgumentError, "Expected an Array, String, Symbol or Hash listing affected controllers"
  end

  actions_for controllers do
    define_method name do
      self.instance_eval &block
    end
  end
end

.actions_for(*controllers, &block) ⇒ Object

Defines a block containing a set of RTML actions for the specified controllers.

Examples:

Rtml::actions_for :controller_name do
  def index
    # . . .
  end
end

Raises:

  • (ArgumentError)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/rtml.rb', line 56

def actions_for(*controllers, &block)
  raise ArgumentError, "actions_for: block containing RTML actions is expected", caller unless block_given?
  (controllers.flatten.collect do |controller|
    case controller
      when String, Symbol then "#{controller.to_s.camelize}Controller".constantize
      else controller
    end
  end).each do |controller|
    helpers = controller.rtml_helpers
    old_methods = helpers.instance_methods
    helpers.class_eval &block
    new_methods = helpers.instance_methods - old_methods
    controller.rtml_actions.concat new_methods

    new_methods.each do |method_name|
      unless helpers.hidden_action?(method_name)
        helpers.class_eval(<<-end_code, __FILE__, __LINE__+1)
          def #{method_name}_with_ivars
            copy_ivars_from(controller)
            # Give rtml actions access to the controller's view helpers
            (class << self; self; end).send(:include, controller.response.template.helpers)
            #{method_name}_without_ivars
          end
        end_code

        helpers.send(:alias_method_chain, method_name, :ivars)
      end
      unless helpers.hidden_action?(method_name) || controller.instance_methods.include?(method_name)
        controller.add_rtml_proxy_action(method_name)
      end
    end
  end
end

.configurationObject



13
14
15
# File 'lib/rtml.rb', line 13

def configuration
  @configuration ||= Rtml::Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



17
18
19
20
# File 'lib/rtml.rb', line 17

def configure
  yield configuration
  configuration.validate!
end

.rootObject



9
10
11
# File 'lib/rtml.rb', line 9

def root
  RTML_ROOT
end