Class: Hobber::RenderAction
- Inherits:
-
Object
- Object
- Hobber::RenderAction
- Defined in:
- lib/hobber/render_action.rb
Instance Attribute Summary collapse
-
#rewrite_paths ⇒ Object
Returns the value of attribute rewrite_paths.
-
#rewrite_urls ⇒ Object
Returns the value of attribute rewrite_urls.
Instance Method Summary collapse
- #_parse_rewrite_args(*args) ⇒ Object
-
#initialize(robjects, binding = nil, &block) ⇒ RenderAction
constructor
A new instance of RenderAction.
- #layout(*robjects) ⇒ Object
-
#perform ⇒ Object
Performs the render actions by iterating over robjects with the specified configuration.
- #rewrite_path(*args) ⇒ Object
- #rewrite_url(*args) ⇒ Object
- #target_extention(ext) ⇒ Object
- #tmpl_vars(vars = []) ⇒ Object
Constructor Details
#initialize(robjects, binding = nil, &block) ⇒ RenderAction
Returns a new instance of RenderAction.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/hobber/render_action.rb', line 9 def initialize robjects, binding=nil, &block @robjects = robjects @tmpl_vars = {} @layouts = [] @rewrite_paths = [] @rewrite_urls = [] @target_extention = nil @caller_binding = binding || ( block && block.binding ) if block block.arity <= 0 ? instance_eval(&block) : block.call(self) end end |
Instance Attribute Details
#rewrite_paths ⇒ Object
Returns the value of attribute rewrite_paths.
6 7 8 |
# File 'lib/hobber/render_action.rb', line 6 def rewrite_paths @rewrite_paths end |
#rewrite_urls ⇒ Object
Returns the value of attribute rewrite_urls.
7 8 9 |
# File 'lib/hobber/render_action.rb', line 7 def rewrite_urls @rewrite_urls end |
Instance Method Details
#_parse_rewrite_args(*args) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/hobber/render_action.rb', line 37 def _parse_rewrite_args *args if args.count == 1 && args[0].is_a?(Hash) regexp, replacement = args[0].keys.first, args[0].values.first elsif args.count == 2 regexp, replacement = args else raise ArgumentError.new('[rewrite_path] Expected either [regexp => sub] or [regexp, replacement] as arguments') end return regexp, replacement end |
#layout(*robjects) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/hobber/render_action.rb', line 23 def layout *robjects robjects.each do |robject| raise ArgumentError.new('Expected RenderableObject as a layout') unless robject.is_a?(RenderableObject) end @layouts.concat robjects end |
#perform ⇒ Object
Performs the render actions by iterating over robjects with the specified configuration
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/hobber/render_action.rb', line 65 def perform @robjects.map do |ro| RenderedObject.new( :data=>_render_renderable_object(ro, { :item => ro }.merge(@tmpl_vars), @layouts), :renderable_object=>ro, :layouts=> @layouts, :path=>_rewrite_paths(ro.path, @rewrite_paths), :url=>_rewrite_paths(ro.path, @rewrite_urls)) end end |
#rewrite_path(*args) ⇒ Object
48 49 50 51 |
# File 'lib/hobber/render_action.rb', line 48 def rewrite_path *args regexp, replacement = _parse_rewrite_args(*args) @rewrite_paths << [regexp, replacement] end |
#rewrite_url(*args) ⇒ Object
53 54 55 56 |
# File 'lib/hobber/render_action.rb', line 53 def rewrite_url *args regexp, replacement = _parse_rewrite_args(*args) @rewrite_urls << [regexp, replacement] end |
#target_extention(ext) ⇒ Object
58 59 60 |
# File 'lib/hobber/render_action.rb', line 58 def target_extention ext @target_extention = ext.to_s end |
#tmpl_vars(vars = []) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/hobber/render_action.rb', line 30 def tmpl_vars vars=[] if vars.empty? return @tmpl_vars end @tmpl_vars.merge!(vars) end |