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.



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

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

Instance Method Details

#file ⇒ Object



18
19
20
# File 'lib/rocco/layout.rb', line 18

def file
  @doc.file
end

#sections ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rocco/layout.rb', line 22

def sections
  num = 0
  @doc.sections.map do |docs,code|
    code ||= ''
    is_header = /^<h.>(.+)<\/h.>$/.match( docs )
    header_text = is_header && is_header[1].split.join("_")
    num += 1
    {
      :docs       =>  docs,
      :docs?      =>  !docs.empty?,
      :header?    =>  is_header,

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

      :empty?     =>  ( code.empty? && docs.empty? ),
      :section_id =>  is_header ? header_text : num
    }
  end
end

#sources ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rocco/layout.rb', line 47

def sources
  currentpath = Pathname.new( File.dirname( @doc.file ) )
  @doc.sources.sort.map do |source|
    htmlpath = Pathname.new( source.sub( Regexp.new( "#{File.extname(source)}$"), ".html" ) )

    {
      :path       => source,
      :basename   => File.basename(source),
      :url        => htmlpath.relative_path_from( currentpath )
    }
  end
end

#sources? ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/rocco/layout.rb', line 43

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

#title ⇒ Object



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

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