Class: Smeagol::TOC

Inherits:
Object
  • Object
show all
Defined in:
lib/smeagol/helpers/toc.rb

Overview

Create a JSON-based Table of Contents. This is used to create 'toc.json', which can be used via jQuery to create a dynamic index page.

Instance Method Summary collapse

Constructor Details

#initialize(ctrl, options = {}) ⇒ TOC

Returns a new instance of TOC.


11
12
13
14
15
16
17
18
# File 'lib/smeagol/helpers/toc.rb', line 11

def initialize(ctrl, options={})
  @ctrl    = ctrl
  @wiki    = ctrl.wiki
  @version = options[:version] || 'master' 
  @pages   = options[:pages]

  require 'json'
end

Instance Method Details

#build_tocObject


34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/smeagol/helpers/toc.rb', line 34

def build_toc
  json = {}
  pages.each do |page|
    data = {}
    data['title']   = page.title
    data['name']    = page.name
    data['href']    = page.href
    data['date']    = page. if page.
    data['author']  = page.author
    data['summary'] = page.summary
    json[page.name] = data
  end
  json
end

#pagesObject


50
51
52
# File 'lib/smeagol/helpers/toc.rb', line 50

def pages
  @ctrl.views(@version).reject{ |v| Smeagol::Views::Form === v }
end

#to_jsonObject Also known as: to_s


21
22
23
# File 'lib/smeagol/helpers/toc.rb', line 21

def to_json
  toc.to_json
end

#tocObject


29
30
31
# File 'lib/smeagol/helpers/toc.rb', line 29

def toc
  @toc ||= build_toc
end