Class: HtmlMockup::TemplateContext

Inherits:
Object
  • Object
show all
Defined in:
lib/html_mockup/template.rb

Instance Method Summary collapse

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

#envObject



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, options = {})
  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, options[: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(options[:locals] || {})
    template.render(context, :env => self.env)        
  else
    raise ArgumentError, "No such partial #{name}, referenced from #{self.template.source_path}"
  end
end

#templateObject



99
100
101
# File 'lib/html_mockup/template.rb', line 99

def template
  @_template
end