Class: WikiCloth::WikiCloth
Instance Method Summary collapse
-
#initialize(opt = {}) ⇒ WikiCloth
constructor
A new instance of WikiCloth.
- #link_handler ⇒ Object
- #load(data, p = {}) ⇒ Object
- #params ⇒ Object
- #render(opt = {}) ⇒ Object
- #sections ⇒ Object
- #to_html(opt = {}) ⇒ Object
Constructor Details
#initialize(opt = {}) ⇒ WikiCloth
Returns a new instance of WikiCloth.
15 16 17 18 |
# File 'lib/wikicloth.rb', line 15 def initialize(opt={}) self.[:link_handler] = opt[:link_handler] unless opt[:link_handler].nil? self.load(opt[:data],opt[:params]) unless opt[:data].nil? || opt[:data].blank? end |
Instance Method Details
#link_handler ⇒ Object
69 70 71 |
# File 'lib/wikicloth.rb', line 69 def link_handler self.[:link_handler] ||= WikiLinkHandler.new end |
#load(data, p = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/wikicloth.rb', line 20 def load(data,p={}) depth = 1 count = 0 root = [self.sections] # parse wiki document into sections data.each_line do |line| if line =~ /^([=]{1,6})\s*(.*?)\s*(\1)/ root << root.last[-1].children if $1.length > depth root.pop if $1.length < depth depth = $1.length root.last << Section.new(line, get_id_for($2.gsub(/\s+/,'_'))) count += 1 else root.last[-1] << line end end # if we find template variables assume document is # a template self.sections.first.template = true if data =~ /\{\{\{\s*([A-Za-z0-9]+)\s*\}\}\}/ # If there are more than four sections enable automatic # table of contents self.sections.first.auto_toc = true unless count < 4 || data =~ /__(NO|)TOC__/ self.params = p end |
#params ⇒ Object
73 74 75 |
# File 'lib/wikicloth.rb', line 73 def params @page_params ||= {} end |
#render(opt = {}) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/wikicloth.rb', line 53 def render(opt={}) noedit = false self.params.merge!({ 'WIKI_VERSION' => ::WikiCloth::VERSION }) self. = { :output => :html, :link_handler => self.link_handler, :params => self.params, :sections => self.sections }.merge(opt) self.[:link_handler].params = [:params] data = self.sections.first.render(self.) data.gsub!(/<!--(.|\s)*?-->/,"") buffer = WikiBuffer.new("",) data.each_char { |c| buffer.add_char(c) } buffer.to_s end |
#sections ⇒ Object
49 50 51 |
# File 'lib/wikicloth.rb', line 49 def sections @sections ||= [Section.new] end |
#to_html(opt = {}) ⇒ Object
65 66 67 |
# File 'lib/wikicloth.rb', line 65 def to_html(opt={}) self.render(opt) end |