Class: HtmlMockup::TemplateContext
- Inherits:
-
Object
- Object
- HtmlMockup::TemplateContext
- Defined in:
- lib/html_mockup/template.rb
Instance Method Summary collapse
- #env ⇒ Object
-
#initialize(template, env = {}) ⇒ TemplateContext
constructor
A new instance of TemplateContext.
- #partial(name, options = {}) ⇒ Object
- #template ⇒ Object
Constructor Details
#initialize(template, env = {}) ⇒ TemplateContext
Returns a new instance of TemplateContext.
95 96 97 |
# File 'lib/html_mockup/template.rb', line 95 def initialize(template, env={}) @_template, @_env = template, env end |
Instance Method Details
#env ⇒ Object
103 104 105 |
# File 'lib/html_mockup/template.rb', line 103 def env @_env end |
#partial(name, options = {}) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/html_mockup/template.rb', line 107 def partial(name, = {}) if template_path = self.template.find_template(name, :partials_path) # puts "Rendering partial #{name}, with template #{template_path}" partial_template = Tilt.new(template_path.to_s) partial_template.render(self, [:locals] || {}) elsif template_path = self.template.find_template(name + ".part", :partials_path) # puts "Rendering old-style partial #{name}, with template #{template_path}" template = Tilt::ERBTemplate.new(template_path.to_s) context = MockupTemplate::TemplateContext.new([:locals] || {}) template.render(context, :env => self.env) else raise ArgumentError, "No such partial #{name}, referenced from #{self.template.source_path}" end end |
#template ⇒ Object
99 100 101 |
# File 'lib/html_mockup/template.rb', line 99 def template @_template end |