Class: GryphonNest::Processors::MustacheProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/gryphon_nest/processors/mustache_processor.rb

Overview

Renders a Mustache template into a html file

Instance Method Summary collapse

Constructor Details

#initialize(renderer) ⇒ MustacheProcessor

Returns a new instance of MustacheProcessor.

Parameters:



11
12
13
# File 'lib/gryphon_nest/processors/mustache_processor.rb', line 11

def initialize(renderer)
  @renderer = renderer
end

Instance Method Details

#process(file) ⇒ Pathname

Parameters:

  • file (Pathname)

Returns:

  • (Pathname)

Raises:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gryphon_nest/processors/mustache_processor.rb', line 18

def process(file)
  dest = dest_name(file)
  msg = File.exist?(dest) ? 'Recreating' : 'Creating'
  puts "#{msg} #{dest}"

  @layout ||= read_layout_file

  context = read_context(file)

  if @layout.empty?
    content = @renderer.render_file(file, context)
  else
    context[:yield] = file.basename(TEMPLATE_EXT)
    content = @renderer.render(@layout, context)
  end

  content = HtmlBeautifier.beautify(content)
  write_file(dest, content)
  dest
end