Class: WikiCloth::Section

Inherits:
String
  • Object
show all
Defined in:
lib/wikicloth/section.rb

Instance Method Summary collapse

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

#childrenObject



13
14
15
# File 'lib/wikicloth/section.rb', line 13

def children
  @children
end

#depthObject



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

#idObject



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={})
  options = { :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(options) } .join
  ret
end

#template=(val) ⇒ Object



25
26
27
# File 'lib/wikicloth/section.rb', line 25

def template=(val)
  @template = val
end

#titleObject



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={})
  options = { :replace => {} }.merge(opt)

  if options[:replace][self.id].nil?
    ret = "#{@title}#{self}"
    ret += @children.collect { |c| c.wikitext(options) }.join
    ret
  else
    options[:replace][self.id]
  end
end