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

#sectionsObject



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

def sections
  num = 0
  @doc.sections.map do |docs,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

#sourcesObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rocco/layout.rb', line 42

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)


38
39
40
# File 'lib/rocco/layout.rb', line 38

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

#titleObject



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

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