Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 2
- Log:
Initial import of Instiki 0.11.0 sources from a downloaded Tarball.
Instiki is a Ruby On Rails based Wiki clone.
- Author:
- adh
- Date:
- Sat Jul 22 14:54:51 +0100 2006
- Size:
- 4001 Bytes
1 | require 'wiki_words' |
2 | require 'chunks/chunk' |
3 | require 'chunks/wiki' |
4 | require 'cgi' |
5 | |
6 | # Contains all the methods for finding and replacing wiki related links. |
7 | module WikiChunk |
8 | include Chunk |
9 | |
10 | # A wiki reference is the top-level class for anything that refers to |
11 | # another wiki page. |
12 | class WikiReference < Chunk::Abstract |
13 | |
14 | # Name of the referenced page |
15 | attr_reader :page_name |
16 | |
17 | # the referenced page |
18 | def refpage |
19 | @content.web.page(@page_name) |
20 | end |
21 | |
22 | end |
23 | |
24 | # A wiki link is the top-level class for links that refers to |
25 | # another wiki page. |
26 | class WikiLink < WikiReference |
27 | |
28 | attr_reader :link_text, :link_type |
29 | |
30 | def initialize(match_data, content) |
31 | super |
32 | @link_type = :show |
33 | end |
34 | |
35 | def self.apply_to(content) |
36 | content.gsub!( self.pattern ) do |matched_text| |
37 | chunk = self.new($~, content) |
38 | if chunk.textile_url? |
39 | # do not substitute |
40 | matched_text |
41 | else |
42 | content.add_chunk(chunk) |
43 | chunk.mask |
44 | end |
45 | end |
46 | end |
47 | |
48 | def textile_url? |
49 | not @textile_link_suffix.nil? |
50 | end |
51 | |
52 | # replace any sequence of whitespace characters with a single space |
53 | def normalize_whitespace(line) |
54 | line.gsub(/\s+/, ' ') |
55 | end |
56 | |
57 | end |
58 | |
59 | # This chunk matches a WikiWord. WikiWords can be escaped |
60 | # by prepending a '\'. When this is the case, the +escaped_text+ |
61 | # method will return the WikiWord instead of the usual +nil+. |
62 | # The +page_name+ method returns the matched WikiWord. |
63 | class Word < WikiLink |
64 | |
65 | attr_reader :escaped_text |
66 | |
67 | unless defined? WIKI_WORD |
68 | WIKI_WORD = Regexp.new('(":)?(\\\\)?(' + WikiWords::WIKI_WORD_PATTERN + ')\b', 0, "utf-8") |
69 | end |
70 | |
71 | def self.pattern |
72 | WIKI_WORD |
73 | end |
74 | |
75 | def initialize(match_data, content) |
76 | super |
77 | @textile_link_suffix, @escape, @page_name = match_data[1..3] |
78 | if @escape |
79 | @unmask_mode = :escape |
80 | @escaped_text = @page_name |
81 | else |
82 | @escaped_text = nil |
83 | end |
84 | @link_text = WikiWords.separate(@page_name) |
85 | @unmask_text = (@escaped_text || @content.page_link(@page_name, @link_text, @link_type)) |
86 | end |
87 | |
88 | end |
89 | |
90 | # This chunk handles [[bracketted wiki words]] and |
91 | # [[AliasedWords|aliased wiki words]]. The first part of an |
92 | # aliased wiki word must be a WikiWord. If the WikiWord |
93 | # is aliased, the +link_text+ field will contain the |
94 | # alias, otherwise +link_text+ will contain the entire |
95 | # contents within the double brackets. |
96 | # |
97 | # NOTE: This chunk must be tested before WikiWord since |
98 | # a WikiWords can be a substring of a WikiLink. |
99 | class Link < WikiLink |
100 | |
101 | unless defined? WIKI_LINK |
102 | WIKI_LINK = /(":)?\[\[\s*([^\]\s][^\]]+?)\s*\]\]/ |
103 | LINK_TYPE_SEPARATION = Regexp.new('^(.+):((file)|(pic))$', 0, 'utf-8') |
104 | ALIAS_SEPARATION = Regexp.new('^(.+)\|(.+)$', 0, 'utf-8') |
105 | end |
106 | |
107 | def self.pattern() WIKI_LINK end |
108 | |
109 | def initialize(match_data, content) |
110 | super |
111 | @textile_link_suffix = match_data[1] |
112 | @link_text = @page_name = normalize_whitespace(match_data[2]) |
113 | separate_link_type |
114 | separate_alias |
115 | @unmask_text = @content.page_link(@page_name, @link_text, @link_type) |
116 | end |
117 | |
118 | private |
119 | |
120 | # if link wihin the brackets has a form of [[filename:file]] or [[filename:pic]], |
121 | # this means a link to a picture or a file |
122 | def separate_link_type |
123 | link_type_match = LINK_TYPE_SEPARATION.match(@page_name) |
124 | if link_type_match |
125 | @link_text = @page_name = link_type_match[1] |
126 | @link_type = link_type_match[2..3].compact[0].to_sym |
127 | end |
128 | end |
129 | |
130 | # link text may be different from page name. this will look like [[actual page|link text]] |
131 | def separate_alias |
132 | alias_match = ALIAS_SEPARATION.match(@page_name) |
133 | if alias_match |
134 | @page_name = normalize_whitespace(alias_match[1]) |
135 | @link_text = alias_match[2] |
136 | end |
137 | # note that [[filename|link text:file]] is also supported |
138 | end |
139 | |
140 | end |
141 | |
142 | |
143 | end |