Class: Rocco::Layout

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

Instance Method Summary collapse

Constructor Details

#initialize(doc, stylesheet, file = nil) ⇒ Layout

Returns a new instance of Layout.



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

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

Instance Method Details

#fileObject



23
24
25
# File 'lib/rocco/layout.rb', line 23

def file
  @doc.file
end

#sectionsObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rocco/layout.rb', line 27

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

#sourcesObject



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rocco/layout.rb', line 52

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)


48
49
50
# File 'lib/rocco/layout.rb', line 48

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

#stylesheetObject



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

def stylesheet
  @stylesheet
end

#titleObject



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

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