Class: Soundwave::Mustache

Inherits:
Mustache
  • Object
show all
Defined in:
lib/soundwave.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page = nil) ⇒ Mustache

Returns a new instance of Mustache.



9
10
11
# File 'lib/soundwave.rb', line 9

def initialize(page=nil)
  @page = page
end

Instance Attribute Details

#pageObject (readonly)

Returns the value of attribute page.



7
8
9
# File 'lib/soundwave.rb', line 7

def page
  @page
end

Instance Method Details

#partial(name) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/soundwave.rb', line 29

def partial(name)
  @paths ||= [@page.path.dirname, site.source.join("includes"), Dir.pwd].map(&:to_s).uniq
  @trail ||= Hike::Trail.new(@page.site.source).tap do |t|
    t.append_extension ".mustache"
    t.append_paths *@paths
  end

  if path = @trail.find(partial_path(name))
    File.read(path)
  end
end

#partial_path(name) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/soundwave.rb', line 21

def partial_path(name)
  name = name.to_s
  dirname = File.dirname(name)
  basename = File.basename(name)
  partialname = "_#{basename}"
  File.join(dirname, partialname)
end

#siteObject



13
14
15
# File 'lib/soundwave.rb', line 13

def site
  @page.site
end

#templateObject



17
18
19
# File 'lib/soundwave.rb', line 17

def template
  @page.path.read
end