Class: Emmett::Renderer
- Inherits:
-
Object
- Object
- Emmett::Renderer
- Defined in:
- lib/emmett/renderer.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#global_context ⇒ Object
Returns the value of attribute global_context.
-
#handlebars ⇒ Object
readonly
Returns the value of attribute handlebars.
-
#templates ⇒ Object
readonly
Returns the value of attribute templates.
Instance Method Summary collapse
-
#initialize(configuration) ⇒ Renderer
constructor
A new instance of Renderer.
- #prepare_output ⇒ Object
- #render(template, context = {}) ⇒ Object
- #render_to(output, name, context = {}) ⇒ Object
Constructor Details
#initialize(configuration) ⇒ Renderer
Returns a new instance of Renderer.
11 12 13 14 15 16 17 18 |
# File 'lib/emmett/renderer.rb', line 11 def initialize(configuration) @configuration = configuration @templates = configuration.to_template @handlebars = Handlebars::Context.new @cache = {} @global_context = {} end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
8 9 10 |
# File 'lib/emmett/renderer.rb', line 8 def configuration @configuration end |
#global_context ⇒ Object
Returns the value of attribute global_context.
8 9 10 |
# File 'lib/emmett/renderer.rb', line 8 def global_context @global_context end |
#handlebars ⇒ Object (readonly)
Returns the value of attribute handlebars.
8 9 10 |
# File 'lib/emmett/renderer.rb', line 8 def @handlebars end |
#templates ⇒ Object (readonly)
Returns the value of attribute templates.
8 9 10 |
# File 'lib/emmett/renderer.rb', line 8 def templates @templates end |
Instance Method Details
#prepare_output ⇒ Object
31 32 33 34 35 |
# File 'lib/emmett/renderer.rb', line 31 def prepare_output FileUtils.rm_rf output_path FileUtils.mkdir_p output_path copy_static end |
#render(template, context = {}) ⇒ Object
20 21 22 |
# File 'lib/emmett/renderer.rb', line 20 def render(template, context = {}) load_template(template).call global_context.merge(context) end |
#render_to(output, name, context = {}) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/emmett/renderer.rb', line 24 def render_to(output, name, context = {}) out = File.join(output_path, output) File.open(out, 'w+') do |f| f.write render(name, context) end end |