Class: Hobber::RenderableObject
- Inherits:
-
Object
- Object
- Hobber::RenderableObject
- Defined in:
- lib/hobber/renderable_object.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#renderer ⇒ Object
readonly
Returns the value of attribute renderer.
-
#tmpl_content ⇒ Object
readonly
Returns the value of attribute tmpl_content.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #fetch(*a) ⇒ Object
-
#initialize(path, a_renderer = nil, a_tmpl_var_extractor = nil) ⇒ RenderableObject
constructor
A new instance of RenderableObject.
- #render(vars = {}, ctx = Object.new, &block) ⇒ Object
- #tmpl_vars ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(path, a_renderer = nil, a_tmpl_var_extractor = nil) ⇒ RenderableObject
Returns a new instance of RenderableObject.
10 11 12 13 14 15 16 |
# File 'lib/hobber/renderable_object.rb', line 10 def initialize(path, a_renderer=nil, a_tmpl_var_extractor=nil) @path = path @tmpl_content = block_given? ? yield(self) : File.open(@path, 'r:UTF-8') { |f| f.read } @renderer = a_renderer || Renderer::Tilt.new @tmpl_var_extractor = a_tmpl_var_extractor || TmplVarExtractor::Yaml.new(@tmpl_content, @path) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/hobber/renderable_object.rb', line 8 def path @path end |
#renderer ⇒ Object (readonly)
Returns the value of attribute renderer.
8 9 10 |
# File 'lib/hobber/renderable_object.rb', line 8 def renderer @renderer end |
#tmpl_content ⇒ Object (readonly)
Returns the value of attribute tmpl_content.
8 9 10 |
# File 'lib/hobber/renderable_object.rb', line 8 def tmpl_content @tmpl_content end |
Instance Method Details
#[](key) ⇒ Object
26 27 28 |
# File 'lib/hobber/renderable_object.rb', line 26 def [](key) tmpl_vars[key] end |
#fetch(*a) ⇒ Object
30 31 32 |
# File 'lib/hobber/renderable_object.rb', line 30 def fetch(*a) tmpl_vars.fetch(*a) end |
#render(vars = {}, ctx = Object.new, &block) ⇒ Object
18 19 20 |
# File 'lib/hobber/renderable_object.rb', line 18 def render(vars={}, ctx=Object.new, &block) @renderer.render(path, tmpl_content, ctx, tmpl_vars.merge(vars), &block) end |
#tmpl_vars ⇒ Object
38 39 40 |
# File 'lib/hobber/renderable_object.rb', line 38 def tmpl_vars @tmpl_var_extractor.tmpl_vars end |
#to_a ⇒ Object
22 23 24 |
# File 'lib/hobber/renderable_object.rb', line 22 def to_a [self] end |