Class: WikiCloth::Parser
Constant Summary
WikiLinkHandler::CATEGORY_NAMESPACES, WikiLinkHandler::FILE_NAMESPACES, WikiLinkHandler::LANGUAGE_NAMESPACES
Class Method Summary
collapse
Instance Method Summary
collapse
#categories, #categories=, #external_link, #external_links, #external_links=, #find_reference_by_name, #function, #include_resource, #included_templates, #internal_links, #internal_links=, #languages, #languages=, #link_attributes_for, #link_for, #link_for_resource, #params, #params=, #reference_index, #references, #references=, #section_link, #section_list, #template, #toc, #url_for
Constructor Details
#initialize(opt = {}) ⇒ Parser
Returns a new instance of Parser.
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/wikicloth/parser.rb', line 5
def initialize(opt={})
opt.each { |k,v|
if v.instance_of?(Proc)
self.class.send :define_method, k.to_sym do |*args|
self.instance_exec(args,&v)
end
end
}
@params = opt[:params] || {}
@wikicloth = WikiCloth.new(:data => opt[:data], :link_handler => self, :params => @params)
end
|
Class Method Details
.external_link(&block) ⇒ Object
36
37
38
39
40
|
# File 'lib/wikicloth/parser.rb', line 36
def external_link(&block)
self.send :define_method, 'external_link' do |url,text|
self.instance_exec(url,text,&block)
end
end
|
.function(&block) ⇒ Object
30
31
32
33
34
|
# File 'lib/wikicloth/parser.rb', line 30
def function(&block)
self.send :define_method, 'function' do |name, params|
self.instance_exec(name, params, &block)
end
end
|
.include_resource(&block) ⇒ Object
42
43
44
45
46
47
|
# File 'lib/wikicloth/parser.rb', line 42
def include_resource(&block)
self.send :define_method, 'include_resource' do |resource,options|
options ||= []
self.instance_exec(resource,options,&block)
end
end
|
.link_attributes_for(&block) ⇒ Object
74
75
76
77
78
|
# File 'lib/wikicloth/parser.rb', line 74
def link_attributes_for(&block)
self.send :define_method, 'link_attributes_for' do |page|
self.instance_exec(page,&block)
end
end
|
.link_for(&block) ⇒ Object
68
69
70
71
72
|
# File 'lib/wikicloth/parser.rb', line 68
def link_for(&block)
self.send :define_method, 'link_for' do |page,text|
self.instance_exec(page,text,&block)
end
end
|
.link_for_resource(&block) ⇒ Object
55
56
57
58
59
60
|
# File 'lib/wikicloth/parser.rb', line 55
def link_for_resource(&block)
self.send :define_method, 'link_for_resource' do |prefix,resource,options|
options ||= []
self.instance_exec(prefix,resource,options,&block)
end
end
|
.section_link(&block) ⇒ Object
62
63
64
65
66
|
# File 'lib/wikicloth/parser.rb', line 62
def section_link(&block)
self.send :define_method, 'section_link' do |section|
self.instance_exec(section,&block)
end
end
|
.template(&block) ⇒ Object
49
50
51
52
53
|
# File 'lib/wikicloth/parser.rb', line 49
def template(&block)
self.send :define_method, 'template' do |template|
self.instance_exec(template,&block)
end
end
|
.toc(&block) ⇒ Object
24
25
26
27
28
|
# File 'lib/wikicloth/parser.rb', line 24
def toc(&block)
self.send :define_method, 'toc' do |sections|
self.instance_exec(sections, &block)
end
end
|
.url_for(&block) ⇒ Object
18
19
20
21
22
|
# File 'lib/wikicloth/parser.rb', line 18
def url_for(&block)
self.send :define_method, 'url_for' do |url|
self.instance_exec(url, &block)
end
end
|
Instance Method Details
#get_section(id) ⇒ Object
Get the section, along with any sub-section of the document
88
89
90
|
# File 'lib/wikicloth/parser.rb', line 88
def get_section(id)
@wikicloth.sections.collect { |s| s.get_section(id) }.join
end
|
#put_section(id, data) ⇒ Object
Replace a section, along with any sub-section in the document
82
83
84
85
|
# File 'lib/wikicloth/parser.rb', line 82
def put_section(id,data)
data = @wikicloth.sections.collect { |s| s.wikitext({ :replace => { id => data.last(1) == "\n" ? data : "#{data}\n" } }) }.join
@wikicloth = WikiCloth.new(:data => data, :link_handler => self, :params => @params)
end
|
92
93
94
|
# File 'lib/wikicloth/parser.rb', line 92
def sections
@wikicloth.sections
end
|
#to_html(opts = {}) ⇒ Object
96
97
98
|
# File 'lib/wikicloth/parser.rb', line 96
def to_html(opts = {})
@wikicloth.to_html(opts)
end
|
100
101
102
|
# File 'lib/wikicloth/parser.rb', line 100
def to_wiki
to_wikitext
end
|
#to_wikitext ⇒ Object
104
105
106
|
# File 'lib/wikicloth/parser.rb', line 104
def to_wikitext
@wikicloth.sections.collect { |s| s.wikitext() }.join
end
|