class WikiCloth::Section

Public Class Methods

new(title=nil, id=nil) click to toggle source
# 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

Public Instance Methods

auto_toc=(val) click to toggle source
# File lib/wikicloth/section.rb, line 21
def auto_toc=(val)
  @auto_toc = val
end
children() click to toggle source
# File lib/wikicloth/section.rb, line 13
def children
  @children
end
depth() click to toggle source
# File lib/wikicloth/section.rb, line 45
def depth
  @depth ||= 1
end
get_section(id) click to toggle source
# 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() click to toggle source
# File lib/wikicloth/section.rb, line 17
def id
  @id
end
render(opt={}) click to toggle source
# 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) click to toggle source
# File lib/wikicloth/section.rb, line 25
def template=(val)
  @template = val
end
title() click to toggle source
# File lib/wikicloth/section.rb, line 41
def title
  @clean_title
end
title=(val) click to toggle source
# 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={}) click to toggle source
# 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