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, layout_file) ⇒ MustacheProcessor

Returns a new instance of MustacheProcessor.

Parameters:



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

def initialize(renderer, layout_file)
  @renderer = renderer
  @layout_file = layout_file
end

Instance Method Details

#dest_name(src) ⇒ Pathname

Parameters:

  • src (Pathname)

Returns:

  • (Pathname)


29
30
31
32
33
34
35
36
37
# File 'lib/gryphon_nest/processors/mustache_processor.rb', line 29

def dest_name(src)
  dir = src.dirname
  path = dir.sub(CONTENT_DIR, BUILD_DIR)
  basename = src.basename(TEMPLATE_EXT)

  path = path.join(basename) if basename.to_s != 'index'

  path.join('index.html')
end

#file_modified?(src, dest) ⇒ Boolean

Parameters:

  • src (Pathname)
  • dest (Pathname)

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/gryphon_nest/processors/mustache_processor.rb', line 42

def file_modified?(src, dest)
  return true unless dest.exist?

  mod_time = dest.mtime
  return true if src.mtime > mod_time

  path = context_file_name(src)
  return true if path.exist? && path.mtime > mod_time

  return false unless @layout_file.exist?

  @layout_file.mtime > mod_time
end

#process(src, dest) ⇒ Object

Parameters:

  • src (Pathname)
  • dest (Pathname)

Raises:



21
22
23
24
25
# File 'lib/gryphon_nest/processors/mustache_processor.rb', line 21

def process(src, dest)
  context = read_context(src)
  content = build_output(src, context)
  write_file(dest, content)
end