Class: Yarrow::Web::Template

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Template

Returns a new instance of Template.



21
22
23
# File 'lib/yarrow/web/template.rb', line 21

def initialize(source)
  @source = source
end

Class Method Details

.for_document(document, config) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/yarrow/web/template.rb', line 4

def self.for_document(document, config)
  layout_name = if document.respond_to?(:layout)
    document.layout || document.type
  else
    document.type
  end

  @template_dir = config.output.template_dir
  #@template_dir = "./spec/fixtures/templates/doctest"
  @template_ext = ".html"

  template_file = "#{layout_name}#{@template_ext}"
  template_path = Pathname.new(@template_dir) + template_file

  new(template_path.read)
end

Instance Method Details

#render(document) ⇒ Object



25
26
27
# File 'lib/yarrow/web/template.rb', line 25

def render(document)
  Mustache.render(@source, document)
end