Class: Rokko::IndexLayout

Inherits:
Layout
  • Object
show all
Defined in:
lib/rokko/index_layout.rb

Overview

Layout containing README file and “Table of Contents” with links to all generated HTML files

Instance Method Summary collapse

Methods inherited from Layout

#highlight_js, #sections, #sources?, #styles

Constructor Details

#initialize(sources, readme = '', options = {}) ⇒ IndexLayout

Returns a new instance of IndexLayout.



6
7
8
9
10
# File 'lib/rokko/index_layout.rb', line 6

def initialize(sources, readme = '', options = {})
  @sources = sources
  @readme = readme
  @options = options
end

Instance Method Details

#dirsObject

Groupped sources by dirname



35
36
37
38
39
40
# File 'lib/rokko/index_layout.rb', line 35

def dirs
  sources.inject(Hash.new{ |hsh, key| hsh[key] = [] }) do |c, source|
    c[File.dirname(source[:path])].push(source)
    c
  end.sort.collect { |k, v| { dir: k, files: v } }
end

#readmeObject



16
17
18
# File 'lib/rokko/index_layout.rb', line 16

def readme
  Rokko::Rokko.renderer.render(@readme)
end

#readme?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/rokko/index_layout.rb', line 20

def readme?
  @readme != ""
end

#sourcesObject



24
25
26
27
28
29
30
31
32
# File 'lib/rokko/index_layout.rb', line 24

def sources
  @sources.sort.map do |source|
    {
      path: source,
      basename: File.basename(source),
      url: source.sub(Regexp.new("#{File.extname(source)}$"), ".html")
    }
  end
end

#titleObject



12
13
14
# File 'lib/rokko/index_layout.rb', line 12

def title
  "Table of Contents"
end