Class: Wiki2Go::Formatter

Inherits:
LineFormatter show all
Defined in:
lib/Wiki2Go/WikiFormatter.rb

Direct Known Subclasses

HTMLFormatter

Instance Attribute Summary

Attributes inherited from LineFormatter

#config

Instance Method Summary collapse

Methods inherited from LineFormatter

#absolute_url, #absolute_url_of_topic, #admin_link, #changes_link, #changes_url, #diff_link, #diff_url, #edit_link, #edit_this_link, #editor_link, #editor_link2, #editor_this_link, #encode_mail_to, #format_line, #formatting_done, #link_to, #link_to_new_page, #make_url, #make_verb_url, #redirect_link, #redirect_url, #removespam_url, #resource_link, #resource_url, #save_url, #search_link, #search_url, #sidebyside_link, #sidebyside_url, #verb_url, #versions_link, #versions_url, #view_link, #view_url, #view_version_link, #view_version_url, #wikiedit_link, #wikiedit_this_link

Constructor Details

#initialize(web, storage, config, generate_html, editable) ⇒ Formatter

Returns a new instance of Formatter.


49
50
51
# File 'lib/Wiki2Go/WikiFormatter.rb', line 49

def initialize(web,storage,config,generate_html,editable)
  super(web,storage,config,generate_html,editable)
end

Instance Method Details

#dump_page_in_template(template, page, from, to) ⇒ Object


83
84
85
86
87
88
89
90
91
92
# File 'lib/Wiki2Go/WikiFormatter.rb', line 83

def dump_page_in_template(template,page,from,to)
  formatted_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)
  context.versions(from,to)
  template = evaluate(erb,context)
  return template
end

#format_page(content) ⇒ Object


94
95
96
97
98
# File 'lib/Wiki2Go/WikiFormatter.rb', line 94

def format_page(content)
  result = format_page_content(content)
  result += formatting_done
  return format_empty_lines(result)
end

#format_page_in_template(template, page, version = -1)) ⇒ Object


55
56
57
58
59
60
61
62
63
# File 'lib/Wiki2Go/WikiFormatter.rb', line 55

def format_page_in_template(template,page,version=-1) 
  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)
  context.versions(version-1,version)
  template = evaluate(erb,context)
  return template
end

#format_pagelist_in_template(template, pages, searchtopic, title) ⇒ Object


65
66
67
68
69
70
71
# File 'lib/Wiki2Go/WikiFormatter.rb', line 65

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

#generate_rss(template, changes) ⇒ Object


101
102
103
104
105
106
107
108
109
110
111
112
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
# File 'lib/Wiki2Go/WikiFormatter.rb', line 101

def generate_rss(template,changes)

  # RSS must contain absolute URLs because some feedreaders don't honor the relative
  #  URLs to the content of the <link> tag
  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">#{absolute_url_of_topic(page.filename)}</guid>
    END_OF_ITEMS
    
    if !Page.is_dynamic?(page.filename) then
      items += "<description><![CDATA[#{format_page(page.content).strip}]]></description>\n"
    end
    items += "</item>\n"
        
  end
    
  template = template + items + template_after_items
    
  # We're using hard coded GMT, because %Z returns something strange
  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

#generate_rss_from_log(log) ⇒ Object


143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/Wiki2Go/WikiFormatter.rb', line 143

def generate_rss_from_log(log)
  header = <<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[#{CGI::escapeHTML(message)}]]></description>
    </item>
        END_OF_ITEMS
      end
    end
  end

  #        <link>#{absolute_url_of_topic(page.filename)}</link>
  #        <guid isPermaLink="true">#{@web.name}/#{page.filename}</guid>

  return header + items + template_after_items
    
end

#put_page_in_template(template, page) ⇒ Object


73
74
75
76
77
78
79
80
81
# File 'lib/Wiki2Go/WikiFormatter.rb', line 73

def put_page_in_template(template,page) 
  formatted_page = CGI::escapeHTML(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