Class: Smeagol::TOC
- Inherits:
-
Object
- Object
- Smeagol::TOC
- 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
- #build_toc ⇒ Object
-
#initialize(ctrl, options = {}) ⇒ TOC
constructor
A new instance of TOC.
- #pages ⇒ Object
- #to_json ⇒ Object (also: #to_s)
- #toc ⇒ Object
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, ={}) @ctrl = ctrl @wiki = ctrl.wiki @version = [:version] || 'master' @pages = [:pages] require 'json' end |
Instance Method Details
#build_toc ⇒ Object
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.post_date if page.post_date data['author'] = page. data['summary'] = page.summary json[page.name] = data end json end |
#pages ⇒ Object
50 51 52 |
# File 'lib/smeagol/helpers/toc.rb', line 50 def pages @ctrl.views(@version).reject{ |v| Smeagol::Views::Form === v } end |
#to_json ⇒ Object Also known as: to_s
21 22 23 |
# File 'lib/smeagol/helpers/toc.rb', line 21 def to_json toc.to_json end |
#toc ⇒ Object
29 30 31 |
# File 'lib/smeagol/helpers/toc.rb', line 29 def toc @toc ||= build_toc end |