Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 344
- Log:
Massive changeset which brings the old, ROOL customised Instiki
version up to date, but without any ROOL customisations in this
latest checked-in version (which is 0.19.1). This is deliberate,
so that it's easy to see the changes made for the ROOL version
in a subsequent changeset. The 'app/views/shared' directory is not
part of Instiki but is kept to maintain the change history with
updated ROOL customisations, some of which involve the same files
in that same directory.
- Author:
- rool
- Date:
- Sat Mar 19 19:52:13 +0000 2011
- Size:
- 4804 Bytes
1 | require 'chunks/chunk' |
2 | require 'instiki_stringsupport' |
3 | |
4 | # Contains all the methods for finding and replacing wiki related links. |
5 | module WikiChunk |
6 | include Chunk |
7 | |
8 | # A wiki reference is the top-level class for anything that refers to |
9 | # another wiki page. |
10 | class WikiReference < Chunk::Abstract |
11 | |
12 | # Name of the referenced page |
13 | attr_reader :page_name |
14 | |
15 | # Name of the referenced page |
16 | attr_reader :web_name |
17 | |
18 | # the referenced page |
19 | def refpage |
20 | @content.web.page(@page_name) |
21 | end |
22 | |
23 | end |
24 | |
25 | # A wiki link is the top-level class for links that refers to |
26 | # another wiki page. |
27 | class WikiLink < WikiReference |
28 | |
29 | attr_reader :link_text, :link_type |
30 | |
31 | def initialize(match_data, content) |
32 | super |
33 | @link_type = :show |
34 | end |
35 | |
36 | def self.apply_to(content) |
37 | content.as_utf8.gsub!( self.pattern ) do |matched_text| |
38 | chunk = self.new($~, content) |
39 | if chunk.textile_url? |
40 | # do not substitute |
41 | matched_text |
42 | else |
43 | content.add_chunk(chunk) |
44 | chunk.mask |
45 | end |
46 | end |
47 | end |
48 | |
49 | def textile_url? |
50 | not @textile_link_suffix.nil? |
51 | end |
52 | |
53 | def interweb_link? |
54 | not @web_name.nil? and Web.find_by_name(@web_name) or |
55 | Web.find_by_address(@web_name) |
56 | end |
57 | |
58 | # replace any sequence of whitespace characters with a single space |
59 | def normalize_whitespace(line) |
60 | line.gsub(/\s+/, ' ') |
61 | end |
62 | |
63 | end |
64 | |
65 | # This chunk matches a WikiWord. WikiWords can be escaped |
66 | # by prepending a '\'. When this is the case, the +escaped_text+ |
67 | # method will return the WikiWord instead of the usual +nil+. |
68 | # The +page_name+ method returns the matched WikiWord. |
69 | class Word < WikiLink |
70 | |
71 | attr_reader :escaped_text |
72 | |
73 | unless defined? WIKI_WORD |
74 | WIKI_WORD = ''.respond_to?(:force_encoding) ? |
75 | Regexp.new('(":)?(\\\\)?(' + WikiWords::WIKI_WORD_PATTERN + ')\b', 0) : |
76 | Regexp.new('(":)?(\\\\)?(' + WikiWords::WIKI_WORD_PATTERN + ')\b', 0, 'u') |
77 | end |
78 | |
79 | def self.pattern |
80 | WIKI_WORD |
81 | end |
82 | |
83 | def initialize(match_data, content) |
84 | super |
85 | @textile_link_suffix, @escape, @page_name = match_data[1..3] |
86 | if @escape |
87 | @unmask_mode = :escape |
88 | @escaped_text = @page_name |
89 | else |
90 | @escaped_text = nil |
91 | end |
92 | @link_text = WikiWords.separate(@page_name) |
93 | @unmask_text = (@escaped_text || @content.page_link(@web_name, @page_name, @link_text, @link_type)) |
94 | end |
95 | |
96 | end |
97 | |
98 | # This chunk handles [[bracketted wiki words]] and |
99 | # [[AliasedWords|aliased wiki words]]. The first part of an |
100 | # aliased wiki word must be a WikiWord. If the WikiWord |
101 | # is aliased, the +link_text+ field will contain the |
102 | # alias, otherwise +link_text+ will contain the entire |
103 | # contents within the double brackets. |
104 | # |
105 | # NOTE: This chunk must be tested before WikiWord since |
106 | # a WikiWords can be a substring of a WikiLink. |
107 | class Link < WikiLink |
108 | |
109 | unless defined? WIKI_LINK |
110 | WIKI_LINK = /(":)?\[\[\s*([^\]\s][^\]]*?)\s*\]\]/ |
111 | LINK_TYPE_SEPARATION = Regexp.new('^(.+):((file)|(pic)|(video)|(audio)|(delete))$', 0) |
112 | ALIAS_SEPARATION = Regexp.new('^(.+)\|(.+)$', 0) |
113 | WEB_SEPARATION = Regexp.new('^(.+):(.+)$', 0) |
114 | end |
115 | |
116 | def self.pattern() WIKI_LINK end |
117 | |
118 | def initialize(match_data, content) |
119 | super |
120 | @textile_link_suffix = match_data[1] |
121 | @link_text = @page_name = normalize_whitespace(match_data[2]) |
122 | separate_link_type |
123 | separate_alias |
124 | separate_web |
125 | @unmask_text = @content.page_link(@web_name, @page_name, @link_text, @link_type) |
126 | end |
127 | |
128 | private |
129 | |
130 | # if link wihin the brackets has a form of [[filename:file]] or [[filename:pic]], |
131 | # this means a link to a picture or a file |
132 | def separate_link_type |
133 | link_type_match = LINK_TYPE_SEPARATION.match(@page_name) |
134 | if link_type_match |
135 | @link_text = @page_name = link_type_match[1] |
136 | @link_type = link_type_match[2..3].compact[0].to_sym |
137 | end |
138 | end |
139 | |
140 | # link text may be different from page name. this will look like [[actual page|link text]] |
141 | def separate_alias |
142 | alias_match = ALIAS_SEPARATION.match(@page_name) |
143 | if alias_match |
144 | @page_name = normalize_whitespace(alias_match[1]) |
145 | @link_text = alias_match[2] |
146 | end |
147 | # note that [[filename|link text:file]] is also supported |
148 | end |
149 | |
150 | # Interweb links have the form [[Web Name:Page Name]] or |
151 | # [[address:PageName]]. Alternate text links of the form |
152 | # [[address:PageName|Other text]] are also supported. |
153 | def separate_web |
154 | web_match = WEB_SEPARATION.match(@page_name) |
155 | if web_match |
156 | @web_name = normalize_whitespace(web_match[1]) |
157 | @page_name = web_match[2] |
158 | @link_text = @page_name if @link_text == web_match[0] |
159 | end |
160 | end |
161 | |
162 | end |
163 | |
164 | end |