Class: Rocco::Layout

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

Instance Method Summary collapse

Constructor Details

#initialize(doc, file = nil) ⇒ Layout

Returns a new instance of Layout.



6
7
8
9
10
11
# File 'lib/rocco/layout.rb', line 6

def initialize(doc, file=nil)
  @doc = doc
  if not file.nil?
    Rocco::Layout.template_file = file
  end
end

Instance Method Details

#sectionsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rocco/layout.rb', line 17

def sections
  num = 0
  @doc.sections.map do |docs,code|
    {
      :docs       =>  docs,
      :docs?      =>  !docs.empty?,
      :header?    =>  /^<h.>.+<\/h.>$/.match( docs ),

      :code       =>  code,
      :code?      =>  !code.empty?,

      :empty?     =>  ( code.empty? && docs.empty? ),
      :num        =>  (num += 1)
    }
  end
end

#sourcesObject



38
39
40
41
42
43
44
45
46
# File 'lib/rocco/layout.rb', line 38

def sources
  @doc.sources.sort.map do |source|
    {
      :path => source,
      :basename => File.basename(source),
      :url => File.basename(source).split('.')[0..-2].join('.') + '.html'
    }
  end
end

#sources?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/rocco/layout.rb', line 34

def sources?
  @doc.sources.length > 1
end

#titleObject



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

def title
  File.basename(@doc.file)
end