Class: Wiki2Go::Formatter
Instance Attribute Summary
#config
Instance Method Summary
collapse
-
#format_page(content) ⇒ Object
-
#format_page_in_template(template, page) ⇒ Object
-
#format_pagelist_in_template(template, pages, searchtopic, title) ⇒ Object
-
#generate_rss(template, changes) ⇒ Object
-
#generate_rss_from_log(log) ⇒ Object
-
#initialize(web, storage, config, generate_html, editable) ⇒ Formatter
constructor
A new instance of Formatter.
-
#put_page_in_template(template, page) ⇒ Object
#absolute_url, #absolute_url_of_topic, #admin_link, #changes_link, #changes_url, #edit_link, #edit_this_link, #encode_mail_to, #format_line, #formatting_done, #make_url, #make_verb_url, #perform_link, #query_string, #redirect_link, #redirect_url, #removespam_url, #resource_url, #save_this_link, #save_url, #search_link, #search_link2, #search_url, #verb_url, #version_link, #version_url, #view_link, #view_page_url, #view_url, #view_version_link, #view_version_url
Constructor Details
#initialize(web, storage, config, generate_html, editable) ⇒ Formatter
Returns a new instance of Formatter.
35
36
37
|
# File 'lib/Wiki2Go/WikiFormatter.rb', line 35
def initialize(web,storage,config,generate_html,editable)
super(web,storage,config,generate_html,editable)
end
|
Instance Method Details
#format_page(content) ⇒ Object
68
69
70
71
72
|
# File 'lib/Wiki2Go/WikiFormatter.rb', line 68
def format_page(content)
result = format_page_content(content)
result += formatting_done
return format_empty_lines(result)
end
|
#format_page_in_template(template, page) ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'lib/Wiki2Go/WikiFormatter.rb', line 41
def format_page_in_template(template,page)
formatted_page = format_page(page.content)
template = splice_variable_values(template,page,formatted_page)
erb = ERB.new(template)
context = PageContext.new(@config,self,formatted_page,page,@web,nil,nil,nil)
template = evaluate(erb,context)
return template
end
|
#format_pagelist_in_template(template, pages, searchtopic, title) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/Wiki2Go/WikiFormatter.rb', line 50
def format_pagelist_in_template(template,pages,searchtopic,title)
template = splice_web_values(template)
erb = ERB.new(template)
context = PageContext.new(@config,self,nil,nil,@web,pages,searchtopic,title)
template = evaluate(erb,context)
return template
end
|
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/Wiki2Go/WikiFormatter.rb', line 75
def (template,changes)
old_absolute_urls = @absolute_urls
@absolute_urls = true
template_after_items = <<-END_OF_AFTER_ITEMS_XML
</channel>
</rss>
END_OF_AFTER_ITEMS_XML
items = ""
changes.each do |page|
items = items + <<-END_OF_ITEMS
<item>
<title>#{CGI::escapeHTML(page.name)}</title>
<author>#{page.alias}</author>
<pubDate>#{@config.blog_style ? page.created_on.strftime("%d %B %Y %H:%M GMT") : page.lastmodified.strftime("%d %B %Y %H:%M GMT")}</pubDate>
<link>#{absolute_url_of_topic(page.filename)}</link>
<guid isPermaLink="true">#{@web.name}/#{page.filename}</guid>
<description><![CDATA[#{format_page(page.content).strip}]]></description>
</item>
END_OF_ITEMS
end
template = template + items + template_after_items
time = Time.new.gmtime.strftime("%d %B %Y %H:%M GMT")
template.gsub!(/\$DATE\$/, time)
template = splice_web_values(template)
@absolute_urls = old_absolute_urls
return template
end
|
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/Wiki2Go/WikiFormatter.rb', line 113
def (log)
= <<END_OF_HEADER
<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0" >
<channel>
<title>#{@web.base_url} Wiki2Go Errorlog</title>
<link>#{@web.base_url}</link>
<description>#{@web.name} wiki errorlog</description>
<language>en-us</language>
<pubDate>#{Time.new.gmtime.strftime("%d %B %Y %H:%M GMT")}</pubDate>
<lastBuildDate>#{Time.new.gmtime.strftime("%d %B %Y %H:%M GMT")}</lastBuildDate>
<docs>http://backend.userland.com/rss</docs>
END_OF_HEADER
template_after_items = <<-END_OF_AFTER_ITEMS_XML
</channel>
</rss>
END_OF_AFTER_ITEMS_XML
items = ""
log.each do |line|
if line =~ /^(\w), \[([^\]]+)\][^:]*: (.+)$/ then
type = $1
datetime = $2
message = $3
if type == 'E' then
items = items + <<-END_OF_ITEMS
<item>
<title>#{CGI::escapeHTML('errormessage')}</title>
<link>#{File.join(@web.base_url,'scripts/secure/admin/show_log')}</link>
<author>Wiki2Go</author>
<pubDate>#{parse_log_date(datetime).strftime("%d %B %Y %H:%M GMT")}</pubDate>
<description><![CDATA[#{message}]]></description>
</item>
END_OF_ITEMS
end
end
end
return + items + template_after_items
end
|
#put_page_in_template(template, page) ⇒ Object
58
59
60
61
62
63
64
65
66
|
# File 'lib/Wiki2Go/WikiFormatter.rb', line 58
def put_page_in_template(template,page)
formatted_page = page.content.gsub(/&/n, '&').gsub(/\"/n, '"').gsub(/>/n, '>').gsub(/</n, '<')
template = splice_variable_values(template,page,formatted_page)
erb = ERB.new(template)
context = PageContext.new(@config,self,formatted_page,page,@web,nil,nil,nil)
template = evaluate(erb,context)
return template
end
|