Module: Rtml
- Defined in:
- lib/rtml.rb,
lib/rtml/version.rb,
lib/rtml/configuration.rb,
lib/rtml/test/builtin_variables.rb
Defined Under Namespace
Modules: Assigns, DSL, InheritedInstanceVariables, Links, Test, TmlizedConditions, VERSION, Widgets Classes: Configuration, Widget
Class Method Summary collapse
-
.action(name, controller, &block) ⇒ Object
Defines a single RTML action.
-
.actions_for(*controllers, &block) ⇒ Object
Defines a block containing a set of RTML actions for the specified controllers.
- .configuration ⇒ Object
- .configure {|configuration| ... } ⇒ Object
- .root ⇒ Object
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
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# 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) || controller.instance_methods.include?(method_name) controller.add_rtml_proxy_action(method_name) end end end end |
.configuration ⇒ Object
13 14 15 |
# File 'lib/rtml.rb', line 13 def configuration @configuration ||= Rtml::Configuration.new end |
.configure {|configuration| ... } ⇒ Object
17 18 19 20 |
# File 'lib/rtml.rb', line 17 def configure yield configuration configuration.validate! end |