Class: WikiCloth::Section
- Inherits:
-
String
- Object
- String
- WikiCloth::Section
- Defined in:
- lib/wikicloth/section.rb
Instance Method Summary collapse
- #auto_toc=(val) ⇒ Object
- #children ⇒ Object
- #depth ⇒ Object
- #get_section(id) ⇒ Object
- #id ⇒ Object
-
#initialize(title = nil, id = nil) ⇒ Section
constructor
A new instance of Section.
- #render(opt = {}) ⇒ Object
- #template=(val) ⇒ Object
- #title ⇒ Object
- #title=(val) ⇒ Object
- #wikitext(opt = {}) ⇒ Object
Constructor Details
#initialize(title = nil, id = nil) ⇒ Section
Returns a new instance of Section.
5 6 7 8 9 10 11 |
# File 'lib/wikicloth/section.rb', line 5 def initialize(title=nil, id=nil) self.title = title @children = [] @id = id @template = nil @auto_toc = nil end |
Instance Method Details
#auto_toc=(val) ⇒ Object
21 22 23 |
# File 'lib/wikicloth/section.rb', line 21 def auto_toc=(val) @auto_toc = val end |
#children ⇒ Object
13 14 15 |
# File 'lib/wikicloth/section.rb', line 13 def children @children end |
#depth ⇒ Object
45 46 47 |
# File 'lib/wikicloth/section.rb', line 45 def depth @depth ||= 1 end |
#get_section(id) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/wikicloth/section.rb', line 49 def get_section(id) return self.wikitext() if self.id == id @children.each do |child| ret = child.get_section(id) return ret unless ret.nil? end nil end |
#id ⇒ Object
17 18 19 |
# File 'lib/wikicloth/section.rb', line 17 def id @id end |
#render(opt = {}) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/wikicloth/section.rb', line 70 def render(opt={}) = { :noedit => opt[:link_handler].nil? ? true : false }.merge(opt) if self.title.nil? ret = "" else ret = "\n#{@title}\n" end ret += self ret += "__TOC__" if @auto_toc ret += @children.collect { |c| c.render() } .join ret end |
#template=(val) ⇒ Object
25 26 27 |
# File 'lib/wikicloth/section.rb', line 25 def template=(val) @template = val end |
#title ⇒ Object
41 42 43 |
# File 'lib/wikicloth/section.rb', line 41 def title @clean_title end |
#title=(val) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/wikicloth/section.rb', line 29 def title=(val) if val =~ /^([=]{1,6})\s*(.*?)\s*(\1)/ @depth = $1.length @clean_title = $2 @title = val else @depth = 1 @clean_title = val @title = val end end |
#wikitext(opt = {}) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/wikicloth/section.rb', line 58 def wikitext(opt={}) = { :replace => {} }.merge(opt) if [:replace][self.id].nil? ret = "#{@title}#{self}" ret += @children.collect { |c| c.wikitext() }.join ret else [:replace][self.id] end end |