Class: Jenner::Template

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, site, options = {}) ⇒ Template

Returns a new instance of Template.



4
5
6
7
8
# File 'lib/jenner/template.rb', line 4

def initialize(body, site, options={})
  @body = body
  @site = site
  @haml = options[:haml]
end

Class Method Details

.from_file(file_path, site) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/jenner/template.rb', line 22

def self.from_file(file_path, site)
  if File.extname(file_path) != ".haml"
    new(File.read(file_path), site)
  else
    from_haml(File.read(file_path), site)
  end
end

.from_haml(haml_body, site) ⇒ Object



30
31
32
# File 'lib/jenner/template.rb', line 30

def self.from_haml(haml_body, site)
  new(haml_body, site, haml: true)
end

Instance Method Details

#body(context = {}) ⇒ Object



14
15
16
# File 'lib/jenner/template.rb', line 14

def body(context={})
  haml? ? Haml::Engine.new(@body).render(Jenner.deep_struct(context)) : @body
end

#haml?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/jenner/template.rb', line 10

def haml?
  @haml
end

#render(context = {}) ⇒ Object



18
19
20
# File 'lib/jenner/template.rb', line 18

def render(context={})
  Liquid::Template.parse(body(context.merge('site' => @site))).render(context.merge('site' => @site), registers: { site: @site }).to_s.encode("utf-8")
end