11
by Jacques Distler
Replaced diff.rb with xhtmldiff.rb, which (unlike its predecessor) produces well-formed redline documents.
1
require 'xhtmldiff'
131
by Jacques Distler
More fixes, sync with HTML5lib
2
1
by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
3
# Temporary class containing all rendering stuff from a Revision
4
# I want to shift all rendering loguc to the controller eventually
8
def self.setup_url_generator(url_generator)
9
@@url_generator = url_generator
12
def self.teardown_url_generator
18
def initialize(revision = nil)
19
self.revision = revision
927
by Jacques Distler
Whitespace and a MIME-type
24
@display_content = @display_published = @wiki_words_cache = @wiki_includes_cache =
1
by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
25
@wiki_references_cache = nil
28
def display_content(update_references = false)
29
@display_content ||= render(:update_references => update_references)
32
def display_content_for_export
33
render :mode => :export
37
@display_published ||= render(:mode => :publish)
861
by Jacques Distler
Atom feed for changes in XHTML diff form
40
def display_diff(styles = {})
1
by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
41
previous_revision = @revision.page.previous_revision(@revision)
11
by Jacques Distler
Replaced diff.rb with xhtmldiff.rb, which (unlike its predecessor) produces well-formed redline documents.
43
875
by Jacques Distler
Also fix generation of diffs for previous issue
44
previous_content = "<div xmlns:se='http://svg-edit.googlecode.com' xmlns:xlink='http://www.w3.org/1999/xlink'>" + WikiContent.new(previous_revision, @@url_generator).render!.to_s + "</div>"
45
current_content = "<div xmlns:se='http://svg-edit.googlecode.com' xmlns:xlink='http://www.w3.org/1999/xlink'>" + display_content.to_s + "</div>"
11
by Jacques Distler
Replaced diff.rb with xhtmldiff.rb, which (unlike its predecessor) produces well-formed redline documents.
46
diff_doc = REXML::Document.new
131
by Jacques Distler
More fixes, sync with HTML5lib
47
div = REXML::Element.new('div', nil, {:respect_whitespace =>:all})
48
div.attributes['class'] = 'xhtmldiff_wrapper'
861
by Jacques Distler
Atom feed for changes in XHTML diff form
50
hd = XHTMLDiff.new(div, styles)
11
by Jacques Distler
Replaced diff.rb with xhtmldiff.rb, which (unlike its predecessor) produces well-formed redline documents.
51
52
parsed_previous_revision = REXML::HashableElementDelegator.new(
53
REXML::XPath.first(REXML::Document.new(previous_content), '/div'))
54
parsed_display_content = REXML::HashableElementDelegator.new(
55
REXML::XPath.first(REXML::Document.new(current_content), '/div'))
56
Diff::LCS.traverse_balanced(parsed_previous_revision, parsed_display_content, hd)
59
diff_doc.write(diffs, -1, true, true)
637
by Jacques Distler
Rails_xss Plugin
60
diffs.gsub(/\A<div class='xhtmldiff_wrapper'>(.*)<\/div>\Z/m, '1円').html_safe
1
by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
61
else
152
by Jacques Distler
Use Standard PageRenderer for S5 Content
66
attr :s5_theme
71
# Renders an S5 slideshow
73
@display_s5 ||= render(:mode => :s5,
265
by Jacques Distler
Upgrade to Rails 2.2.0
74
:engine_opts => {:author => @author, :title => @plain_name},
152
by Jacques Distler
Use Standard PageRenderer for S5 Content
76
end
1
by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
78
# Returns an array of all the WikiIncludes present in the content of this revision.
927
by Jacques Distler
Whitespace and a MIME-type
80
unless @wiki_includes_cache
1
by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
81
chunks = display_content.find_chunks(Include)
82
@wiki_includes_cache = chunks.map { |c| ( c.escaped? ? nil : c.page_name ) }.compact.uniq
87
# Returns an array of all the WikiReferences present in the content of this revision.
89
unless @wiki_references_cache
90
chunks = display_content.find_chunks(WikiChunk::WikiReference)
91
@wiki_references_cache = chunks.map { |c| ( c.escaped? ? nil : c.page_name ) }.compact.uniq
93
@wiki_references_cache
96
# Returns an array of all the WikiWords present in the content of this revision.
98
@wiki_words_cache ||= find_wiki_words(display_content)
927
by Jacques Distler
Whitespace and a MIME-type
100
1
by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
101
def find_wiki_words(rendering_result)
332
by Jacques Distler
Referring Pages for File List
102
the_wiki_words = wiki_links(rendering_result)
1
by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
103
# Exclude backslash-escaped wiki words, such as \WikiWord, as well as links to files
104
# and pictures, such as [[foo.txt:file]] or [[foo.jpg:pic]]
792
by Jacques Distler
Missed this bit for CDF support
105
the_wiki_words.delete_if { |link| link.escaped? or [:pic, :file, :cdf, :audio, :video, :delete].include?(link.link_type) }
1
by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
106
# convert to the list of unique page names
332
by Jacques Distler
Referring Pages for File List
107
the_wiki_words.map { |link| ( link.page_name ) }.uniq
110
# Returns an array of all the WikiWords present in the content of this revision.
112
@wiki_files_cache ||= find_wiki_files(display_content)
927
by Jacques Distler
Whitespace and a MIME-type
114
332
by Jacques Distler
Referring Pages for File List
115
def find_wiki_files(rendering_result)
116
the_wiki_files = wiki_links(rendering_result)
792
by Jacques Distler
Missed this bit for CDF support
117
the_wiki_files.delete_if { |link| ![:pic, :file, :cdf, :audio, :video].include?(link.link_type) }
332
by Jacques Distler
Referring Pages for File List
118
the_wiki_files.map { |link| ( link.page_name ) }.uniq
121
def wiki_links(rendering_result)
122
rendering_result.find_chunks(WikiChunk::WikiLink)
1
by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
123
end
125
# Returns an array of all the WikiWords present in the content of this revision.
126
# that already exists as a page in the web.
128
wiki_words.select { |wiki_word| @revision.page.web.page(wiki_word) }
131
# Returns an array of all the WikiWords present in the content of this revision
132
# that *doesn't* already exists as a page in the web.
134
wiki_words - existing_pages
139
def render(options = {})
140
rendering_result = WikiContent.new(@revision, @@url_generator, options).render!
141
update_references(rendering_result) if options[:update_references]
145
def update_references(rendering_result)
146
WikiReference.delete_all ['page_id = ?', @revision.page_id]
148
references = @revision.page.wiki_references
150
wiki_words = find_wiki_words(rendering_result)
151
# TODO it may be desirable to save links to files and pictures as WikiReference objects
152
# present version doesn't do it
154
wiki_words.each do |referenced_name|
155
# Links to self are always considered linked
156
if referenced_name == @revision.page.name
157
link_type = WikiReference::LINKED_PAGE
159
link_type = WikiReference.link_type(@revision.page.web, referenced_name)
180
by Jacques Distler
New Version
161
references.build :referenced_name => referenced_name, :link_type => link_type
1
by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
162
end
927
by Jacques Distler
Whitespace and a MIME-type
163
332
by Jacques Distler
Referring Pages for File List
164
wiki_files = find_wiki_files(rendering_result)
165
wiki_files.each do |referenced_name|
166
references.build :referenced_name => referenced_name, :link_type => WikiReference::FILE
927
by Jacques Distler
Whitespace and a MIME-type
168
1
by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
169
include_chunks = rendering_result.find_chunks(Include)
170
includes = include_chunks.map { |c| ( c.escaped? ? nil : c.page_name ) }.compact.uniq
171
includes.each do |included_page_name|
927
by Jacques Distler
Whitespace and a MIME-type
172
references.build :referenced_name => included_page_name,
1
by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
173
:link_type => WikiReference::INCLUDED_PAGE
927
by Jacques Distler
Whitespace and a MIME-type
175
389
by Jacques Distler
Wiki Redirects and Page Renaming
176
redirect_chunks = rendering_result.find_chunks(Redirect)
177
redirects = redirect_chunks.map { |c| ( c.escaped? ? nil : c.page_name ) }.compact.uniq
178
redirects.each do |redirected_page_name|
927
by Jacques Distler
Whitespace and a MIME-type
179
references.build :referenced_name => redirected_page_name,
389
by Jacques Distler
Wiki Redirects and Page Renaming
180
:link_type => WikiReference::REDIRECTED_PAGE
927
by Jacques Distler
Whitespace and a MIME-type
182
391
by Jacques Distler
Expire Caches for Redirected Links
183
# ugly hack: store these in a thread-local variable, so that the cache-sweeper has access to it.
184
Thread.current[:page_redirects] ?
397
by Jacques Distler
Another Bug-fix and some tests
185
Thread.current[:page_redirects].update({ @revision.page => redirects}) :
186
Thread.current[:page_redirects] = { @revision.page => redirects}
927
by Jacques Distler
Whitespace and a MIME-type
187
1
by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
188
categories = rendering_result.find_chunks(Category).map { |cat| cat.list }.flatten
189
categories.each do |category|
180
by Jacques Distler
New Version
190
references.build :referenced_name => category, :link_type => WikiReference::CATEGORY
1
by Jacques Distler
Checkout of Instiki Trunk 1/21/2007.
191
end