@@ -1,59 +1,59 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class SettingsController < ApplicationController |
|
19 | 19 | before_filter :require_admin |
|
20 | 20 | |
|
21 | 21 | def index |
|
22 | 22 | edit |
|
23 | 23 | render :action => 'edit' |
|
24 | 24 | end |
|
25 | 25 | |
|
26 | 26 | def edit |
|
27 | 27 | @notifiables = %w(issue_added issue_updated news_added document_added file_added message_posted) |
|
28 | 28 | if request.post? && params[:settings] && params[:settings].is_a?(Hash) |
|
29 | 29 | settings = (params[:settings] || {}).dup.symbolize_keys |
|
30 | 30 | settings.each do |name, value| |
|
31 | 31 | # remove blank values in array settings |
|
32 | 32 | value.delete_if {|v| v.blank? } if value.is_a?(Array) |
|
33 | 33 | Setting[name] = value |
|
34 | 34 | end |
|
35 | 35 | flash[:notice] = l(:notice_successful_update) |
|
36 | 36 | redirect_to :action => 'edit', :tab => params[:tab] |
|
37 | 37 | return |
|
38 | 38 | end |
|
39 | 39 | @options = {} |
|
40 | 40 | @options[:user_format] = User::USER_FORMATS.keys.collect {|f| [User.current.name(f), f.to_s] } |
|
41 | 41 | @deliveries = ActionMailer::Base.perform_deliveries |
|
42 | 42 | |
|
43 | @guessed_host_and_path = request.host_with_port | |
|
43 | @guessed_host_and_path = request.host_with_port.dup | |
|
44 | 44 | @guessed_host_and_path << ('/'+ request.relative_url_root.gsub(%r{^\/}, '')) unless request.relative_url_root.blank? |
|
45 | 45 | end |
|
46 | 46 | |
|
47 | 47 | def plugin |
|
48 | 48 | @plugin = Redmine::Plugin.find(params[:id]) |
|
49 | 49 | if request.post? |
|
50 | 50 | Setting["plugin_#{@plugin.id}"] = params[:settings] |
|
51 | 51 | flash[:notice] = l(:notice_successful_update) |
|
52 | 52 | redirect_to :action => 'plugin', :id => @plugin.id |
|
53 | 53 | end |
|
54 | 54 | @partial = @plugin.settings[:partial] |
|
55 | 55 | @settings = Setting["plugin_#{@plugin.id}"] |
|
56 | 56 | rescue Redmine::PluginNotFound |
|
57 | 57 | render_404 |
|
58 | 58 | end |
|
59 | 59 | end |
@@ -1,628 +1,627 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require 'coderay' |
|
19 | 19 | require 'coderay/helpers/file_type' |
|
20 | 20 | require 'forwardable' |
|
21 | 21 | require 'cgi' |
|
22 | 22 | |
|
23 | 23 | module ApplicationHelper |
|
24 | 24 | include Redmine::WikiFormatting::Macros::Definitions |
|
25 | 25 | include GravatarHelper::PublicMethods |
|
26 | 26 | |
|
27 | 27 | extend Forwardable |
|
28 | 28 | def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter |
|
29 | 29 | |
|
30 | 30 | def current_role |
|
31 | 31 | @current_role ||= User.current.role_for_project(@project) |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | # Return true if user is authorized for controller/action, otherwise false |
|
35 | 35 | def authorize_for(controller, action) |
|
36 | 36 | User.current.allowed_to?({:controller => controller, :action => action}, @project) |
|
37 | 37 | end |
|
38 | 38 | |
|
39 | 39 | # Display a link if user is authorized |
|
40 | 40 | def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference) |
|
41 | 41 | link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action]) |
|
42 | 42 | end |
|
43 | 43 | |
|
44 | 44 | # Display a link to remote if user is authorized |
|
45 | 45 | def link_to_remote_if_authorized(name, options = {}, html_options = nil) |
|
46 | 46 | url = options[:url] || {} |
|
47 | 47 | link_to_remote(name, options, html_options) if authorize_for(url[:controller] || params[:controller], url[:action]) |
|
48 | 48 | end |
|
49 | 49 | |
|
50 | 50 | # Display a link to user's account page |
|
51 | 51 | def link_to_user(user, options={}) |
|
52 | 52 | (user && !user.anonymous?) ? link_to(user.name(options[:format]), :controller => 'account', :action => 'show', :id => user) : 'Anonymous' |
|
53 | 53 | end |
|
54 | 54 | |
|
55 | 55 | def link_to_issue(issue, options={}) |
|
56 | 56 | options[:class] ||= '' |
|
57 | 57 | options[:class] << ' issue' |
|
58 | 58 | options[:class] << ' closed' if issue.closed? |
|
59 | 59 | link_to "#{issue.tracker.name} ##{issue.id}", {:controller => "issues", :action => "show", :id => issue}, options |
|
60 | 60 | end |
|
61 | 61 | |
|
62 | 62 | # Generates a link to an attachment. |
|
63 | 63 | # Options: |
|
64 | 64 | # * :text - Link text (default to attachment filename) |
|
65 | 65 | # * :download - Force download (default: false) |
|
66 | 66 | def link_to_attachment(attachment, options={}) |
|
67 | 67 | text = options.delete(:text) || attachment.filename |
|
68 | 68 | action = options.delete(:download) ? 'download' : 'show' |
|
69 | 69 | |
|
70 | 70 | link_to(h(text), {:controller => 'attachments', :action => action, :id => attachment, :filename => attachment.filename }, options) |
|
71 | 71 | end |
|
72 | 72 | |
|
73 | 73 | def toggle_link(name, id, options={}) |
|
74 | 74 | onclick = "Element.toggle('#{id}'); " |
|
75 | 75 | onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ") |
|
76 | 76 | onclick << "return false;" |
|
77 | 77 | link_to(name, "#", :onclick => onclick) |
|
78 | 78 | end |
|
79 | 79 | |
|
80 | 80 | def image_to_function(name, function, html_options = {}) |
|
81 | 81 | html_options.symbolize_keys! |
|
82 | 82 | tag(:input, html_options.merge({ |
|
83 | 83 | :type => "image", :src => image_path(name), |
|
84 | 84 | :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};" |
|
85 | 85 | })) |
|
86 | 86 | end |
|
87 | 87 | |
|
88 | 88 | def prompt_to_remote(name, text, param, url, html_options = {}) |
|
89 | 89 | html_options[:onclick] = "promptToRemote('#{text}', '#{param}', '#{url_for(url)}'); return false;" |
|
90 | 90 | link_to name, {}, html_options |
|
91 | 91 | end |
|
92 | 92 | |
|
93 | 93 | def format_date(date) |
|
94 | 94 | return nil unless date |
|
95 | 95 | # "Setting.date_format.size < 2" is a temporary fix (content of date_format setting changed) |
|
96 | 96 | @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format) |
|
97 | 97 | date.strftime(@date_format) |
|
98 | 98 | end |
|
99 | 99 | |
|
100 | 100 | def format_time(time, include_date = true) |
|
101 | 101 | return nil unless time |
|
102 | 102 | time = time.to_time if time.is_a?(String) |
|
103 | 103 | zone = User.current.time_zone |
|
104 | 104 | local = zone ? time.in_time_zone(zone) : (time.utc? ? time.localtime : time) |
|
105 | 105 | @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format) |
|
106 | 106 | @time_format ||= (Setting.time_format.blank? ? l(:general_fmt_time) : Setting.time_format) |
|
107 | 107 | include_date ? local.strftime("#{@date_format} #{@time_format}") : local.strftime(@time_format) |
|
108 | 108 | end |
|
109 | 109 | |
|
110 | 110 | def format_activity_title(text) |
|
111 | 111 | h(truncate_single_line(text, 100)) |
|
112 | 112 | end |
|
113 | 113 | |
|
114 | 114 | def format_activity_day(date) |
|
115 | 115 | date == Date.today ? l(:label_today).titleize : format_date(date) |
|
116 | 116 | end |
|
117 | 117 | |
|
118 | 118 | def format_activity_description(text) |
|
119 | 119 | h(truncate(text.to_s, 250).gsub(%r{<(pre|code)>.*$}m, '...')) |
|
120 | 120 | end |
|
121 | 121 | |
|
122 | 122 | def distance_of_date_in_words(from_date, to_date = 0) |
|
123 | 123 | from_date = from_date.to_date if from_date.respond_to?(:to_date) |
|
124 | 124 | to_date = to_date.to_date if to_date.respond_to?(:to_date) |
|
125 | 125 | distance_in_days = (to_date - from_date).abs |
|
126 | 126 | lwr(:actionview_datehelper_time_in_words_day, distance_in_days) |
|
127 | 127 | end |
|
128 | 128 | |
|
129 | 129 | def due_date_distance_in_words(date) |
|
130 | 130 | if date |
|
131 | 131 | l((date < Date.today ? :label_roadmap_overdue : :label_roadmap_due_in), distance_of_date_in_words(Date.today, date)) |
|
132 | 132 | end |
|
133 | 133 | end |
|
134 | 134 | |
|
135 | 135 | def render_page_hierarchy(pages, node=nil) |
|
136 | 136 | content = '' |
|
137 | 137 | if pages[node] |
|
138 | 138 | content << "<ul class=\"pages-hierarchy\">\n" |
|
139 | 139 | pages[node].each do |page| |
|
140 | 140 | content << "<li>" |
|
141 | 141 | content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'index', :id => page.project, :page => page.title}, |
|
142 | 142 | :title => (page.respond_to?(:updated_on) ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil)) |
|
143 | 143 | content << "\n" + render_page_hierarchy(pages, page.id) if pages[page.id] |
|
144 | 144 | content << "</li>\n" |
|
145 | 145 | end |
|
146 | 146 | content << "</ul>\n" |
|
147 | 147 | end |
|
148 | 148 | content |
|
149 | 149 | end |
|
150 | 150 | |
|
151 | 151 | # Renders flash messages |
|
152 | 152 | def render_flash_messages |
|
153 | 153 | s = '' |
|
154 | 154 | flash.each do |k,v| |
|
155 | 155 | s << content_tag('div', v, :class => "flash #{k}") |
|
156 | 156 | end |
|
157 | 157 | s |
|
158 | 158 | end |
|
159 | 159 | |
|
160 | 160 | # Truncates and returns the string as a single line |
|
161 | 161 | def truncate_single_line(string, *args) |
|
162 | 162 | truncate(string, *args).gsub(%r{[\r\n]+}m, ' ') |
|
163 | 163 | end |
|
164 | 164 | |
|
165 | 165 | def html_hours(text) |
|
166 | 166 | text.gsub(%r{(\d+)\.(\d+)}, '<span class="hours hours-int">\1</span><span class="hours hours-dec">.\2</span>') |
|
167 | 167 | end |
|
168 | 168 | |
|
169 | 169 | def authoring(created, author, options={}) |
|
170 | 170 | time_tag = @project.nil? ? content_tag('acronym', distance_of_time_in_words(Time.now, created), :title => format_time(created)) : |
|
171 | 171 | link_to(distance_of_time_in_words(Time.now, created), |
|
172 | 172 | {:controller => 'projects', :action => 'activity', :id => @project, :from => created.to_date}, |
|
173 | 173 | :title => format_time(created)) |
|
174 | 174 | author_tag = (author.is_a?(User) && !author.anonymous?) ? link_to(h(author), :controller => 'account', :action => 'show', :id => author) : h(author || 'Anonymous') |
|
175 | 175 | l(options[:label] || :label_added_time_by, author_tag, time_tag) |
|
176 | 176 | end |
|
177 | 177 | |
|
178 | 178 | def l_or_humanize(s, options={}) |
|
179 | 179 | k = "#{options[:prefix]}#{s}".to_sym |
|
180 | 180 | l_has_string?(k) ? l(k) : s.to_s.humanize |
|
181 | 181 | end |
|
182 | 182 | |
|
183 | 183 | def day_name(day) |
|
184 | 184 | l(:general_day_names).split(',')[day-1] |
|
185 | 185 | end |
|
186 | 186 | |
|
187 | 187 | def month_name(month) |
|
188 | 188 | l(:actionview_datehelper_select_month_names).split(',')[month-1] |
|
189 | 189 | end |
|
190 | 190 | |
|
191 | 191 | def syntax_highlight(name, content) |
|
192 | 192 | type = CodeRay::FileType[name] |
|
193 | 193 | type ? CodeRay.scan(content, type).html : h(content) |
|
194 | 194 | end |
|
195 | 195 | |
|
196 | 196 | def to_path_param(path) |
|
197 | 197 | path.to_s.split(%r{[/\\]}).select {|p| !p.blank?} |
|
198 | 198 | end |
|
199 | 199 | |
|
200 | 200 | def pagination_links_full(paginator, count=nil, options={}) |
|
201 | 201 | page_param = options.delete(:page_param) || :page |
|
202 | 202 | url_param = params.dup |
|
203 | 203 | # don't reuse params if filters are present |
|
204 | 204 | url_param.clear if url_param.has_key?(:set_filter) |
|
205 | 205 | |
|
206 | 206 | html = '' |
|
207 | 207 | html << link_to_remote(('« ' + l(:label_previous)), |
|
208 | 208 | {:update => 'content', |
|
209 | 209 | :url => url_param.merge(page_param => paginator.current.previous), |
|
210 | 210 | :complete => 'window.scrollTo(0,0)'}, |
|
211 | 211 | {:href => url_for(:params => url_param.merge(page_param => paginator.current.previous))}) + ' ' if paginator.current.previous |
|
212 | 212 | |
|
213 | 213 | html << (pagination_links_each(paginator, options) do |n| |
|
214 | 214 | link_to_remote(n.to_s, |
|
215 | 215 | {:url => {:params => url_param.merge(page_param => n)}, |
|
216 | 216 | :update => 'content', |
|
217 | 217 | :complete => 'window.scrollTo(0,0)'}, |
|
218 | 218 | {:href => url_for(:params => url_param.merge(page_param => n))}) |
|
219 | 219 | end || '') |
|
220 | 220 | |
|
221 | 221 | html << ' ' + link_to_remote((l(:label_next) + ' »'), |
|
222 | 222 | {:update => 'content', |
|
223 | 223 | :url => url_param.merge(page_param => paginator.current.next), |
|
224 | 224 | :complete => 'window.scrollTo(0,0)'}, |
|
225 | 225 | {:href => url_for(:params => url_param.merge(page_param => paginator.current.next))}) if paginator.current.next |
|
226 | 226 | |
|
227 | 227 | unless count.nil? |
|
228 | 228 | html << [" (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})", per_page_links(paginator.items_per_page)].compact.join(' | ') |
|
229 | 229 | end |
|
230 | 230 | |
|
231 | 231 | html |
|
232 | 232 | end |
|
233 | 233 | |
|
234 | 234 | def per_page_links(selected=nil) |
|
235 | 235 | url_param = params.dup |
|
236 | 236 | url_param.clear if url_param.has_key?(:set_filter) |
|
237 | 237 | |
|
238 | 238 | links = Setting.per_page_options_array.collect do |n| |
|
239 | 239 | n == selected ? n : link_to_remote(n, {:update => "content", :url => params.dup.merge(:per_page => n)}, |
|
240 | 240 | {:href => url_for(url_param.merge(:per_page => n))}) |
|
241 | 241 | end |
|
242 | 242 | links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil |
|
243 | 243 | end |
|
244 | 244 | |
|
245 | 245 | def breadcrumb(*args) |
|
246 | 246 | elements = args.flatten |
|
247 | 247 | elements.any? ? content_tag('p', args.join(' » ') + ' » ', :class => 'breadcrumb') : nil |
|
248 | 248 | end |
|
249 | 249 | |
|
250 | 250 | def html_title(*args) |
|
251 | 251 | if args.empty? |
|
252 | 252 | title = [] |
|
253 | 253 | title << @project.name if @project |
|
254 | 254 | title += @html_title if @html_title |
|
255 | 255 | title << Setting.app_title |
|
256 | 256 | title.compact.join(' - ') |
|
257 | 257 | else |
|
258 | 258 | @html_title ||= [] |
|
259 | 259 | @html_title += args |
|
260 | 260 | end |
|
261 | 261 | end |
|
262 | 262 | |
|
263 | 263 | def accesskey(s) |
|
264 | 264 | Redmine::AccessKeys.key_for s |
|
265 | 265 | end |
|
266 | 266 | |
|
267 | 267 | # Formats text according to system settings. |
|
268 | 268 | # 2 ways to call this method: |
|
269 | 269 | # * with a String: textilizable(text, options) |
|
270 | 270 | # * with an object and one of its attribute: textilizable(issue, :description, options) |
|
271 | 271 | def textilizable(*args) |
|
272 | 272 | options = args.last.is_a?(Hash) ? args.pop : {} |
|
273 | 273 | case args.size |
|
274 | 274 | when 1 |
|
275 | 275 | obj = options[:object] |
|
276 | 276 | text = args.shift |
|
277 | 277 | when 2 |
|
278 | 278 | obj = args.shift |
|
279 | 279 | text = obj.send(args.shift).to_s |
|
280 | 280 | else |
|
281 | 281 | raise ArgumentError, 'invalid arguments to textilizable' |
|
282 | 282 | end |
|
283 | 283 | return '' if text.blank? |
|
284 | 284 | |
|
285 | 285 | only_path = options.delete(:only_path) == false ? false : true |
|
286 | 286 | |
|
287 | 287 | # when using an image link, try to use an attachment, if possible |
|
288 | 288 | attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil) |
|
289 | 289 | |
|
290 | 290 | if attachments |
|
291 | 291 | attachments = attachments.sort_by(&:created_on).reverse |
|
292 | 292 | text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(bmp|gif|jpg|jpeg|png))!/i) do |m| |
|
293 | 293 | style = $1 |
|
294 | filename = $6 | |
|
295 | rf = Regexp.new(Regexp.escape(filename), Regexp::IGNORECASE) | |
|
294 | filename = $6.downcase | |
|
296 | 295 | # search for the picture in attachments |
|
297 |
if found = attachments.detect { |att| att.filename = |
|
|
296 | if found = attachments.detect { |att| att.filename.downcase == filename } | |
|
298 | 297 | image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found |
|
299 | 298 | desc = found.description.to_s.gsub(/^([^\(\)]*).*$/, "\\1") |
|
300 | 299 | alt = desc.blank? ? nil : "(#{desc})" |
|
301 | 300 | "!#{style}#{image_url}#{alt}!" |
|
302 | 301 | else |
|
303 | "!#{style}#{filename}!" | |
|
302 | m | |
|
304 | 303 | end |
|
305 | 304 | end |
|
306 | 305 | end |
|
307 | 306 | |
|
308 | 307 | text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text) { |macro, args| exec_macro(macro, obj, args) } |
|
309 | 308 | |
|
310 | 309 | # different methods for formatting wiki links |
|
311 | 310 | case options[:wiki_links] |
|
312 | 311 | when :local |
|
313 | 312 | # used for local links to html files |
|
314 | 313 | format_wiki_link = Proc.new {|project, title, anchor| "#{title}.html" } |
|
315 | 314 | when :anchor |
|
316 | 315 | # used for single-file wiki export |
|
317 | 316 | format_wiki_link = Proc.new {|project, title, anchor| "##{title}" } |
|
318 | 317 | else |
|
319 | 318 | format_wiki_link = Proc.new {|project, title, anchor| url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => project, :page => title, :anchor => anchor) } |
|
320 | 319 | end |
|
321 | 320 | |
|
322 | 321 | project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil) |
|
323 | 322 | |
|
324 | 323 | # Wiki links |
|
325 | 324 | # |
|
326 | 325 | # Examples: |
|
327 | 326 | # [[mypage]] |
|
328 | 327 | # [[mypage|mytext]] |
|
329 | 328 | # wiki links can refer other project wikis, using project name or identifier: |
|
330 | 329 | # [[project:]] -> wiki starting page |
|
331 | 330 | # [[project:|mytext]] |
|
332 | 331 | # [[project:mypage]] |
|
333 | 332 | # [[project:mypage|mytext]] |
|
334 | 333 | text = text.gsub(/(!)?(\[\[([^\]\n\|]+)(\|([^\]\n\|]+))?\]\])/) do |m| |
|
335 | 334 | link_project = project |
|
336 | 335 | esc, all, page, title = $1, $2, $3, $5 |
|
337 | 336 | if esc.nil? |
|
338 | 337 | if page =~ /^([^\:]+)\:(.*)$/ |
|
339 | 338 | link_project = Project.find_by_name($1) || Project.find_by_identifier($1) |
|
340 | 339 | page = $2 |
|
341 | 340 | title ||= $1 if page.blank? |
|
342 | 341 | end |
|
343 | 342 | |
|
344 | 343 | if link_project && link_project.wiki |
|
345 | 344 | # extract anchor |
|
346 | 345 | anchor = nil |
|
347 | 346 | if page =~ /^(.+?)\#(.+)$/ |
|
348 | 347 | page, anchor = $1, $2 |
|
349 | 348 | end |
|
350 | 349 | # check if page exists |
|
351 | 350 | wiki_page = link_project.wiki.find_page(page) |
|
352 | 351 | link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page), anchor), |
|
353 | 352 | :class => ('wiki-page' + (wiki_page ? '' : ' new'))) |
|
354 | 353 | else |
|
355 | 354 | # project or wiki doesn't exist |
|
356 | 355 | title || page |
|
357 | 356 | end |
|
358 | 357 | else |
|
359 | 358 | all |
|
360 | 359 | end |
|
361 | 360 | end |
|
362 | 361 | |
|
363 | 362 | # Redmine links |
|
364 | 363 | # |
|
365 | 364 | # Examples: |
|
366 | 365 | # Issues: |
|
367 | 366 | # #52 -> Link to issue #52 |
|
368 | 367 | # Changesets: |
|
369 | 368 | # r52 -> Link to revision 52 |
|
370 | 369 | # commit:a85130f -> Link to scmid starting with a85130f |
|
371 | 370 | # Documents: |
|
372 | 371 | # document#17 -> Link to document with id 17 |
|
373 | 372 | # document:Greetings -> Link to the document with title "Greetings" |
|
374 | 373 | # document:"Some document" -> Link to the document with title "Some document" |
|
375 | 374 | # Versions: |
|
376 | 375 | # version#3 -> Link to version with id 3 |
|
377 | 376 | # version:1.0.0 -> Link to version named "1.0.0" |
|
378 | 377 | # version:"1.0 beta 2" -> Link to version named "1.0 beta 2" |
|
379 | 378 | # Attachments: |
|
380 | 379 | # attachment:file.zip -> Link to the attachment of the current object named file.zip |
|
381 | 380 | # Source files: |
|
382 | 381 | # source:some/file -> Link to the file located at /some/file in the project's repository |
|
383 | 382 | # source:some/file@52 -> Link to the file's revision 52 |
|
384 | 383 | # source:some/file#L120 -> Link to line 120 of the file |
|
385 | 384 | # source:some/file@52#L120 -> Link to line 120 of the file's revision 52 |
|
386 | 385 | # export:some/file -> Force the download of the file |
|
387 | 386 | # Forum messages: |
|
388 | 387 | # message#1218 -> Link to message with id 1218 |
|
389 | 388 | text = text.gsub(%r{([\s\(,\-\>]|^)(!)?(attachment|document|version|commit|source|export|message)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|\s|<|$)}) do |m| |
|
390 | 389 | leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8 |
|
391 | 390 | link = nil |
|
392 | 391 | if esc.nil? |
|
393 | 392 | if prefix.nil? && sep == 'r' |
|
394 | 393 | if project && (changeset = project.changesets.find_by_revision(oid)) |
|
395 | 394 | link = link_to("r#{oid}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => oid}, |
|
396 | 395 | :class => 'changeset', |
|
397 | 396 | :title => truncate_single_line(changeset.comments, 100)) |
|
398 | 397 | end |
|
399 | 398 | elsif sep == '#' |
|
400 | 399 | oid = oid.to_i |
|
401 | 400 | case prefix |
|
402 | 401 | when nil |
|
403 | 402 | if issue = Issue.find_by_id(oid, :include => [:project, :status], :conditions => Project.visible_by(User.current)) |
|
404 | 403 | link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid}, |
|
405 | 404 | :class => (issue.closed? ? 'issue closed' : 'issue'), |
|
406 | 405 | :title => "#{truncate(issue.subject, 100)} (#{issue.status.name})") |
|
407 | 406 | link = content_tag('del', link) if issue.closed? |
|
408 | 407 | end |
|
409 | 408 | when 'document' |
|
410 | 409 | if document = Document.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current)) |
|
411 | 410 | link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document}, |
|
412 | 411 | :class => 'document' |
|
413 | 412 | end |
|
414 | 413 | when 'version' |
|
415 | 414 | if version = Version.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current)) |
|
416 | 415 | link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version}, |
|
417 | 416 | :class => 'version' |
|
418 | 417 | end |
|
419 | 418 | when 'message' |
|
420 | 419 | if message = Message.find_by_id(oid, :include => [:parent, {:board => :project}], :conditions => Project.visible_by(User.current)) |
|
421 | 420 | link = link_to h(truncate(message.subject, 60)), {:only_path => only_path, |
|
422 | 421 | :controller => 'messages', |
|
423 | 422 | :action => 'show', |
|
424 | 423 | :board_id => message.board, |
|
425 | 424 | :id => message.root, |
|
426 | 425 | :anchor => (message.parent ? "message-#{message.id}" : nil)}, |
|
427 | 426 | :class => 'message' |
|
428 | 427 | end |
|
429 | 428 | end |
|
430 | 429 | elsif sep == ':' |
|
431 | 430 | # removes the double quotes if any |
|
432 | 431 | name = oid.gsub(%r{^"(.*)"$}, "\\1") |
|
433 | 432 | case prefix |
|
434 | 433 | when 'document' |
|
435 | 434 | if project && document = project.documents.find_by_title(name) |
|
436 | 435 | link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document}, |
|
437 | 436 | :class => 'document' |
|
438 | 437 | end |
|
439 | 438 | when 'version' |
|
440 | 439 | if project && version = project.versions.find_by_name(name) |
|
441 | 440 | link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version}, |
|
442 | 441 | :class => 'version' |
|
443 | 442 | end |
|
444 | 443 | when 'commit' |
|
445 | 444 | if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"])) |
|
446 | 445 | link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision}, |
|
447 | 446 | :class => 'changeset', |
|
448 | 447 | :title => truncate_single_line(changeset.comments, 100) |
|
449 | 448 | end |
|
450 | 449 | when 'source', 'export' |
|
451 | 450 | if project && project.repository |
|
452 | 451 | name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$} |
|
453 | 452 | path, rev, anchor = $1, $3, $5 |
|
454 | 453 | link = link_to h("#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project, |
|
455 | 454 | :path => to_path_param(path), |
|
456 | 455 | :rev => rev, |
|
457 | 456 | :anchor => anchor, |
|
458 | 457 | :format => (prefix == 'export' ? 'raw' : nil)}, |
|
459 | 458 | :class => (prefix == 'export' ? 'source download' : 'source') |
|
460 | 459 | end |
|
461 | 460 | when 'attachment' |
|
462 | 461 | if attachments && attachment = attachments.detect {|a| a.filename == name } |
|
463 | 462 | link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment}, |
|
464 | 463 | :class => 'attachment' |
|
465 | 464 | end |
|
466 | 465 | end |
|
467 | 466 | end |
|
468 | 467 | end |
|
469 | 468 | leading + (link || "#{prefix}#{sep}#{oid}") |
|
470 | 469 | end |
|
471 | 470 | |
|
472 | 471 | text |
|
473 | 472 | end |
|
474 | 473 | |
|
475 | 474 | # Same as Rails' simple_format helper without using paragraphs |
|
476 | 475 | def simple_format_without_paragraph(text) |
|
477 | 476 | text.to_s. |
|
478 | 477 | gsub(/\r\n?/, "\n"). # \r\n and \r -> \n |
|
479 | 478 | gsub(/\n\n+/, "<br /><br />"). # 2+ newline -> 2 br |
|
480 | 479 | gsub(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br |
|
481 | 480 | end |
|
482 | 481 | |
|
483 | 482 | def error_messages_for(object_name, options = {}) |
|
484 | 483 | options = options.symbolize_keys |
|
485 | 484 | object = instance_variable_get("@#{object_name}") |
|
486 | 485 | if object && !object.errors.empty? |
|
487 | 486 | # build full_messages here with controller current language |
|
488 | 487 | full_messages = [] |
|
489 | 488 | object.errors.each do |attr, msg| |
|
490 | 489 | next if msg.nil? |
|
491 | 490 | msg = msg.first if msg.is_a? Array |
|
492 | 491 | if attr == "base" |
|
493 | 492 | full_messages << l(msg) |
|
494 | 493 | else |
|
495 | 494 | full_messages << "« " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " » " + l(msg) unless attr == "custom_values" |
|
496 | 495 | end |
|
497 | 496 | end |
|
498 | 497 | # retrieve custom values error messages |
|
499 | 498 | if object.errors[:custom_values] |
|
500 | 499 | object.custom_values.each do |v| |
|
501 | 500 | v.errors.each do |attr, msg| |
|
502 | 501 | next if msg.nil? |
|
503 | 502 | msg = msg.first if msg.is_a? Array |
|
504 | 503 | full_messages << "« " + v.custom_field.name + " » " + l(msg) |
|
505 | 504 | end |
|
506 | 505 | end |
|
507 | 506 | end |
|
508 | 507 | content_tag("div", |
|
509 | 508 | content_tag( |
|
510 | 509 | options[:header_tag] || "span", lwr(:gui_validation_error, full_messages.length) + ":" |
|
511 | 510 | ) + |
|
512 | 511 | content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }), |
|
513 | 512 | "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation" |
|
514 | 513 | ) |
|
515 | 514 | else |
|
516 | 515 | "" |
|
517 | 516 | end |
|
518 | 517 | end |
|
519 | 518 | |
|
520 | 519 | def lang_options_for_select(blank=true) |
|
521 | 520 | (blank ? [["(auto)", ""]] : []) + |
|
522 | 521 | GLoc.valid_languages.collect{|lang| [ ll(lang.to_s, :general_lang_name), lang.to_s]}.sort{|x,y| x.last <=> y.last } |
|
523 | 522 | end |
|
524 | 523 | |
|
525 | 524 | def label_tag_for(name, option_tags = nil, options = {}) |
|
526 | 525 | label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "") |
|
527 | 526 | content_tag("label", label_text) |
|
528 | 527 | end |
|
529 | 528 | |
|
530 | 529 | def labelled_tabular_form_for(name, object, options, &proc) |
|
531 | 530 | options[:html] ||= {} |
|
532 | 531 | options[:html][:class] = 'tabular' unless options[:html].has_key?(:class) |
|
533 | 532 | form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc) |
|
534 | 533 | end |
|
535 | 534 | |
|
536 | 535 | def back_url_hidden_field_tag |
|
537 | 536 | back_url = params[:back_url] || request.env['HTTP_REFERER'] |
|
538 | 537 | back_url = CGI.unescape(back_url.to_s) |
|
539 | 538 | hidden_field_tag('back_url', CGI.escape(back_url)) unless back_url.blank? |
|
540 | 539 | end |
|
541 | 540 | |
|
542 | 541 | def check_all_links(form_name) |
|
543 | 542 | link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") + |
|
544 | 543 | " | " + |
|
545 | 544 | link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)") |
|
546 | 545 | end |
|
547 | 546 | |
|
548 | 547 | def progress_bar(pcts, options={}) |
|
549 | 548 | pcts = [pcts, pcts] unless pcts.is_a?(Array) |
|
550 | 549 | pcts[1] = pcts[1] - pcts[0] |
|
551 | 550 | pcts << (100 - pcts[1] - pcts[0]) |
|
552 | 551 | width = options[:width] || '100px;' |
|
553 | 552 | legend = options[:legend] || '' |
|
554 | 553 | content_tag('table', |
|
555 | 554 | content_tag('tr', |
|
556 | 555 | (pcts[0] > 0 ? content_tag('td', '', :style => "width: #{pcts[0].floor}%;", :class => 'closed') : '') + |
|
557 | 556 | (pcts[1] > 0 ? content_tag('td', '', :style => "width: #{pcts[1].floor}%;", :class => 'done') : '') + |
|
558 | 557 | (pcts[2] > 0 ? content_tag('td', '', :style => "width: #{pcts[2].floor}%;", :class => 'todo') : '') |
|
559 | 558 | ), :class => 'progress', :style => "width: #{width};") + |
|
560 | 559 | content_tag('p', legend, :class => 'pourcent') |
|
561 | 560 | end |
|
562 | 561 | |
|
563 | 562 | def context_menu_link(name, url, options={}) |
|
564 | 563 | options[:class] ||= '' |
|
565 | 564 | if options.delete(:selected) |
|
566 | 565 | options[:class] << ' icon-checked disabled' |
|
567 | 566 | options[:disabled] = true |
|
568 | 567 | end |
|
569 | 568 | if options.delete(:disabled) |
|
570 | 569 | options.delete(:method) |
|
571 | 570 | options.delete(:confirm) |
|
572 | 571 | options.delete(:onclick) |
|
573 | 572 | options[:class] << ' disabled' |
|
574 | 573 | url = '#' |
|
575 | 574 | end |
|
576 | 575 | link_to name, url, options |
|
577 | 576 | end |
|
578 | 577 | |
|
579 | 578 | def calendar_for(field_id) |
|
580 | 579 | include_calendar_headers_tags |
|
581 | 580 | image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) + |
|
582 | 581 | javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });") |
|
583 | 582 | end |
|
584 | 583 | |
|
585 | 584 | def include_calendar_headers_tags |
|
586 | 585 | unless @calendar_headers_tags_included |
|
587 | 586 | @calendar_headers_tags_included = true |
|
588 | 587 | content_for :header_tags do |
|
589 | 588 | javascript_include_tag('calendar/calendar') + |
|
590 | 589 | javascript_include_tag("calendar/lang/calendar-#{current_language}.js") + |
|
591 | 590 | javascript_include_tag('calendar/calendar-setup') + |
|
592 | 591 | stylesheet_link_tag('calendar') |
|
593 | 592 | end |
|
594 | 593 | end |
|
595 | 594 | end |
|
596 | 595 | |
|
597 | 596 | def content_for(name, content = nil, &block) |
|
598 | 597 | @has_content ||= {} |
|
599 | 598 | @has_content[name] = true |
|
600 | 599 | super(name, content, &block) |
|
601 | 600 | end |
|
602 | 601 | |
|
603 | 602 | def has_content?(name) |
|
604 | 603 | (@has_content && @has_content[name]) || false |
|
605 | 604 | end |
|
606 | 605 | |
|
607 | 606 | # Returns the avatar image tag for the given +user+ if avatars are enabled |
|
608 | 607 | # +user+ can be a User or a string that will be scanned for an email address (eg. 'joe <joe@foo.bar>') |
|
609 | 608 | def avatar(user, options = { }) |
|
610 | 609 | if Setting.gravatar_enabled? |
|
611 | 610 | email = nil |
|
612 | 611 | if user.respond_to?(:mail) |
|
613 | 612 | email = user.mail |
|
614 | 613 | elsif user.to_s =~ %r{<(.+?)>} |
|
615 | 614 | email = $1 |
|
616 | 615 | end |
|
617 | 616 | return gravatar(email.to_s.downcase, options) unless email.blank? rescue nil |
|
618 | 617 | end |
|
619 | 618 | end |
|
620 | 619 | |
|
621 | 620 | private |
|
622 | 621 | |
|
623 | 622 | def wiki_helper |
|
624 | 623 | helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting) |
|
625 | 624 | extend helper |
|
626 | 625 | return self |
|
627 | 626 | end |
|
628 | 627 | end |
@@ -1,89 +1,89 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class Message < ActiveRecord::Base |
|
19 | 19 | belongs_to :board |
|
20 | 20 | belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' |
|
21 | 21 | acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC" |
|
22 | 22 | acts_as_attachable |
|
23 | 23 | belongs_to :last_reply, :class_name => 'Message', :foreign_key => 'last_reply_id' |
|
24 | 24 | |
|
25 | 25 | acts_as_searchable :columns => ['subject', 'content'], |
|
26 |
:include => {:board |
|
|
26 | :include => {:board => :project}, | |
|
27 | 27 | :project_key => 'project_id', |
|
28 | 28 | :date_column => "#{table_name}.created_on" |
|
29 | 29 | acts_as_event :title => Proc.new {|o| "#{o.board.name}: #{o.subject}"}, |
|
30 | 30 | :description => :content, |
|
31 | 31 | :type => Proc.new {|o| o.parent_id.nil? ? 'message' : 'reply'}, |
|
32 | 32 | :url => Proc.new {|o| {:controller => 'messages', :action => 'show', :board_id => o.board_id}.merge(o.parent_id.nil? ? {:id => o.id} : |
|
33 | 33 | {:id => o.parent_id, :anchor => "message-#{o.id}"})} |
|
34 | 34 | |
|
35 | 35 | acts_as_activity_provider :find_options => {:include => [{:board => :project}, :author]}, |
|
36 | 36 | :author_key => :author_id |
|
37 | 37 | acts_as_watchable |
|
38 | 38 | |
|
39 | 39 | attr_protected :locked, :sticky |
|
40 | 40 | validates_presence_of :subject, :content |
|
41 | 41 | validates_length_of :subject, :maximum => 255 |
|
42 | 42 | |
|
43 | 43 | after_create :add_author_as_watcher |
|
44 | 44 | |
|
45 | 45 | def validate_on_create |
|
46 | 46 | # Can not reply to a locked topic |
|
47 | 47 | errors.add_to_base 'Topic is locked' if root.locked? && self != root |
|
48 | 48 | end |
|
49 | 49 | |
|
50 | 50 | def after_create |
|
51 | 51 | board.update_attribute(:last_message_id, self.id) |
|
52 | 52 | board.increment! :messages_count |
|
53 | 53 | if parent |
|
54 | 54 | parent.reload.update_attribute(:last_reply_id, self.id) |
|
55 | 55 | else |
|
56 | 56 | board.increment! :topics_count |
|
57 | 57 | end |
|
58 | 58 | end |
|
59 | 59 | |
|
60 | 60 | def after_destroy |
|
61 | 61 | # The following line is required so that the previous counter |
|
62 | 62 | # updates (due to children removal) are not overwritten |
|
63 | 63 | board.reload |
|
64 | 64 | board.decrement! :messages_count |
|
65 | 65 | board.decrement! :topics_count unless parent |
|
66 | 66 | end |
|
67 | 67 | |
|
68 | 68 | def sticky? |
|
69 | 69 | sticky == 1 |
|
70 | 70 | end |
|
71 | 71 | |
|
72 | 72 | def project |
|
73 | 73 | board.project |
|
74 | 74 | end |
|
75 | 75 | |
|
76 | 76 | def editable_by?(usr) |
|
77 | 77 | usr && usr.logged? && (usr.allowed_to?(:edit_messages, project) || (self.author == usr && usr.allowed_to?(:edit_own_messages, project))) |
|
78 | 78 | end |
|
79 | 79 | |
|
80 | 80 | def destroyable_by?(usr) |
|
81 | 81 | usr && usr.logged? && (usr.allowed_to?(:delete_messages, project) || (self.author == usr && usr.allowed_to?(:delete_own_messages, project))) |
|
82 | 82 | end |
|
83 | 83 | |
|
84 | 84 | private |
|
85 | 85 | |
|
86 | 86 | def add_author_as_watcher |
|
87 | 87 | Watcher.create(:watchable => self.root, :user => author) |
|
88 | 88 | end |
|
89 | 89 | end |
@@ -1,147 +1,147 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class Role < ActiveRecord::Base |
|
19 | 19 | # Built-in roles |
|
20 | 20 | BUILTIN_NON_MEMBER = 1 |
|
21 | 21 | BUILTIN_ANONYMOUS = 2 |
|
22 | 22 | |
|
23 | 23 | named_scope :builtin, lambda { |*args| |
|
24 | 24 | compare = 'not' if args.first == true |
|
25 | 25 | { :conditions => "#{compare} builtin = 0" } |
|
26 | 26 | } |
|
27 | 27 | |
|
28 | 28 | before_destroy :check_deletable |
|
29 | 29 | has_many :workflows, :dependent => :delete_all do |
|
30 | 30 | def copy(role) |
|
31 | 31 | raise "Can not copy workflow from a #{role.class}" unless role.is_a?(Role) |
|
32 | 32 | raise "Can not copy workflow from/to an unsaved role" if proxy_owner.new_record? || role.new_record? |
|
33 | 33 | clear |
|
34 |
connection.insert "INSERT INTO |
|
|
34 | connection.insert "INSERT INTO #{Workflow.table_name} (tracker_id, old_status_id, new_status_id, role_id)" + | |
|
35 | 35 | " SELECT tracker_id, old_status_id, new_status_id, #{proxy_owner.id}" + |
|
36 |
" FROM |
|
|
36 | " FROM #{Workflow.table_name}" + | |
|
37 | 37 | " WHERE role_id = #{role.id}" |
|
38 | 38 | end |
|
39 | 39 | end |
|
40 | 40 | |
|
41 | 41 | has_many :members |
|
42 | 42 | acts_as_list |
|
43 | 43 | |
|
44 | 44 | serialize :permissions, Array |
|
45 | 45 | attr_protected :builtin |
|
46 | 46 | |
|
47 | 47 | validates_presence_of :name |
|
48 | 48 | validates_uniqueness_of :name |
|
49 | 49 | validates_length_of :name, :maximum => 30 |
|
50 | 50 | validates_format_of :name, :with => /^[\w\s\'\-]*$/i |
|
51 | 51 | |
|
52 | 52 | def permissions |
|
53 | 53 | read_attribute(:permissions) || [] |
|
54 | 54 | end |
|
55 | 55 | |
|
56 | 56 | def permissions=(perms) |
|
57 | 57 | perms = perms.collect {|p| p.to_sym unless p.blank? }.compact.uniq if perms |
|
58 | 58 | write_attribute(:permissions, perms) |
|
59 | 59 | end |
|
60 | 60 | |
|
61 | 61 | def add_permission!(*perms) |
|
62 | 62 | self.permissions = [] unless permissions.is_a?(Array) |
|
63 | 63 | |
|
64 | 64 | permissions_will_change! |
|
65 | 65 | perms.each do |p| |
|
66 | 66 | p = p.to_sym |
|
67 | 67 | permissions << p unless permissions.include?(p) |
|
68 | 68 | end |
|
69 | 69 | save! |
|
70 | 70 | end |
|
71 | 71 | |
|
72 | 72 | def remove_permission!(*perms) |
|
73 | 73 | return unless permissions.is_a?(Array) |
|
74 | 74 | permissions_will_change! |
|
75 | 75 | perms.each { |p| permissions.delete(p.to_sym) } |
|
76 | 76 | save! |
|
77 | 77 | end |
|
78 | 78 | |
|
79 | 79 | # Returns true if the role has the given permission |
|
80 | 80 | def has_permission?(perm) |
|
81 | 81 | !permissions.nil? && permissions.include?(perm.to_sym) |
|
82 | 82 | end |
|
83 | 83 | |
|
84 | 84 | def <=>(role) |
|
85 | 85 | position <=> role.position |
|
86 | 86 | end |
|
87 | 87 | |
|
88 | 88 | # Return true if the role is a builtin role |
|
89 | 89 | def builtin? |
|
90 | 90 | self.builtin != 0 |
|
91 | 91 | end |
|
92 | 92 | |
|
93 | 93 | # Return true if the role is a project member role |
|
94 | 94 | def member? |
|
95 | 95 | !self.builtin? |
|
96 | 96 | end |
|
97 | 97 | |
|
98 | 98 | # Return true if role is allowed to do the specified action |
|
99 | 99 | # action can be: |
|
100 | 100 | # * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit') |
|
101 | 101 | # * a permission Symbol (eg. :edit_project) |
|
102 | 102 | def allowed_to?(action) |
|
103 | 103 | if action.is_a? Hash |
|
104 | 104 | allowed_actions.include? "#{action[:controller]}/#{action[:action]}" |
|
105 | 105 | else |
|
106 | 106 | allowed_permissions.include? action |
|
107 | 107 | end |
|
108 | 108 | end |
|
109 | 109 | |
|
110 | 110 | # Return all the permissions that can be given to the role |
|
111 | 111 | def setable_permissions |
|
112 | 112 | setable_permissions = Redmine::AccessControl.permissions - Redmine::AccessControl.public_permissions |
|
113 | 113 | setable_permissions -= Redmine::AccessControl.members_only_permissions if self.builtin == BUILTIN_NON_MEMBER |
|
114 | 114 | setable_permissions -= Redmine::AccessControl.loggedin_only_permissions if self.builtin == BUILTIN_ANONYMOUS |
|
115 | 115 | setable_permissions |
|
116 | 116 | end |
|
117 | 117 | |
|
118 | 118 | # Find all the roles that can be given to a project member |
|
119 | 119 | def self.find_all_givable |
|
120 | 120 | find(:all, :conditions => {:builtin => 0}, :order => 'position') |
|
121 | 121 | end |
|
122 | 122 | |
|
123 | 123 | # Return the builtin 'non member' role |
|
124 | 124 | def self.non_member |
|
125 | 125 | find(:first, :conditions => {:builtin => BUILTIN_NON_MEMBER}) || raise('Missing non-member builtin role.') |
|
126 | 126 | end |
|
127 | 127 | |
|
128 | 128 | # Return the builtin 'anonymous' role |
|
129 | 129 | def self.anonymous |
|
130 | 130 | find(:first, :conditions => {:builtin => BUILTIN_ANONYMOUS}) || raise('Missing anonymous builtin role.') |
|
131 | 131 | end |
|
132 | 132 | |
|
133 | 133 | |
|
134 | 134 | private |
|
135 | 135 | def allowed_permissions |
|
136 | 136 | @allowed_permissions ||= permissions + Redmine::AccessControl.public_permissions.collect {|p| p.name} |
|
137 | 137 | end |
|
138 | 138 | |
|
139 | 139 | def allowed_actions |
|
140 | 140 | @actions_allowed ||= allowed_permissions.inject([]) { |actions, permission| actions += Redmine::AccessControl.allowed_actions(permission) }.flatten |
|
141 | 141 | end |
|
142 | 142 | |
|
143 | 143 | def check_deletable |
|
144 | 144 | raise "Can't delete role" if members.any? |
|
145 | 145 | raise "Can't delete builtin role" if builtin? |
|
146 | 146 | end |
|
147 | 147 | end |
@@ -1,56 +1,56 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class Tracker < ActiveRecord::Base |
|
19 | 19 | before_destroy :check_integrity |
|
20 | 20 | has_many :issues |
|
21 | 21 | has_many :workflows, :dependent => :delete_all do |
|
22 | 22 | def copy(tracker) |
|
23 | 23 | raise "Can not copy workflow from a #{tracker.class}" unless tracker.is_a?(Tracker) |
|
24 | 24 | raise "Can not copy workflow from/to an unsaved tracker" if proxy_owner.new_record? || tracker.new_record? |
|
25 | 25 | clear |
|
26 |
connection.insert "INSERT INTO |
|
|
26 | connection.insert "INSERT INTO #{Workflow.table_name} (tracker_id, old_status_id, new_status_id, role_id)" + | |
|
27 | 27 | " SELECT #{proxy_owner.id}, old_status_id, new_status_id, role_id" + |
|
28 |
" FROM |
|
|
28 | " FROM #{Workflow.table_name}" + | |
|
29 | 29 | " WHERE tracker_id = #{tracker.id}" |
|
30 | 30 | end |
|
31 | 31 | end |
|
32 | 32 | |
|
33 | 33 | has_and_belongs_to_many :projects |
|
34 | 34 | has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_trackers#{table_name_suffix}", :association_foreign_key => 'custom_field_id' |
|
35 | 35 | acts_as_list |
|
36 | 36 | |
|
37 | 37 | validates_presence_of :name |
|
38 | 38 | validates_uniqueness_of :name |
|
39 | 39 | validates_length_of :name, :maximum => 30 |
|
40 | 40 | validates_format_of :name, :with => /^[\w\s\'\-]*$/i |
|
41 | 41 | |
|
42 | 42 | def to_s; name end |
|
43 | 43 | |
|
44 | 44 | def <=>(tracker) |
|
45 | 45 | name <=> tracker.name |
|
46 | 46 | end |
|
47 | 47 | |
|
48 | 48 | def self.all |
|
49 | 49 | find(:all, :order => 'position') |
|
50 | 50 | end |
|
51 | 51 | |
|
52 | 52 | private |
|
53 | 53 | def check_integrity |
|
54 | 54 | raise "Can't delete tracker" if Issue.find(:first, :conditions => ["tracker_id=?", self.id]) |
|
55 | 55 | end |
|
56 | 56 | end |
@@ -1,61 +1,63 | |||
|
1 | 1 | <% if @issue.new_record? %> |
|
2 | 2 | <p><%= f.select :tracker_id, @project.trackers.collect {|t| [t.name, t.id]}, :required => true %></p> |
|
3 | 3 | <%= observe_field :issue_tracker_id, :url => { :action => :new }, |
|
4 | 4 | :update => :content, |
|
5 | 5 | :with => "Form.serialize('issue-form')" %> |
|
6 | 6 | <hr /> |
|
7 | 7 | <% end %> |
|
8 | 8 | |
|
9 | 9 | <div id="issue_descr_fields" <%= 'style="display:none"' unless @issue.new_record? || @issue.errors.any? %>> |
|
10 | 10 | <p><%= f.text_field :subject, :size => 80, :required => true %></p> |
|
11 | 11 | <p><%= f.text_area :description, |
|
12 | 12 | :cols => 60, |
|
13 | 13 | :rows => (@issue.description.blank? ? 10 : [[10, @issue.description.length / 50].max, 100].min), |
|
14 | 14 | :accesskey => accesskey(:edit), |
|
15 | 15 | :class => 'wiki-edit' %></p> |
|
16 | 16 | </div> |
|
17 | 17 | |
|
18 | 18 | <div class="splitcontentleft"> |
|
19 | 19 | <% if @issue.new_record? || @allowed_statuses.any? %> |
|
20 | 20 | <p><%= f.select :status_id, (@allowed_statuses.collect {|p| [p.name, p.id]}), :required => true %></p> |
|
21 | 21 | <% else %> |
|
22 | 22 | <p><label><%= l(:field_status) %></label> <%= @issue.status.name %></p> |
|
23 | 23 | <% end %> |
|
24 | 24 | |
|
25 | 25 | <p><%= f.select :priority_id, (@priorities.collect {|p| [p.name, p.id]}), :required => true %></p> |
|
26 | 26 | <p><%= f.select :assigned_to_id, (@issue.assignable_users.collect {|m| [m.name, m.id]}), :include_blank => true %></p> |
|
27 | <% unless @project.issue_categories.empty? %> | |
|
27 | 28 | <p><%= f.select :category_id, (@project.issue_categories.collect {|c| [c.name, c.id]}), :include_blank => true %> |
|
28 | 29 | <%= prompt_to_remote(l(:label_issue_category_new), |
|
29 | 30 | l(:label_issue_category_new), 'category[name]', |
|
30 | 31 | {:controller => 'projects', :action => 'add_issue_category', :id => @project}, |
|
31 | 32 | :class => 'small', :tabindex => 199) if authorize_for('projects', 'add_issue_category') %></p> |
|
33 | <% end %> | |
|
32 | 34 | <%= content_tag('p', f.select(:fixed_version_id, |
|
33 | 35 | (@project.versions.sort.collect {|v| [v.name, v.id]}), |
|
34 | 36 | { :include_blank => true })) unless @project.versions.empty? %> |
|
35 | 37 | </div> |
|
36 | 38 | |
|
37 | 39 | <div class="splitcontentright"> |
|
38 | 40 | <p><%= f.text_field :start_date, :size => 10 %><%= calendar_for('issue_start_date') %></p> |
|
39 | 41 | <p><%= f.text_field :due_date, :size => 10 %><%= calendar_for('issue_due_date') %></p> |
|
40 | 42 | <p><%= f.text_field :estimated_hours, :size => 3 %> <%= l(:field_hours) %></p> |
|
41 | 43 | <p><%= f.select :done_ratio, ((0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %></p> |
|
42 | 44 | </div> |
|
43 | 45 | |
|
44 | 46 | <div style="clear:both;"> </div> |
|
45 | 47 | <%= render :partial => 'form_custom_fields' %> |
|
46 | 48 | |
|
47 | 49 | <% if @issue.new_record? %> |
|
48 | 50 | <p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p> |
|
49 | 51 | <% end %> |
|
50 | 52 | |
|
51 | 53 | <% if @issue.new_record? && User.current.allowed_to?(:add_issue_watchers, @project) -%> |
|
52 | 54 | <p><label><%= l(:label_issue_watchers) %></label> |
|
53 | 55 | <% @issue.project.users.sort.each do |user| -%> |
|
54 | 56 | <label class="floating"><%= check_box_tag 'issue[watcher_user_ids][]', user.id, @issue.watcher_user_ids.include?(user.id) %> <%=h user %></label> |
|
55 | 57 | <% end -%> |
|
56 | 58 | </p> |
|
57 | 59 | <% end %> |
|
58 | 60 | |
|
59 | 61 | <%= call_hook(:view_issues_form_details_bottom, { :issue => @issue, :form => f }) %> |
|
60 | 62 | |
|
61 | 63 | <%= wikitoolbar_for 'issue_description' %> |
@@ -1,50 +1,51 | |||
|
1 | 1 | <h2><%= l(:label_bulk_edit_selected_issues) %></h2> |
|
2 | 2 | |
|
3 | 3 | <ul><%= @issues.collect {|i| content_tag('li', link_to(h("#{i.tracker} ##{i.id}"), { :action => 'show', :id => i }) + h(": #{i.subject}")) }.join("\n") %></ul> |
|
4 | 4 | |
|
5 | 5 | <% form_tag() do %> |
|
6 | 6 | <%= @issues.collect {|i| hidden_field_tag('ids[]', i.id)}.join %> |
|
7 | 7 | <div class="box"> |
|
8 | 8 | <fieldset> |
|
9 | 9 | <legend><%= l(:label_change_properties) %></legend> |
|
10 | 10 | <p> |
|
11 | 11 | <% if @available_statuses.any? %> |
|
12 | 12 | <label><%= l(:field_status) %>: |
|
13 | 13 | <%= select_tag('status_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@available_statuses, :id, :name)) %></label> |
|
14 | 14 | <% end %> |
|
15 | 15 | <label><%= l(:field_priority) %>: |
|
16 | 16 | <%= select_tag('priority_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(Enumeration.get_values('IPRI'), :id, :name)) %></label> |
|
17 | 17 | <label><%= l(:field_category) %>: |
|
18 | 18 | <%= select_tag('category_id', content_tag('option', l(:label_no_change_option), :value => '') + |
|
19 | 19 | content_tag('option', l(:label_none), :value => 'none') + |
|
20 | 20 | options_from_collection_for_select(@project.issue_categories, :id, :name)) %></label> |
|
21 | 21 | </p> |
|
22 | 22 | <p> |
|
23 | 23 | <label><%= l(:field_assigned_to) %>: |
|
24 | 24 | <%= select_tag('assigned_to_id', content_tag('option', l(:label_no_change_option), :value => '') + |
|
25 | 25 | content_tag('option', l(:label_nobody), :value => 'none') + |
|
26 | 26 | options_from_collection_for_select(@project.assignable_users, :id, :name)) %></label> |
|
27 | 27 | <label><%= l(:field_fixed_version) %>: |
|
28 | 28 | <%= select_tag('fixed_version_id', content_tag('option', l(:label_no_change_option), :value => '') + |
|
29 | 29 | content_tag('option', l(:label_none), :value => 'none') + |
|
30 | 30 | options_from_collection_for_select(@project.versions, :id, :name)) %></label> |
|
31 | 31 | </p> |
|
32 | 32 | |
|
33 | 33 | <p> |
|
34 | 34 | <label><%= l(:field_start_date) %>: |
|
35 | 35 | <%= text_field_tag 'start_date', '', :size => 10 %><%= calendar_for('start_date') %></label> |
|
36 | 36 | <label><%= l(:field_due_date) %>: |
|
37 | 37 | <%= text_field_tag 'due_date', '', :size => 10 %><%= calendar_for('due_date') %></label> |
|
38 | 38 | <label><%= l(:field_done_ratio) %>: |
|
39 | 39 | <%= select_tag 'done_ratio', options_for_select([[l(:label_no_change_option), '']] + (0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %></label> |
|
40 | 40 | </p> |
|
41 | 41 | <%= call_hook(:view_issues_bulk_edit_details_bottom, { :issues => @issues }) %> |
|
42 | 42 | </fieldset> |
|
43 | 43 | |
|
44 | 44 | <fieldset><legend><%= l(:field_notes) %></legend> |
|
45 | 45 | <%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %> |
|
46 | 46 | <%= wikitoolbar_for 'notes' %> |
|
47 | </fieldset> | |
|
47 | 48 | </div> |
|
48 | 49 | |
|
49 | 50 | <p><%= submit_tag l(:button_submit) %> |
|
50 | 51 | <% end %> |
@@ -1,52 +1,52 | |||
|
1 | 1 | <h3><%=l(:label_spent_time)%> (<%= l(:label_last_n_days, 7) %>)</h3> |
|
2 | 2 | <% |
|
3 | 3 | entries = TimeEntry.find(:all, |
|
4 | 4 | :conditions => ["#{TimeEntry.table_name}.user_id = ? AND #{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", @user.id, Date.today - 6, Date.today], |
|
5 | 5 | :include => [:activity, :project, {:issue => [:tracker, :status]}], |
|
6 | 6 | :order => "#{TimeEntry.table_name}.spent_on DESC, #{Project.table_name}.name ASC, #{Tracker.table_name}.position ASC, #{Issue.table_name}.id ASC") |
|
7 | 7 | entries_by_day = entries.group_by(&:spent_on) |
|
8 | 8 | %> |
|
9 | 9 | |
|
10 | 10 | <div class="total-hours"> |
|
11 | 11 | <p><%= l(:label_total) %>: <%= html_hours("%.2f" % entries.sum(&:hours).to_f) %></p> |
|
12 | 12 | </div> |
|
13 | 13 | |
|
14 | 14 | <% if entries.any? %> |
|
15 | 15 | <table class="list time-entries"> |
|
16 | 16 | <thead> |
|
17 | 17 | <th><%= l(:label_activity) %></th> |
|
18 | 18 | <th><%= l(:label_project) %></th> |
|
19 | 19 | <th><%= l(:field_comments) %></th> |
|
20 | 20 | <th><%= l(:field_hours) %></th> |
|
21 | 21 | <th></th> |
|
22 | 22 | </thead> |
|
23 | 23 | <tbody> |
|
24 | 24 | <% entries_by_day.keys.sort.reverse.each do |day| %> |
|
25 | 25 | <tr class="odd"> |
|
26 | 26 | <td><strong><%= day == Date.today ? l(:label_today).titleize : format_date(day) %></strong></td> |
|
27 | 27 | <td colspan="2"></td> |
|
28 | 28 | <td class="hours"><em><%= html_hours("%.2f" % entries_by_day[day].sum(&:hours).to_f) %></em></td> |
|
29 | 29 | <td></td> |
|
30 | 30 | </tr> |
|
31 | 31 | <% entries_by_day[day].each do |entry| -%> |
|
32 | 32 | <tr class="time-entry" style="border-bottom: 1px solid #f5f5f5;"> |
|
33 | 33 | <td class="activity"><%=h entry.activity %></td> |
|
34 | 34 | <td class="subject"><%=h entry.project %> <%= ' - ' + link_to_issue(entry.issue, :title => h("#{entry.issue.subject} (#{entry.issue.status})")) if entry.issue %></td> |
|
35 | 35 | <td class="comments"><%=h entry.comments %></td> |
|
36 | 36 | <td class="hours"><%= html_hours("%.2f" % entry.hours) %></td> |
|
37 | 37 | <td align="center"> |
|
38 | 38 | <% if entry.editable_by?(@user) -%> |
|
39 | 39 | <%= link_to image_tag('edit.png'), {:controller => 'timelog', :action => 'edit', :id => entry}, |
|
40 | 40 | :title => l(:button_edit) %> |
|
41 | 41 | <%= link_to image_tag('delete.png'), {:controller => 'timelog', :action => 'destroy', :id => entry}, |
|
42 | 42 | :confirm => l(:text_are_you_sure), |
|
43 | 43 | :method => :post, |
|
44 | 44 | :title => l(:button_delete) %> |
|
45 | 45 | <% end -%> |
|
46 | 46 | </td> |
|
47 | 47 | </tr> |
|
48 | 48 | <% end -%> |
|
49 | 49 | <% end -%> |
|
50 |
</tb |
|
|
50 | </tbody> | |
|
51 | 51 | </table> |
|
52 | 52 | <% end %> |
@@ -1,29 +1,28 | |||
|
1 | 1 | <% if @project.versions.any? %> |
|
2 | 2 | <table class="list"> |
|
3 | 3 | <thead> |
|
4 | 4 | <th><%= l(:label_version) %></th> |
|
5 | 5 | <th><%= l(:field_effective_date) %></th> |
|
6 | 6 | <th><%= l(:field_description) %></th> |
|
7 | 7 | <th><%= l(:label_wiki_page) unless @project.wiki.nil? %></th> |
|
8 | 8 | <th style="width:15%"></th> |
|
9 | 9 | <th style="width:15%"></th> |
|
10 | 10 | </thead> |
|
11 | 11 | <tbody> |
|
12 | 12 | <% for version in @project.versions.sort %> |
|
13 | 13 | <tr class="<%= cycle 'odd', 'even' %>"> |
|
14 | 14 | <td><%= link_to h(version.name), :controller => 'versions', :action => 'show', :id => version %></td> |
|
15 | 15 | <td align="center"><%= format_date(version.effective_date) %></td> |
|
16 | 16 | <td><%=h version.description %></td> |
|
17 | 17 | <td><%= link_to(version.wiki_page_title, :controller => 'wiki', :page => Wiki.titleize(version.wiki_page_title)) unless version.wiki_page_title.blank? || @project.wiki.nil? %></td> |
|
18 | 18 | <td align="center"><%= link_to_if_authorized l(:button_edit), { :controller => 'versions', :action => 'edit', :id => version }, :class => 'icon icon-edit' %></td> |
|
19 | 19 | <td align="center"><%= link_to_if_authorized l(:button_delete), {:controller => 'versions', :action => 'destroy', :id => version}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %></td> |
|
20 | </td> | |
|
21 | 20 | </tr> |
|
22 | 21 | <% end; reset_cycle %> |
|
23 | 22 | </tbody> |
|
24 | 23 | </table> |
|
25 | 24 | <% else %> |
|
26 | 25 | <p class="nodata"><%= l(:label_no_data) %></p> |
|
27 | 26 | <% end %> |
|
28 | 27 | |
|
29 | 28 | <p><%= link_to_if_authorized l(:label_version_new), :controller => 'projects', :action => 'add_version', :id => @project %></p> |
@@ -1,18 +1,18 | |||
|
1 | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
|
2 | 2 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> |
|
3 | 3 | <head> |
|
4 | 4 | <title><%=h @page.pretty_title %></title> |
|
5 | 5 | <meta http-equiv="content-type" content="text/html; charset=utf-8" /> |
|
6 | 6 | <style> |
|
7 | 7 | body { font:80% Verdana,Tahoma,Arial,sans-serif; } |
|
8 | h1, h2, h3, h4 { font-family: Trebuchet MS,Georgia,"Times New Roman",serif; } | |
|
8 | h1, h2, h3, h4 { font-family: "Trebuchet MS",Georgia,"Times New Roman",serif; } | |
|
9 | 9 | ul.toc { padding: 4px; margin-left: 0; } |
|
10 | 10 | ul.toc li { list-style-type:none; } |
|
11 | 11 | ul.toc li.heading2 { margin-left: 1em; } |
|
12 | 12 | ul.toc li.heading3 { margin-left: 2em; } |
|
13 | 13 | </style> |
|
14 | 14 | </head> |
|
15 | 15 | <body> |
|
16 | 16 | <%= textilizable @content, :text, :wiki_links => :local %> |
|
17 | 17 | </body> |
|
18 | 18 | </html> |
@@ -1,27 +1,27 | |||
|
1 | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
|
2 | 2 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> |
|
3 | 3 | <head> |
|
4 | 4 | <title><%=h @wiki.project.name %></title> |
|
5 | 5 | <meta http-equiv="content-type" content="text/html; charset=utf-8" /> |
|
6 | 6 | <style> |
|
7 | 7 | body { font:80% Verdana,Tahoma,Arial,sans-serif; } |
|
8 | h1, h2, h3, h4 { font-family: Trebuchet MS,Georgia,"Times New Roman",serif; } | |
|
8 | h1, h2, h3, h4 { font-family: "Trebuchet MS",Georgia,"Times New Roman",serif; } | |
|
9 | 9 | </style> |
|
10 | 10 | </head> |
|
11 | 11 | <body> |
|
12 | 12 | |
|
13 | 13 | <strong><%= l(:label_index_by_title) %></strong> |
|
14 | 14 | <ul> |
|
15 | 15 | <% @pages.each do |page| %> |
|
16 | 16 | <li><a href="#<%= page.title %>"><%= page.pretty_title %></a></li> |
|
17 | 17 | <% end %> |
|
18 | 18 | </ul> |
|
19 | 19 | |
|
20 | 20 | <% @pages.each do |page| %> |
|
21 | 21 | <hr /> |
|
22 | 22 | <a name="<%= page.title %>" /> |
|
23 | 23 | <%= textilizable page.content ,:text, :wiki_links => :anchor %> |
|
24 | 24 | <% end %> |
|
25 | 25 | |
|
26 | 26 | </body> |
|
27 | 27 | </html> |
@@ -1,14 +1,15 | |||
|
1 | 1 | class SetTopicAuthorsAsWatchers < ActiveRecord::Migration |
|
2 | 2 | def self.up |
|
3 | 3 | # Sets active users who created/replied a topic as watchers of the topic |
|
4 | 4 | # so that the new watch functionality at topic level doesn't affect notifications behaviour |
|
5 |
Message.connection.execute("INSERT INTO |
|
|
6 |
" SELECT DISTINCT 'Message', COALESCE(m |
|
|
7 |
" |
|
|
5 | Message.connection.execute("INSERT INTO #{Watcher.table_name} (watchable_type, watchable_id, user_id)" + | |
|
6 | " SELECT DISTINCT 'Message', COALESCE(m.parent_id, m.id), m.author_id" + | |
|
7 | " FROM #{Message.table_name} m, #{User.table_name} u" + | |
|
8 | " WHERE m.author_id = u.id AND u.status = 1") | |
|
8 | 9 | end |
|
9 | 10 | |
|
10 | 11 | def self.down |
|
11 | 12 | # Removes all message watchers |
|
12 | 13 | Watcher.delete_all("watchable_type = 'Message'") |
|
13 | 14 | end |
|
14 | 15 | end |
@@ -1,1177 +1,1177 | |||
|
1 | 1 | # vim:ts=4:sw=4: |
|
2 | 2 | # = RedCloth - Textile and Markdown Hybrid for Ruby |
|
3 | 3 | # |
|
4 | 4 | # Homepage:: http://whytheluckystiff.net/ruby/redcloth/ |
|
5 | 5 | # Author:: why the lucky stiff (http://whytheluckystiff.net/) |
|
6 | 6 | # Copyright:: (cc) 2004 why the lucky stiff (and his puppet organizations.) |
|
7 | 7 | # License:: BSD |
|
8 | 8 | # |
|
9 | 9 | # (see http://hobix.com/textile/ for a Textile Reference.) |
|
10 | 10 | # |
|
11 | 11 | # Based on (and also inspired by) both: |
|
12 | 12 | # |
|
13 | 13 | # PyTextile: http://diveintomark.org/projects/textile/textile.py.txt |
|
14 | 14 | # Textism for PHP: http://www.textism.com/tools/textile/ |
|
15 | 15 | # |
|
16 | 16 | # |
|
17 | 17 | |
|
18 | 18 | # = RedCloth |
|
19 | 19 | # |
|
20 | 20 | # RedCloth is a Ruby library for converting Textile and/or Markdown |
|
21 | 21 | # into HTML. You can use either format, intermingled or separately. |
|
22 | 22 | # You can also extend RedCloth to honor your own custom text stylings. |
|
23 | 23 | # |
|
24 | 24 | # RedCloth users are encouraged to use Textile if they are generating |
|
25 | 25 | # HTML and to use Markdown if others will be viewing the plain text. |
|
26 | 26 | # |
|
27 | 27 | # == What is Textile? |
|
28 | 28 | # |
|
29 | 29 | # Textile is a simple formatting style for text |
|
30 | 30 | # documents, loosely based on some HTML conventions. |
|
31 | 31 | # |
|
32 | 32 | # == Sample Textile Text |
|
33 | 33 | # |
|
34 | 34 | # h2. This is a title |
|
35 | 35 | # |
|
36 | 36 | # h3. This is a subhead |
|
37 | 37 | # |
|
38 | 38 | # This is a bit of paragraph. |
|
39 | 39 | # |
|
40 | 40 | # bq. This is a blockquote. |
|
41 | 41 | # |
|
42 | 42 | # = Writing Textile |
|
43 | 43 | # |
|
44 | 44 | # A Textile document consists of paragraphs. Paragraphs |
|
45 | 45 | # can be specially formatted by adding a small instruction |
|
46 | 46 | # to the beginning of the paragraph. |
|
47 | 47 | # |
|
48 | 48 | # h[n]. Header of size [n]. |
|
49 | 49 | # bq. Blockquote. |
|
50 | 50 | # # Numeric list. |
|
51 | 51 | # * Bulleted list. |
|
52 | 52 | # |
|
53 | 53 | # == Quick Phrase Modifiers |
|
54 | 54 | # |
|
55 | 55 | # Quick phrase modifiers are also included, to allow formatting |
|
56 | 56 | # of small portions of text within a paragraph. |
|
57 | 57 | # |
|
58 | 58 | # \_emphasis\_ |
|
59 | 59 | # \_\_italicized\_\_ |
|
60 | 60 | # \*strong\* |
|
61 | 61 | # \*\*bold\*\* |
|
62 | 62 | # ??citation?? |
|
63 | 63 | # -deleted text- |
|
64 | 64 | # +inserted text+ |
|
65 | 65 | # ^superscript^ |
|
66 | 66 | # ~subscript~ |
|
67 | 67 | # @code@ |
|
68 | 68 | # %(classname)span% |
|
69 | 69 | # |
|
70 | 70 | # ==notextile== (leave text alone) |
|
71 | 71 | # |
|
72 | 72 | # == Links |
|
73 | 73 | # |
|
74 | 74 | # To make a hypertext link, put the link text in "quotation |
|
75 | 75 | # marks" followed immediately by a colon and the URL of the link. |
|
76 | 76 | # |
|
77 | 77 | # Optional: text in (parentheses) following the link text, |
|
78 | 78 | # but before the closing quotation mark, will become a Title |
|
79 | 79 | # attribute for the link, visible as a tool tip when a cursor is above it. |
|
80 | 80 | # |
|
81 | 81 | # Example: |
|
82 | 82 | # |
|
83 | 83 | # "This is a link (This is a title) ":http://www.textism.com |
|
84 | 84 | # |
|
85 | 85 | # Will become: |
|
86 | 86 | # |
|
87 | 87 | # <a href="http://www.textism.com" title="This is a title">This is a link</a> |
|
88 | 88 | # |
|
89 | 89 | # == Images |
|
90 | 90 | # |
|
91 | 91 | # To insert an image, put the URL for the image inside exclamation marks. |
|
92 | 92 | # |
|
93 | 93 | # Optional: text that immediately follows the URL in (parentheses) will |
|
94 | 94 | # be used as the Alt text for the image. Images on the web should always |
|
95 | 95 | # have descriptive Alt text for the benefit of readers using non-graphical |
|
96 | 96 | # browsers. |
|
97 | 97 | # |
|
98 | 98 | # Optional: place a colon followed by a URL immediately after the |
|
99 | 99 | # closing ! to make the image into a link. |
|
100 | 100 | # |
|
101 | 101 | # Example: |
|
102 | 102 | # |
|
103 | 103 | # !http://www.textism.com/common/textist.gif(Textist)! |
|
104 | 104 | # |
|
105 | 105 | # Will become: |
|
106 | 106 | # |
|
107 | 107 | # <img src="http://www.textism.com/common/textist.gif" alt="Textist" /> |
|
108 | 108 | # |
|
109 | 109 | # With a link: |
|
110 | 110 | # |
|
111 | 111 | # !/common/textist.gif(Textist)!:http://textism.com |
|
112 | 112 | # |
|
113 | 113 | # Will become: |
|
114 | 114 | # |
|
115 | 115 | # <a href="http://textism.com"><img src="/common/textist.gif" alt="Textist" /></a> |
|
116 | 116 | # |
|
117 | 117 | # == Defining Acronyms |
|
118 | 118 | # |
|
119 | 119 | # HTML allows authors to define acronyms via the tag. The definition appears as a |
|
120 | 120 | # tool tip when a cursor hovers over the acronym. A crucial aid to clear writing, |
|
121 | 121 | # this should be used at least once for each acronym in documents where they appear. |
|
122 | 122 | # |
|
123 | 123 | # To quickly define an acronym in Textile, place the full text in (parentheses) |
|
124 | 124 | # immediately following the acronym. |
|
125 | 125 | # |
|
126 | 126 | # Example: |
|
127 | 127 | # |
|
128 | 128 | # ACLU(American Civil Liberties Union) |
|
129 | 129 | # |
|
130 | 130 | # Will become: |
|
131 | 131 | # |
|
132 | 132 | # <acronym title="American Civil Liberties Union">ACLU</acronym> |
|
133 | 133 | # |
|
134 | 134 | # == Adding Tables |
|
135 | 135 | # |
|
136 | 136 | # In Textile, simple tables can be added by seperating each column by |
|
137 | 137 | # a pipe. |
|
138 | 138 | # |
|
139 | 139 | # |a|simple|table|row| |
|
140 | 140 | # |And|Another|table|row| |
|
141 | 141 | # |
|
142 | 142 | # Attributes are defined by style definitions in parentheses. |
|
143 | 143 | # |
|
144 | 144 | # table(border:1px solid black). |
|
145 | 145 | # (background:#ddd;color:red). |{}| | | | |
|
146 | 146 | # |
|
147 | 147 | # == Using RedCloth |
|
148 | 148 | # |
|
149 | 149 | # RedCloth is simply an extension of the String class, which can handle |
|
150 | 150 | # Textile formatting. Use it like a String and output HTML with its |
|
151 | 151 | # RedCloth#to_html method. |
|
152 | 152 | # |
|
153 | 153 | # doc = RedCloth.new " |
|
154 | 154 | # |
|
155 | 155 | # h2. Test document |
|
156 | 156 | # |
|
157 | 157 | # Just a simple test." |
|
158 | 158 | # |
|
159 | 159 | # puts doc.to_html |
|
160 | 160 | # |
|
161 | 161 | # By default, RedCloth uses both Textile and Markdown formatting, with |
|
162 | 162 | # Textile formatting taking precedence. If you want to turn off Markdown |
|
163 | 163 | # formatting, to boost speed and limit the processor: |
|
164 | 164 | # |
|
165 | 165 | # class RedCloth::Textile.new( str ) |
|
166 | 166 | |
|
167 | 167 | class RedCloth3 < String |
|
168 | 168 | |
|
169 | 169 | VERSION = '3.0.4' |
|
170 | 170 | DEFAULT_RULES = [:textile, :markdown] |
|
171 | 171 | |
|
172 | 172 | # |
|
173 | 173 | # Two accessor for setting security restrictions. |
|
174 | 174 | # |
|
175 | 175 | # This is a nice thing if you're using RedCloth for |
|
176 | 176 | # formatting in public places (e.g. Wikis) where you |
|
177 | 177 | # don't want users to abuse HTML for bad things. |
|
178 | 178 | # |
|
179 | 179 | # If +:filter_html+ is set, HTML which wasn't |
|
180 | 180 | # created by the Textile processor will be escaped. |
|
181 | 181 | # |
|
182 | 182 | # If +:filter_styles+ is set, it will also disable |
|
183 | 183 | # the style markup specifier. ('{color: red}') |
|
184 | 184 | # |
|
185 | 185 | attr_accessor :filter_html, :filter_styles |
|
186 | 186 | |
|
187 | 187 | # |
|
188 | 188 | # Accessor for toggling hard breaks. |
|
189 | 189 | # |
|
190 | 190 | # If +:hard_breaks+ is set, single newlines will |
|
191 | 191 | # be converted to HTML break tags. This is the |
|
192 | 192 | # default behavior for traditional RedCloth. |
|
193 | 193 | # |
|
194 | 194 | attr_accessor :hard_breaks |
|
195 | 195 | |
|
196 | 196 | # Accessor for toggling lite mode. |
|
197 | 197 | # |
|
198 | 198 | # In lite mode, block-level rules are ignored. This means |
|
199 | 199 | # that tables, paragraphs, lists, and such aren't available. |
|
200 | 200 | # Only the inline markup for bold, italics, entities and so on. |
|
201 | 201 | # |
|
202 | 202 | # r = RedCloth.new( "And then? She *fell*!", [:lite_mode] ) |
|
203 | 203 | # r.to_html |
|
204 | 204 | # #=> "And then? She <strong>fell</strong>!" |
|
205 | 205 | # |
|
206 | 206 | attr_accessor :lite_mode |
|
207 | 207 | |
|
208 | 208 | # |
|
209 | 209 | # Accessor for toggling span caps. |
|
210 | 210 | # |
|
211 | 211 | # Textile places `span' tags around capitalized |
|
212 | 212 | # words by default, but this wreaks havoc on Wikis. |
|
213 | 213 | # If +:no_span_caps+ is set, this will be |
|
214 | 214 | # suppressed. |
|
215 | 215 | # |
|
216 | 216 | attr_accessor :no_span_caps |
|
217 | 217 | |
|
218 | 218 | # |
|
219 | 219 | # Establishes the markup predence. Available rules include: |
|
220 | 220 | # |
|
221 | 221 | # == Textile Rules |
|
222 | 222 | # |
|
223 | 223 | # The following textile rules can be set individually. Or add the complete |
|
224 | 224 | # set of rules with the single :textile rule, which supplies the rule set in |
|
225 | 225 | # the following precedence: |
|
226 | 226 | # |
|
227 | 227 | # refs_textile:: Textile references (i.e. [hobix]http://hobix.com/) |
|
228 | 228 | # block_textile_table:: Textile table block structures |
|
229 | 229 | # block_textile_lists:: Textile list structures |
|
230 | 230 | # block_textile_prefix:: Textile blocks with prefixes (i.e. bq., h2., etc.) |
|
231 | 231 | # inline_textile_image:: Textile inline images |
|
232 | 232 | # inline_textile_link:: Textile inline links |
|
233 | 233 | # inline_textile_span:: Textile inline spans |
|
234 | 234 | # glyphs_textile:: Textile entities (such as em-dashes and smart quotes) |
|
235 | 235 | # |
|
236 | 236 | # == Markdown |
|
237 | 237 | # |
|
238 | 238 | # refs_markdown:: Markdown references (for example: [hobix]: http://hobix.com/) |
|
239 | 239 | # block_markdown_setext:: Markdown setext headers |
|
240 | 240 | # block_markdown_atx:: Markdown atx headers |
|
241 | 241 | # block_markdown_rule:: Markdown horizontal rules |
|
242 | 242 | # block_markdown_bq:: Markdown blockquotes |
|
243 | 243 | # block_markdown_lists:: Markdown lists |
|
244 | 244 | # inline_markdown_link:: Markdown links |
|
245 | 245 | attr_accessor :rules |
|
246 | 246 | |
|
247 | 247 | # Returns a new RedCloth object, based on _string_ and |
|
248 | 248 | # enforcing all the included _restrictions_. |
|
249 | 249 | # |
|
250 | 250 | # r = RedCloth.new( "h1. A <b>bold</b> man", [:filter_html] ) |
|
251 | 251 | # r.to_html |
|
252 | 252 | # #=>"<h1>A <b>bold</b> man</h1>" |
|
253 | 253 | # |
|
254 | 254 | def initialize( string, restrictions = [] ) |
|
255 | 255 | restrictions.each { |r| method( "#{ r }=" ).call( true ) } |
|
256 | 256 | super( string ) |
|
257 | 257 | end |
|
258 | 258 | |
|
259 | 259 | # |
|
260 | 260 | # Generates HTML from the Textile contents. |
|
261 | 261 | # |
|
262 | 262 | # r = RedCloth.new( "And then? She *fell*!" ) |
|
263 | 263 | # r.to_html( true ) |
|
264 | 264 | # #=>"And then? She <strong>fell</strong>!" |
|
265 | 265 | # |
|
266 | 266 | def to_html( *rules ) |
|
267 | 267 | rules = DEFAULT_RULES if rules.empty? |
|
268 | 268 | # make our working copy |
|
269 | 269 | text = self.dup |
|
270 | 270 | |
|
271 | 271 | @urlrefs = {} |
|
272 | 272 | @shelf = [] |
|
273 | 273 | textile_rules = [:refs_textile, :block_textile_table, :block_textile_lists, |
|
274 | 274 | :block_textile_prefix, :inline_textile_image, :inline_textile_link, |
|
275 | 275 | :inline_textile_code, :inline_textile_span, :glyphs_textile] |
|
276 | 276 | markdown_rules = [:refs_markdown, :block_markdown_setext, :block_markdown_atx, :block_markdown_rule, |
|
277 | 277 | :block_markdown_bq, :block_markdown_lists, |
|
278 | 278 | :inline_markdown_reflink, :inline_markdown_link] |
|
279 | 279 | @rules = rules.collect do |rule| |
|
280 | 280 | case rule |
|
281 | 281 | when :markdown |
|
282 | 282 | markdown_rules |
|
283 | 283 | when :textile |
|
284 | 284 | textile_rules |
|
285 | 285 | else |
|
286 | 286 | rule |
|
287 | 287 | end |
|
288 | 288 | end.flatten |
|
289 | 289 | |
|
290 | 290 | # standard clean up |
|
291 | 291 | incoming_entities text |
|
292 | 292 | clean_white_space text |
|
293 | 293 | |
|
294 | 294 | # start processor |
|
295 | 295 | @pre_list = [] |
|
296 | 296 | rip_offtags text |
|
297 | 297 | no_textile text |
|
298 | 298 | escape_html_tags text |
|
299 | 299 | hard_break text |
|
300 | 300 | unless @lite_mode |
|
301 | 301 | refs text |
|
302 | 302 | # need to do this before text is split by #blocks |
|
303 | 303 | block_textile_quotes text |
|
304 | 304 | blocks text |
|
305 | 305 | end |
|
306 | 306 | inline text |
|
307 | 307 | smooth_offtags text |
|
308 | 308 | |
|
309 | 309 | retrieve text |
|
310 | 310 | |
|
311 | 311 | text.gsub!( /<\/?notextile>/, '' ) |
|
312 | 312 | text.gsub!( /x%x%/, '&' ) |
|
313 | 313 | clean_html text if filter_html |
|
314 | 314 | text.strip! |
|
315 | 315 | text |
|
316 | 316 | |
|
317 | 317 | end |
|
318 | 318 | |
|
319 | 319 | ####### |
|
320 | 320 | private |
|
321 | 321 | ####### |
|
322 | 322 | # |
|
323 | 323 | # Mapping of 8-bit ASCII codes to HTML numerical entity equivalents. |
|
324 | 324 | # (from PyTextile) |
|
325 | 325 | # |
|
326 | 326 | TEXTILE_TAGS = |
|
327 | 327 | |
|
328 | 328 | [[128, 8364], [129, 0], [130, 8218], [131, 402], [132, 8222], [133, 8230], |
|
329 | 329 | [134, 8224], [135, 8225], [136, 710], [137, 8240], [138, 352], [139, 8249], |
|
330 | 330 | [140, 338], [141, 0], [142, 0], [143, 0], [144, 0], [145, 8216], [146, 8217], |
|
331 | 331 | [147, 8220], [148, 8221], [149, 8226], [150, 8211], [151, 8212], [152, 732], |
|
332 | 332 | [153, 8482], [154, 353], [155, 8250], [156, 339], [157, 0], [158, 0], [159, 376]]. |
|
333 | 333 | |
|
334 | 334 | collect! do |a, b| |
|
335 | 335 | [a.chr, ( b.zero? and "" or "&#{ b };" )] |
|
336 | 336 | end |
|
337 | 337 | |
|
338 | 338 | # |
|
339 | 339 | # Regular expressions to convert to HTML. |
|
340 | 340 | # |
|
341 | 341 | A_HLGN = /(?:(?:<>|<|>|\=|[()]+)+)/ |
|
342 | 342 | A_VLGN = /[\-^~]/ |
|
343 | 343 | C_CLAS = '(?:\([^)]+\))' |
|
344 | 344 | C_LNGE = '(?:\[[^\[\]]+\])' |
|
345 | 345 | C_STYL = '(?:\{[^}]+\})' |
|
346 | 346 | S_CSPN = '(?:\\\\\d+)' |
|
347 | 347 | S_RSPN = '(?:/\d+)' |
|
348 | 348 | A = "(?:#{A_HLGN}?#{A_VLGN}?|#{A_VLGN}?#{A_HLGN}?)" |
|
349 | 349 | S = "(?:#{S_CSPN}?#{S_RSPN}|#{S_RSPN}?#{S_CSPN}?)" |
|
350 | 350 | C = "(?:#{C_CLAS}?#{C_STYL}?#{C_LNGE}?|#{C_STYL}?#{C_LNGE}?#{C_CLAS}?|#{C_LNGE}?#{C_STYL}?#{C_CLAS}?)" |
|
351 | 351 | # PUNCT = Regexp::quote( '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' ) |
|
352 | 352 | PUNCT = Regexp::quote( '!"#$%&\'*+,-./:;=?@\\^_`|~' ) |
|
353 | 353 | PUNCT_NOQ = Regexp::quote( '!"#$&\',./:;=?@\\`|' ) |
|
354 | 354 | PUNCT_Q = Regexp::quote( '*-_+^~%' ) |
|
355 | 355 | HYPERLINK = '(\S+?)([^\w\s/;=\?]*?)(?=\s|<|$)' |
|
356 | 356 | |
|
357 | 357 | # Text markup tags, don't conflict with block tags |
|
358 | 358 | SIMPLE_HTML_TAGS = [ |
|
359 | 359 | 'tt', 'b', 'i', 'big', 'small', 'em', 'strong', 'dfn', 'code', |
|
360 | 360 | 'samp', 'kbd', 'var', 'cite', 'abbr', 'acronym', 'a', 'img', 'br', |
|
361 | 361 | 'br', 'map', 'q', 'sub', 'sup', 'span', 'bdo' |
|
362 | 362 | ] |
|
363 | 363 | |
|
364 | 364 | QTAGS = [ |
|
365 | 365 | ['**', 'b', :limit], |
|
366 | 366 | ['*', 'strong', :limit], |
|
367 | 367 | ['??', 'cite', :limit], |
|
368 | 368 | ['-', 'del', :limit], |
|
369 | 369 | ['__', 'i', :limit], |
|
370 | 370 | ['_', 'em', :limit], |
|
371 | 371 | ['%', 'span', :limit], |
|
372 | 372 | ['+', 'ins', :limit], |
|
373 | 373 | ['^', 'sup', :limit], |
|
374 | 374 | ['~', 'sub', :limit] |
|
375 | 375 | ] |
|
376 | 376 | QTAGS.collect! do |rc, ht, rtype| |
|
377 | 377 | rcq = Regexp::quote rc |
|
378 | 378 | re = |
|
379 | 379 | case rtype |
|
380 | 380 | when :limit |
|
381 | 381 | /(^|[>\s\(]) |
|
382 | 382 | (#{rcq}) |
|
383 | 383 | (#{C}) |
|
384 | 384 | (?::(\S+?))? |
|
385 | 385 | (\w|[^\s\-].*?[^\s\-]) |
|
386 | 386 | #{rcq} |
|
387 | 387 | (?=[[:punct:]]|\s|\)|$)/x |
|
388 | 388 | else |
|
389 | 389 | /(#{rcq}) |
|
390 | 390 | (#{C}) |
|
391 | 391 | (?::(\S+))? |
|
392 | 392 | (\w|[^\s\-].*?[^\s\-]) |
|
393 | 393 | #{rcq}/xm |
|
394 | 394 | end |
|
395 | 395 | [rc, ht, re, rtype] |
|
396 | 396 | end |
|
397 | 397 | |
|
398 | 398 | # Elements to handle |
|
399 | 399 | GLYPHS = [ |
|
400 | 400 | # [ /([^\s\[{(>])?\'([dmst]\b|ll\b|ve\b|\s|:|$)/, '\1’\2' ], # single closing |
|
401 | 401 | # [ /([^\s\[{(>#{PUNCT_Q}][#{PUNCT_Q}]*)\'/, '\1’' ], # single closing |
|
402 | 402 | # [ /\'(?=[#{PUNCT_Q}]*(s\b|[\s#{PUNCT_NOQ}]))/, '’' ], # single closing |
|
403 | 403 | # [ /\'/, '‘' ], # single opening |
|
404 | 404 | # [ /</, '<' ], # less-than |
|
405 | 405 | # [ />/, '>' ], # greater-than |
|
406 | 406 | # [ /([^\s\[{(])?"(\s|:|$)/, '\1”\2' ], # double closing |
|
407 | 407 | # [ /([^\s\[{(>#{PUNCT_Q}][#{PUNCT_Q}]*)"/, '\1”' ], # double closing |
|
408 | 408 | # [ /"(?=[#{PUNCT_Q}]*[\s#{PUNCT_NOQ}])/, '”' ], # double closing |
|
409 | 409 | # [ /"/, '“' ], # double opening |
|
410 | 410 | # [ /\b( )?\.{3}/, '\1…' ], # ellipsis |
|
411 | 411 | # [ /\b([A-Z][A-Z0-9]{2,})\b(?:[(]([^)]*)[)])/, '<acronym title="\2">\1</acronym>' ], # 3+ uppercase acronym |
|
412 | 412 | # [ /(^|[^"][>\s])([A-Z][A-Z0-9 ]+[A-Z0-9])([^<A-Za-z0-9]|$)/, '\1<span class="caps">\2</span>\3', :no_span_caps ], # 3+ uppercase caps |
|
413 | 413 | # [ /(\.\s)?\s?--\s?/, '\1—' ], # em dash |
|
414 | 414 | # [ /\s->\s/, ' → ' ], # right arrow |
|
415 | 415 | # [ /\s-\s/, ' – ' ], # en dash |
|
416 | 416 | # [ /(\d+) ?x ?(\d+)/, '\1×\2' ], # dimension sign |
|
417 | 417 | # [ /\b ?[(\[]TM[\])]/i, '™' ], # trademark |
|
418 | 418 | # [ /\b ?[(\[]R[\])]/i, '®' ], # registered |
|
419 | 419 | # [ /\b ?[(\[]C[\])]/i, '©' ] # copyright |
|
420 | 420 | ] |
|
421 | 421 | |
|
422 | 422 | H_ALGN_VALS = { |
|
423 | 423 | '<' => 'left', |
|
424 | 424 | '=' => 'center', |
|
425 | 425 | '>' => 'right', |
|
426 | 426 | '<>' => 'justify' |
|
427 | 427 | } |
|
428 | 428 | |
|
429 | 429 | V_ALGN_VALS = { |
|
430 | 430 | '^' => 'top', |
|
431 | 431 | '-' => 'middle', |
|
432 | 432 | '~' => 'bottom' |
|
433 | 433 | } |
|
434 | 434 | |
|
435 | 435 | # |
|
436 | 436 | # Flexible HTML escaping |
|
437 | 437 | # |
|
438 | 438 | def htmlesc( str, mode=:Quotes ) |
|
439 | 439 | if str |
|
440 | 440 | str.gsub!( '&', '&' ) |
|
441 | 441 | str.gsub!( '"', '"' ) if mode != :NoQuotes |
|
442 | 442 | str.gsub!( "'", ''' ) if mode == :Quotes |
|
443 | 443 | str.gsub!( '<', '<') |
|
444 | 444 | str.gsub!( '>', '>') |
|
445 | 445 | end |
|
446 | 446 | str |
|
447 | 447 | end |
|
448 | 448 | |
|
449 | 449 | # Search and replace for Textile glyphs (quotes, dashes, other symbols) |
|
450 | 450 | def pgl( text ) |
|
451 | 451 | #GLYPHS.each do |re, resub, tog| |
|
452 | 452 | # next if tog and method( tog ).call |
|
453 | 453 | # text.gsub! re, resub |
|
454 | 454 | #end |
|
455 | 455 | text.gsub!(/\b([A-Z][A-Z0-9]{2,})\b(?:[(]([^)]*)[)])/) do |m| |
|
456 | 456 | "<acronym title=\"#{htmlesc $2}\">#{$1}</acronym>" |
|
457 | 457 | end |
|
458 | 458 | end |
|
459 | 459 | |
|
460 | 460 | # Parses Textile attribute lists and builds an HTML attribute string |
|
461 | 461 | def pba( text_in, element = "" ) |
|
462 | 462 | |
|
463 | 463 | return '' unless text_in |
|
464 | 464 | |
|
465 | 465 | style = [] |
|
466 | 466 | text = text_in.dup |
|
467 | 467 | if element == 'td' |
|
468 | 468 | colspan = $1 if text =~ /\\(\d+)/ |
|
469 | 469 | rowspan = $1 if text =~ /\/(\d+)/ |
|
470 | 470 | style << "vertical-align:#{ v_align( $& ) };" if text =~ A_VLGN |
|
471 | 471 | end |
|
472 | 472 | |
|
473 | 473 | style << "#{ htmlesc $1 };" if text.sub!( /\{([^}]*)\}/, '' ) && !filter_styles |
|
474 | 474 | |
|
475 | 475 | lang = $1 if |
|
476 | 476 | text.sub!( /\[([^)]+?)\]/, '' ) |
|
477 | 477 | |
|
478 | 478 | cls = $1 if |
|
479 | 479 | text.sub!( /\(([^()]+?)\)/, '' ) |
|
480 | 480 | |
|
481 | 481 | style << "padding-left:#{ $1.length }em;" if |
|
482 | 482 | text.sub!( /([(]+)/, '' ) |
|
483 | 483 | |
|
484 | 484 | style << "padding-right:#{ $1.length }em;" if text.sub!( /([)]+)/, '' ) |
|
485 | 485 | |
|
486 | 486 | style << "text-align:#{ h_align( $& ) };" if text =~ A_HLGN |
|
487 | 487 | |
|
488 | 488 | cls, id = $1, $2 if cls =~ /^(.*?)#(.*)$/ |
|
489 | 489 | |
|
490 | 490 | atts = '' |
|
491 | 491 | atts << " style=\"#{ style.join }\"" unless style.empty? |
|
492 | 492 | atts << " class=\"#{ cls }\"" unless cls.to_s.empty? |
|
493 | 493 | atts << " lang=\"#{ lang }\"" if lang |
|
494 | 494 | atts << " id=\"#{ id }\"" if id |
|
495 | 495 | atts << " colspan=\"#{ colspan }\"" if colspan |
|
496 | 496 | atts << " rowspan=\"#{ rowspan }\"" if rowspan |
|
497 | 497 | |
|
498 | 498 | atts |
|
499 | 499 | end |
|
500 | 500 | |
|
501 | 501 | TABLE_RE = /^(?:table(_?#{S}#{A}#{C})\. ?\n)?^(#{A}#{C}\.? ?\|.*?\|)(\n\n|\Z)/m |
|
502 | 502 | |
|
503 | 503 | # Parses a Textile table block, building HTML from the result. |
|
504 | 504 | def block_textile_table( text ) |
|
505 | 505 | text.gsub!( TABLE_RE ) do |matches| |
|
506 | 506 | |
|
507 | 507 | tatts, fullrow = $~[1..2] |
|
508 | 508 | tatts = pba( tatts, 'table' ) |
|
509 | 509 | tatts = shelve( tatts ) if tatts |
|
510 | 510 | rows = [] |
|
511 | 511 | |
|
512 | 512 | fullrow.each_line do |row| |
|
513 | 513 | ratts, row = pba( $1, 'tr' ), $2 if row =~ /^(#{A}#{C}\. )(.*)/m |
|
514 | 514 | cells = [] |
|
515 | 515 | row.split( /(\|)(?![^\[\|]*\]\])/ )[1..-2].each do |cell| |
|
516 | 516 | next if cell == '|' |
|
517 | 517 | ctyp = 'd' |
|
518 | 518 | ctyp = 'h' if cell =~ /^_/ |
|
519 | 519 | |
|
520 | 520 | catts = '' |
|
521 | 521 | catts, cell = pba( $1, 'td' ), $2 if cell =~ /^(_?#{S}#{A}#{C}\. ?)(.*)/ |
|
522 | 522 | |
|
523 | 523 | catts = shelve( catts ) if catts |
|
524 | 524 | cells << "\t\t\t<t#{ ctyp }#{ catts }>#{ cell }</t#{ ctyp }>" |
|
525 | 525 | end |
|
526 | 526 | ratts = shelve( ratts ) if ratts |
|
527 | 527 | rows << "\t\t<tr#{ ratts }>\n#{ cells.join( "\n" ) }\n\t\t</tr>" |
|
528 | 528 | end |
|
529 | 529 | "\t<table#{ tatts }>\n#{ rows.join( "\n" ) }\n\t</table>\n\n" |
|
530 | 530 | end |
|
531 | 531 | end |
|
532 | 532 | |
|
533 | 533 | LISTS_RE = /^([#*]+?#{C} .*?)$(?![^#*])/m |
|
534 | 534 | LISTS_CONTENT_RE = /^([#*]+)(#{A}#{C}) (.*)$/m |
|
535 | 535 | |
|
536 | 536 | # Parses Textile lists and generates HTML |
|
537 | 537 | def block_textile_lists( text ) |
|
538 | 538 | text.gsub!( LISTS_RE ) do |match| |
|
539 | 539 | lines = match.split( /\n/ ) |
|
540 | 540 | last_line = -1 |
|
541 | 541 | depth = [] |
|
542 | 542 | lines.each_with_index do |line, line_id| |
|
543 | 543 | if line =~ LISTS_CONTENT_RE |
|
544 | 544 | tl,atts,content = $~[1..3] |
|
545 | 545 | if depth.last |
|
546 | 546 | if depth.last.length > tl.length |
|
547 | 547 | (depth.length - 1).downto(0) do |i| |
|
548 | 548 | break if depth[i].length == tl.length |
|
549 | 549 | lines[line_id - 1] << "</li>\n\t</#{ lT( depth[i] ) }l>\n\t" |
|
550 | 550 | depth.pop |
|
551 | 551 | end |
|
552 | 552 | end |
|
553 | 553 | if depth.last and depth.last.length == tl.length |
|
554 | 554 | lines[line_id - 1] << '</li>' |
|
555 | 555 | end |
|
556 | 556 | end |
|
557 | 557 | unless depth.last == tl |
|
558 | 558 | depth << tl |
|
559 | 559 | atts = pba( atts ) |
|
560 | 560 | atts = shelve( atts ) if atts |
|
561 | 561 | lines[line_id] = "\t<#{ lT(tl) }l#{ atts }>\n\t<li>#{ content }" |
|
562 | 562 | else |
|
563 | 563 | lines[line_id] = "\t\t<li>#{ content }" |
|
564 | 564 | end |
|
565 | 565 | last_line = line_id |
|
566 | 566 | |
|
567 | 567 | else |
|
568 | 568 | last_line = line_id |
|
569 | 569 | end |
|
570 | 570 | if line_id - last_line > 1 or line_id == lines.length - 1 |
|
571 | 571 | depth.delete_if do |v| |
|
572 | 572 | lines[last_line] << "</li>\n\t</#{ lT( v ) }l>" |
|
573 | 573 | end |
|
574 | 574 | end |
|
575 | 575 | end |
|
576 | 576 | lines.join( "\n" ) |
|
577 | 577 | end |
|
578 | 578 | end |
|
579 | 579 | |
|
580 | 580 | QUOTES_RE = /(^>+([^\n]*?)\n?)+/m |
|
581 | 581 | QUOTES_CONTENT_RE = /^([> ]+)(.*)$/m |
|
582 | 582 | |
|
583 | 583 | def block_textile_quotes( text ) |
|
584 | 584 | text.gsub!( QUOTES_RE ) do |match| |
|
585 | 585 | lines = match.split( /\n/ ) |
|
586 | 586 | quotes = '' |
|
587 | 587 | indent = 0 |
|
588 | 588 | lines.each do |line| |
|
589 | 589 | line =~ QUOTES_CONTENT_RE |
|
590 | 590 | bq,content = $1, $2 |
|
591 | 591 | l = bq.count('>') |
|
592 | 592 | if l != indent |
|
593 | 593 | quotes << ("\n\n" + (l>indent ? '<blockquote>' * (l-indent) : '</blockquote>' * (indent-l)) + "\n\n") |
|
594 | 594 | indent = l |
|
595 | 595 | end |
|
596 | 596 | quotes << (content + "\n") |
|
597 | 597 | end |
|
598 | 598 | quotes << ("\n" + '</blockquote>' * indent + "\n\n") |
|
599 | 599 | quotes |
|
600 | 600 | end |
|
601 | 601 | end |
|
602 | 602 | |
|
603 | 603 | CODE_RE = /(\W) |
|
604 | 604 | @ |
|
605 | 605 | (?:\|(\w+?)\|)? |
|
606 | 606 | (.+?) |
|
607 | 607 | @ |
|
608 | 608 | (?=\W)/x |
|
609 | 609 | |
|
610 | 610 | def inline_textile_code( text ) |
|
611 | 611 | text.gsub!( CODE_RE ) do |m| |
|
612 | 612 | before,lang,code,after = $~[1..4] |
|
613 | 613 | lang = " lang=\"#{ lang }\"" if lang |
|
614 | 614 | rip_offtags( "#{ before }<code#{ lang }>#{ code }</code>#{ after }" ) |
|
615 | 615 | end |
|
616 | 616 | end |
|
617 | 617 | |
|
618 | 618 | def lT( text ) |
|
619 | 619 | text =~ /\#$/ ? 'o' : 'u' |
|
620 | 620 | end |
|
621 | 621 | |
|
622 | 622 | def hard_break( text ) |
|
623 | 623 | text.gsub!( /(.)\n(?!\Z| *([#*=]+(\s|$)|[{|]))/, "\\1<br />" ) if hard_breaks |
|
624 | 624 | end |
|
625 | 625 | |
|
626 | 626 | BLOCKS_GROUP_RE = /\n{2,}(?! )/m |
|
627 | 627 | |
|
628 | 628 | def blocks( text, deep_code = false ) |
|
629 | 629 | text.replace( text.split( BLOCKS_GROUP_RE ).collect do |blk| |
|
630 | 630 | plain = blk !~ /\A[#*> ]/ |
|
631 | 631 | |
|
632 | 632 | # skip blocks that are complex HTML |
|
633 | 633 | if blk =~ /^<\/?(\w+).*>/ and not SIMPLE_HTML_TAGS.include? $1 |
|
634 | 634 | blk |
|
635 | 635 | else |
|
636 | 636 | # search for indentation levels |
|
637 | 637 | blk.strip! |
|
638 | 638 | if blk.empty? |
|
639 | 639 | blk |
|
640 | 640 | else |
|
641 | 641 | code_blk = nil |
|
642 | 642 | blk.gsub!( /((?:\n(?:\n^ +[^\n]*)+)+)/m ) do |iblk| |
|
643 | 643 | flush_left iblk |
|
644 | 644 | blocks iblk, plain |
|
645 | 645 | iblk.gsub( /^(\S)/, "\t\\1" ) |
|
646 | 646 | if plain |
|
647 | 647 | code_blk = iblk; "" |
|
648 | 648 | else |
|
649 | 649 | iblk |
|
650 | 650 | end |
|
651 | 651 | end |
|
652 | 652 | |
|
653 | 653 | block_applied = 0 |
|
654 | 654 | @rules.each do |rule_name| |
|
655 | 655 | block_applied += 1 if ( rule_name.to_s.match /^block_/ and method( rule_name ).call( blk ) ) |
|
656 | 656 | end |
|
657 | 657 | if block_applied.zero? |
|
658 | 658 | if deep_code |
|
659 | 659 | blk = "\t<pre><code>#{ blk }</code></pre>" |
|
660 | 660 | else |
|
661 | 661 | blk = "\t<p>#{ blk }</p>" |
|
662 | 662 | end |
|
663 | 663 | end |
|
664 | 664 | # hard_break blk |
|
665 | 665 | blk + "\n#{ code_blk }" |
|
666 | 666 | end |
|
667 | 667 | end |
|
668 | 668 | |
|
669 | 669 | end.join( "\n\n" ) ) |
|
670 | 670 | end |
|
671 | 671 | |
|
672 | 672 | def textile_bq( tag, atts, cite, content ) |
|
673 | 673 | cite, cite_title = check_refs( cite ) |
|
674 | 674 | cite = " cite=\"#{ cite }\"" if cite |
|
675 | 675 | atts = shelve( atts ) if atts |
|
676 | 676 | "\t<blockquote#{ cite }>\n\t\t<p#{ atts }>#{ content }</p>\n\t</blockquote>" |
|
677 | 677 | end |
|
678 | 678 | |
|
679 | 679 | def textile_p( tag, atts, cite, content ) |
|
680 | 680 | atts = shelve( atts ) if atts |
|
681 | 681 | "\t<#{ tag }#{ atts }>#{ content }</#{ tag }>" |
|
682 | 682 | end |
|
683 | 683 | |
|
684 | 684 | alias textile_h1 textile_p |
|
685 | 685 | alias textile_h2 textile_p |
|
686 | 686 | alias textile_h3 textile_p |
|
687 | 687 | alias textile_h4 textile_p |
|
688 | 688 | alias textile_h5 textile_p |
|
689 | 689 | alias textile_h6 textile_p |
|
690 | 690 | |
|
691 | 691 | def textile_fn_( tag, num, atts, cite, content ) |
|
692 | 692 | atts << " id=\"fn#{ num }\" class=\"footnote\"" |
|
693 | 693 | content = "<sup>#{ num }</sup> #{ content }" |
|
694 | 694 | atts = shelve( atts ) if atts |
|
695 | 695 | "\t<p#{ atts }>#{ content }</p>" |
|
696 | 696 | end |
|
697 | 697 | |
|
698 | 698 | BLOCK_RE = /^(([a-z]+)(\d*))(#{A}#{C})\.(?::(\S+))? (.*)$/m |
|
699 | 699 | |
|
700 | 700 | def block_textile_prefix( text ) |
|
701 | 701 | if text =~ BLOCK_RE |
|
702 | 702 | tag,tagpre,num,atts,cite,content = $~[1..6] |
|
703 | 703 | atts = pba( atts ) |
|
704 | 704 | |
|
705 | 705 | # pass to prefix handler |
|
706 | 706 | if respond_to? "textile_#{ tag }", true |
|
707 | 707 | text.gsub!( $&, method( "textile_#{ tag }" ).call( tag, atts, cite, content ) ) |
|
708 | 708 | elsif respond_to? "textile_#{ tagpre }_", true |
|
709 | 709 | text.gsub!( $&, method( "textile_#{ tagpre }_" ).call( tagpre, num, atts, cite, content ) ) |
|
710 | 710 | end |
|
711 | 711 | end |
|
712 | 712 | end |
|
713 | 713 | |
|
714 | 714 | SETEXT_RE = /\A(.+?)\n([=-])[=-]* *$/m |
|
715 | 715 | def block_markdown_setext( text ) |
|
716 | 716 | if text =~ SETEXT_RE |
|
717 | 717 | tag = if $2 == "="; "h1"; else; "h2"; end |
|
718 | 718 | blk, cont = "<#{ tag }>#{ $1 }</#{ tag }>", $' |
|
719 | 719 | blocks cont |
|
720 | 720 | text.replace( blk + cont ) |
|
721 | 721 | end |
|
722 | 722 | end |
|
723 | 723 | |
|
724 | 724 | ATX_RE = /\A(\#{1,6}) # $1 = string of #'s |
|
725 | 725 | [ ]* |
|
726 | 726 | (.+?) # $2 = Header text |
|
727 | 727 | [ ]* |
|
728 | 728 | \#* # optional closing #'s (not counted) |
|
729 | 729 | $/x |
|
730 | 730 | def block_markdown_atx( text ) |
|
731 | 731 | if text =~ ATX_RE |
|
732 | 732 | tag = "h#{ $1.length }" |
|
733 | 733 | blk, cont = "<#{ tag }>#{ $2 }</#{ tag }>\n\n", $' |
|
734 | 734 | blocks cont |
|
735 | 735 | text.replace( blk + cont ) |
|
736 | 736 | end |
|
737 | 737 | end |
|
738 | 738 | |
|
739 | 739 | MARKDOWN_BQ_RE = /\A(^ *> ?.+$(.+\n)*\n*)+/m |
|
740 | 740 | |
|
741 | 741 | def block_markdown_bq( text ) |
|
742 | 742 | text.gsub!( MARKDOWN_BQ_RE ) do |blk| |
|
743 | 743 | blk.gsub!( /^ *> ?/, '' ) |
|
744 | 744 | flush_left blk |
|
745 | 745 | blocks blk |
|
746 | 746 | blk.gsub!( /^(\S)/, "\t\\1" ) |
|
747 | 747 | "<blockquote>\n#{ blk }\n</blockquote>\n\n" |
|
748 | 748 | end |
|
749 | 749 | end |
|
750 | 750 | |
|
751 | 751 | MARKDOWN_RULE_RE = /^(#{ |
|
752 | 752 | ['*', '-', '_'].collect { |ch| ' ?(' + Regexp::quote( ch ) + ' ?){3,}' }.join( '|' ) |
|
753 | 753 | })$/ |
|
754 | 754 | |
|
755 | 755 | def block_markdown_rule( text ) |
|
756 | 756 | text.gsub!( MARKDOWN_RULE_RE ) do |blk| |
|
757 | 757 | "<hr />" |
|
758 | 758 | end |
|
759 | 759 | end |
|
760 | 760 | |
|
761 | 761 | # XXX TODO XXX |
|
762 | 762 | def block_markdown_lists( text ) |
|
763 | 763 | end |
|
764 | 764 | |
|
765 | 765 | def inline_textile_span( text ) |
|
766 | 766 | QTAGS.each do |qtag_rc, ht, qtag_re, rtype| |
|
767 | 767 | text.gsub!( qtag_re ) do |m| |
|
768 | 768 | |
|
769 | 769 | case rtype |
|
770 | 770 | when :limit |
|
771 | 771 | sta,qtag,atts,cite,content = $~[1..5] |
|
772 | 772 | else |
|
773 | 773 | qtag,atts,cite,content = $~[1..4] |
|
774 | 774 | sta = '' |
|
775 | 775 | end |
|
776 | 776 | atts = pba( atts ) |
|
777 | 777 | atts << " cite=\"#{ cite }\"" if cite |
|
778 | 778 | atts = shelve( atts ) if atts |
|
779 | 779 | |
|
780 | 780 | "#{ sta }<#{ ht }#{ atts }>#{ content }</#{ ht }>" |
|
781 | 781 | |
|
782 | 782 | end |
|
783 | 783 | end |
|
784 | 784 | end |
|
785 | 785 | |
|
786 | 786 | LINK_RE = / |
|
787 | 787 | ([\s\[{(]|[#{PUNCT}])? # $pre |
|
788 | 788 | " # start |
|
789 | 789 | (#{C}) # $atts |
|
790 | 790 | ([^"\n]+?) # $text |
|
791 | 791 | \s? |
|
792 | 792 | (?:\(([^)]+?)\)(?="))? # $title |
|
793 | 793 | ": |
|
794 | 794 | ( # $url |
|
795 | (\/|https?:\/\/|s?ftps?:\/\/|www\.) | |
|
795 | (\/|[a-zA-Z]+:\/\/|www\.) # $proto | |
|
796 | 796 | [\w\/]\S+? |
|
797 | 797 | ) |
|
798 | 798 | (\/)? # $slash |
|
799 | 799 | ([^\w\=\/;\(\)]*?) # $post |
|
800 | 800 | (?=<|\s|$) |
|
801 | 801 | /x |
|
802 | 802 | #" |
|
803 | 803 | def inline_textile_link( text ) |
|
804 | 804 | text.gsub!( LINK_RE ) do |m| |
|
805 | 805 | pre,atts,text,title,url,proto,slash,post = $~[1..8] |
|
806 | 806 | |
|
807 | 807 | url, url_title = check_refs( url ) |
|
808 | 808 | title ||= url_title |
|
809 | 809 | |
|
810 | 810 | # Idea below : an URL with unbalanced parethesis and |
|
811 | 811 | # ending by ')' is put into external parenthesis |
|
812 | 812 | if ( url[-1]==?) and ((url.count("(") - url.count(")")) < 0 ) ) |
|
813 | 813 | url=url[0..-2] # discard closing parenth from url |
|
814 | 814 | post = ")"+post # add closing parenth to post |
|
815 | 815 | end |
|
816 | 816 | atts = pba( atts ) |
|
817 | 817 | atts = " href=\"#{ url }#{ slash }\"#{ atts }" |
|
818 | 818 | atts << " title=\"#{ htmlesc title }\"" if title |
|
819 | 819 | atts = shelve( atts ) if atts |
|
820 | 820 | |
|
821 | 821 | external = (url =~ /^https?:\/\//) ? ' class="external"' : '' |
|
822 | 822 | |
|
823 | 823 | "#{ pre }<a#{ atts }#{ external }>#{ text }</a>#{ post }" |
|
824 | 824 | end |
|
825 | 825 | end |
|
826 | 826 | |
|
827 | 827 | MARKDOWN_REFLINK_RE = / |
|
828 | 828 | \[([^\[\]]+)\] # $text |
|
829 | 829 | [ ]? # opt. space |
|
830 | 830 | (?:\n[ ]*)? # one optional newline followed by spaces |
|
831 | 831 | \[(.*?)\] # $id |
|
832 | 832 | /x |
|
833 | 833 | |
|
834 | 834 | def inline_markdown_reflink( text ) |
|
835 | 835 | text.gsub!( MARKDOWN_REFLINK_RE ) do |m| |
|
836 | 836 | text, id = $~[1..2] |
|
837 | 837 | |
|
838 | 838 | if id.empty? |
|
839 | 839 | url, title = check_refs( text ) |
|
840 | 840 | else |
|
841 | 841 | url, title = check_refs( id ) |
|
842 | 842 | end |
|
843 | 843 | |
|
844 | 844 | atts = " href=\"#{ url }\"" |
|
845 | 845 | atts << " title=\"#{ title }\"" if title |
|
846 | 846 | atts = shelve( atts ) |
|
847 | 847 | |
|
848 | 848 | "<a#{ atts }>#{ text }</a>" |
|
849 | 849 | end |
|
850 | 850 | end |
|
851 | 851 | |
|
852 | 852 | MARKDOWN_LINK_RE = / |
|
853 | 853 | \[([^\[\]]+)\] # $text |
|
854 | 854 | \( # open paren |
|
855 | 855 | [ \t]* # opt space |
|
856 | 856 | <?(.+?)>? # $href |
|
857 | 857 | [ \t]* # opt space |
|
858 | 858 | (?: # whole title |
|
859 | 859 | (['"]) # $quote |
|
860 | 860 | (.*?) # $title |
|
861 | 861 | \3 # matching quote |
|
862 | 862 | )? # title is optional |
|
863 | 863 | \) |
|
864 | 864 | /x |
|
865 | 865 | |
|
866 | 866 | def inline_markdown_link( text ) |
|
867 | 867 | text.gsub!( MARKDOWN_LINK_RE ) do |m| |
|
868 | 868 | text, url, quote, title = $~[1..4] |
|
869 | 869 | |
|
870 | 870 | atts = " href=\"#{ url }\"" |
|
871 | 871 | atts << " title=\"#{ title }\"" if title |
|
872 | 872 | atts = shelve( atts ) |
|
873 | 873 | |
|
874 | 874 | "<a#{ atts }>#{ text }</a>" |
|
875 | 875 | end |
|
876 | 876 | end |
|
877 | 877 | |
|
878 | 878 | TEXTILE_REFS_RE = /(^ *)\[([^\[\n]+?)\](#{HYPERLINK})(?=\s|$)/ |
|
879 | 879 | MARKDOWN_REFS_RE = /(^ *)\[([^\n]+?)\]:\s+<?(#{HYPERLINK})>?(?:\s+"((?:[^"]|\\")+)")?(?=\s|$)/m |
|
880 | 880 | |
|
881 | 881 | def refs( text ) |
|
882 | 882 | @rules.each do |rule_name| |
|
883 | 883 | method( rule_name ).call( text ) if rule_name.to_s.match /^refs_/ |
|
884 | 884 | end |
|
885 | 885 | end |
|
886 | 886 | |
|
887 | 887 | def refs_textile( text ) |
|
888 | 888 | text.gsub!( TEXTILE_REFS_RE ) do |m| |
|
889 | 889 | flag, url = $~[2..3] |
|
890 | 890 | @urlrefs[flag.downcase] = [url, nil] |
|
891 | 891 | nil |
|
892 | 892 | end |
|
893 | 893 | end |
|
894 | 894 | |
|
895 | 895 | def refs_markdown( text ) |
|
896 | 896 | text.gsub!( MARKDOWN_REFS_RE ) do |m| |
|
897 | 897 | flag, url = $~[2..3] |
|
898 | 898 | title = $~[6] |
|
899 | 899 | @urlrefs[flag.downcase] = [url, title] |
|
900 | 900 | nil |
|
901 | 901 | end |
|
902 | 902 | end |
|
903 | 903 | |
|
904 | 904 | def check_refs( text ) |
|
905 | 905 | ret = @urlrefs[text.downcase] if text |
|
906 | 906 | ret || [text, nil] |
|
907 | 907 | end |
|
908 | 908 | |
|
909 | 909 | IMAGE_RE = / |
|
910 | 910 | (<p>|.|^) # start of line? |
|
911 | 911 | \! # opening |
|
912 | 912 | (\<|\=|\>)? # optional alignment atts |
|
913 | 913 | (#{C}) # optional style,class atts |
|
914 | 914 | (?:\. )? # optional dot-space |
|
915 | 915 | ([^\s(!]+?) # presume this is the src |
|
916 | 916 | \s? # optional space |
|
917 | 917 | (?:\(((?:[^\(\)]|\([^\)]+\))+?)\))? # optional title |
|
918 | 918 | \! # closing |
|
919 | 919 | (?::#{ HYPERLINK })? # optional href |
|
920 | 920 | /x |
|
921 | 921 | |
|
922 | 922 | def inline_textile_image( text ) |
|
923 | 923 | text.gsub!( IMAGE_RE ) do |m| |
|
924 | 924 | stln,algn,atts,url,title,href,href_a1,href_a2 = $~[1..8] |
|
925 | 925 | htmlesc title |
|
926 | 926 | atts = pba( atts ) |
|
927 | 927 | atts = " src=\"#{ url }\"#{ atts }" |
|
928 | 928 | atts << " title=\"#{ title }\"" if title |
|
929 | 929 | atts << " alt=\"#{ title }\"" |
|
930 | 930 | # size = @getimagesize($url); |
|
931 | 931 | # if($size) $atts.= " $size[3]"; |
|
932 | 932 | |
|
933 | 933 | href, alt_title = check_refs( href ) if href |
|
934 | 934 | url, url_title = check_refs( url ) |
|
935 | 935 | |
|
936 | 936 | out = '' |
|
937 | 937 | out << "<a#{ shelve( " href=\"#{ href }\"" ) }>" if href |
|
938 | 938 | out << "<img#{ shelve( atts ) } />" |
|
939 | 939 | out << "</a>#{ href_a1 }#{ href_a2 }" if href |
|
940 | 940 | |
|
941 | 941 | if algn |
|
942 | 942 | algn = h_align( algn ) |
|
943 | 943 | if stln == "<p>" |
|
944 | 944 | out = "<p style=\"float:#{ algn }\">#{ out }" |
|
945 | 945 | else |
|
946 | 946 | out = "#{ stln }<div style=\"float:#{ algn }\">#{ out }</div>" |
|
947 | 947 | end |
|
948 | 948 | else |
|
949 | 949 | out = stln + out |
|
950 | 950 | end |
|
951 | 951 | |
|
952 | 952 | out |
|
953 | 953 | end |
|
954 | 954 | end |
|
955 | 955 | |
|
956 | 956 | def shelve( val ) |
|
957 | 957 | @shelf << val |
|
958 | 958 | " :redsh##{ @shelf.length }:" |
|
959 | 959 | end |
|
960 | 960 | |
|
961 | 961 | def retrieve( text ) |
|
962 | 962 | @shelf.each_with_index do |r, i| |
|
963 | 963 | text.gsub!( " :redsh##{ i + 1 }:", r ) |
|
964 | 964 | end |
|
965 | 965 | end |
|
966 | 966 | |
|
967 | 967 | def incoming_entities( text ) |
|
968 | 968 | ## turn any incoming ampersands into a dummy character for now. |
|
969 | 969 | ## This uses a negative lookahead for alphanumerics followed by a semicolon, |
|
970 | 970 | ## implying an incoming html entity, to be skipped |
|
971 | 971 | |
|
972 | 972 | text.gsub!( /&(?![#a-z0-9]+;)/i, "x%x%" ) |
|
973 | 973 | end |
|
974 | 974 | |
|
975 | 975 | def no_textile( text ) |
|
976 | 976 | text.gsub!( /(^|\s)==([^=]+.*?)==(\s|$)?/, |
|
977 | 977 | '\1<notextile>\2</notextile>\3' ) |
|
978 | 978 | text.gsub!( /^ *==([^=]+.*?)==/m, |
|
979 | 979 | '\1<notextile>\2</notextile>\3' ) |
|
980 | 980 | end |
|
981 | 981 | |
|
982 | 982 | def clean_white_space( text ) |
|
983 | 983 | # normalize line breaks |
|
984 | 984 | text.gsub!( /\r\n/, "\n" ) |
|
985 | 985 | text.gsub!( /\r/, "\n" ) |
|
986 | 986 | text.gsub!( /\t/, ' ' ) |
|
987 | 987 | text.gsub!( /^ +$/, '' ) |
|
988 | 988 | text.gsub!( /\n{3,}/, "\n\n" ) |
|
989 | 989 | text.gsub!( /"$/, "\" " ) |
|
990 | 990 | |
|
991 | 991 | # if entire document is indented, flush |
|
992 | 992 | # to the left side |
|
993 | 993 | flush_left text |
|
994 | 994 | end |
|
995 | 995 | |
|
996 | 996 | def flush_left( text ) |
|
997 | 997 | indt = 0 |
|
998 | 998 | if text =~ /^ / |
|
999 | 999 | while text !~ /^ {#{indt}}\S/ |
|
1000 | 1000 | indt += 1 |
|
1001 | 1001 | end unless text.empty? |
|
1002 | 1002 | if indt.nonzero? |
|
1003 | 1003 | text.gsub!( /^ {#{indt}}/, '' ) |
|
1004 | 1004 | end |
|
1005 | 1005 | end |
|
1006 | 1006 | end |
|
1007 | 1007 | |
|
1008 | 1008 | def footnote_ref( text ) |
|
1009 | 1009 | text.gsub!( /\b\[([0-9]+?)\](\s)?/, |
|
1010 | 1010 | '<sup><a href="#fn\1">\1</a></sup>\2' ) |
|
1011 | 1011 | end |
|
1012 | 1012 | |
|
1013 | 1013 | OFFTAGS = /(code|pre|kbd|notextile)/ |
|
1014 | 1014 | OFFTAG_MATCH = /(?:(<\/#{ OFFTAGS }>)|(<#{ OFFTAGS }[^>]*>))(.*?)(?=<\/?#{ OFFTAGS }|\Z)/mi |
|
1015 | 1015 | OFFTAG_OPEN = /<#{ OFFTAGS }/ |
|
1016 | 1016 | OFFTAG_CLOSE = /<\/?#{ OFFTAGS }/ |
|
1017 | 1017 | HASTAG_MATCH = /(<\/?\w[^\n]*?>)/m |
|
1018 | 1018 | ALLTAG_MATCH = /(<\/?\w[^\n]*?>)|.*?(?=<\/?\w[^\n]*?>|$)/m |
|
1019 | 1019 | |
|
1020 | 1020 | def glyphs_textile( text, level = 0 ) |
|
1021 | 1021 | if text !~ HASTAG_MATCH |
|
1022 | 1022 | pgl text |
|
1023 | 1023 | footnote_ref text |
|
1024 | 1024 | else |
|
1025 | 1025 | codepre = 0 |
|
1026 | 1026 | text.gsub!( ALLTAG_MATCH ) do |line| |
|
1027 | 1027 | ## matches are off if we're between <code>, <pre> etc. |
|
1028 | 1028 | if $1 |
|
1029 | 1029 | if line =~ OFFTAG_OPEN |
|
1030 | 1030 | codepre += 1 |
|
1031 | 1031 | elsif line =~ OFFTAG_CLOSE |
|
1032 | 1032 | codepre -= 1 |
|
1033 | 1033 | codepre = 0 if codepre < 0 |
|
1034 | 1034 | end |
|
1035 | 1035 | elsif codepre.zero? |
|
1036 | 1036 | glyphs_textile( line, level + 1 ) |
|
1037 | 1037 | else |
|
1038 | 1038 | htmlesc( line, :NoQuotes ) |
|
1039 | 1039 | end |
|
1040 | 1040 | # p [level, codepre, line] |
|
1041 | 1041 | |
|
1042 | 1042 | line |
|
1043 | 1043 | end |
|
1044 | 1044 | end |
|
1045 | 1045 | end |
|
1046 | 1046 | |
|
1047 | 1047 | def rip_offtags( text ) |
|
1048 | 1048 | if text =~ /<.*>/ |
|
1049 | 1049 | ## strip and encode <pre> content |
|
1050 | 1050 | codepre, used_offtags = 0, {} |
|
1051 | 1051 | text.gsub!( OFFTAG_MATCH ) do |line| |
|
1052 | 1052 | if $3 |
|
1053 | 1053 | offtag, aftertag = $4, $5 |
|
1054 | 1054 | codepre += 1 |
|
1055 | 1055 | used_offtags[offtag] = true |
|
1056 | 1056 | if codepre - used_offtags.length > 0 |
|
1057 | 1057 | htmlesc( line, :NoQuotes ) |
|
1058 | 1058 | @pre_list.last << line |
|
1059 | 1059 | line = "" |
|
1060 | 1060 | else |
|
1061 | 1061 | htmlesc( aftertag, :NoQuotes ) if aftertag |
|
1062 | 1062 | line = "<redpre##{ @pre_list.length }>" |
|
1063 | 1063 | $3.match(/<#{ OFFTAGS }([^>]*)>/) |
|
1064 | 1064 | tag = $1 |
|
1065 | 1065 | $2.to_s.match(/(class\=\S+)/i) |
|
1066 | 1066 | tag << " #{$1}" if $1 |
|
1067 | 1067 | @pre_list << "<#{ tag }>#{ aftertag }" |
|
1068 | 1068 | end |
|
1069 | 1069 | elsif $1 and codepre > 0 |
|
1070 | 1070 | if codepre - used_offtags.length > 0 |
|
1071 | 1071 | htmlesc( line, :NoQuotes ) |
|
1072 | 1072 | @pre_list.last << line |
|
1073 | 1073 | line = "" |
|
1074 | 1074 | end |
|
1075 | 1075 | codepre -= 1 unless codepre.zero? |
|
1076 | 1076 | used_offtags = {} if codepre.zero? |
|
1077 | 1077 | end |
|
1078 | 1078 | line |
|
1079 | 1079 | end |
|
1080 | 1080 | end |
|
1081 | 1081 | text |
|
1082 | 1082 | end |
|
1083 | 1083 | |
|
1084 | 1084 | def smooth_offtags( text ) |
|
1085 | 1085 | unless @pre_list.empty? |
|
1086 | 1086 | ## replace <pre> content |
|
1087 | 1087 | text.gsub!( /<redpre#(\d+)>/ ) { @pre_list[$1.to_i] } |
|
1088 | 1088 | end |
|
1089 | 1089 | end |
|
1090 | 1090 | |
|
1091 | 1091 | def inline( text ) |
|
1092 | 1092 | [/^inline_/, /^glyphs_/].each do |meth_re| |
|
1093 | 1093 | @rules.each do |rule_name| |
|
1094 | 1094 | method( rule_name ).call( text ) if rule_name.to_s.match( meth_re ) |
|
1095 | 1095 | end |
|
1096 | 1096 | end |
|
1097 | 1097 | end |
|
1098 | 1098 | |
|
1099 | 1099 | def h_align( text ) |
|
1100 | 1100 | H_ALGN_VALS[text] |
|
1101 | 1101 | end |
|
1102 | 1102 | |
|
1103 | 1103 | def v_align( text ) |
|
1104 | 1104 | V_ALGN_VALS[text] |
|
1105 | 1105 | end |
|
1106 | 1106 | |
|
1107 | 1107 | def textile_popup_help( name, windowW, windowH ) |
|
1108 | 1108 | ' <a target="_blank" href="http://hobix.com/textile/#' + helpvar + '" onclick="window.open(this.href, \'popupwindow\', \'width=' + windowW + ',height=' + windowH + ',scrollbars,resizable\'); return false;">' + name + '</a><br />' |
|
1109 | 1109 | end |
|
1110 | 1110 | |
|
1111 | 1111 | # HTML cleansing stuff |
|
1112 | 1112 | BASIC_TAGS = { |
|
1113 | 1113 | 'a' => ['href', 'title'], |
|
1114 | 1114 | 'img' => ['src', 'alt', 'title'], |
|
1115 | 1115 | 'br' => [], |
|
1116 | 1116 | 'i' => nil, |
|
1117 | 1117 | 'u' => nil, |
|
1118 | 1118 | 'b' => nil, |
|
1119 | 1119 | 'pre' => nil, |
|
1120 | 1120 | 'kbd' => nil, |
|
1121 | 1121 | 'code' => ['lang'], |
|
1122 | 1122 | 'cite' => nil, |
|
1123 | 1123 | 'strong' => nil, |
|
1124 | 1124 | 'em' => nil, |
|
1125 | 1125 | 'ins' => nil, |
|
1126 | 1126 | 'sup' => nil, |
|
1127 | 1127 | 'sub' => nil, |
|
1128 | 1128 | 'del' => nil, |
|
1129 | 1129 | 'table' => nil, |
|
1130 | 1130 | 'tr' => nil, |
|
1131 | 1131 | 'td' => ['colspan', 'rowspan'], |
|
1132 | 1132 | 'th' => nil, |
|
1133 | 1133 | 'ol' => nil, |
|
1134 | 1134 | 'ul' => nil, |
|
1135 | 1135 | 'li' => nil, |
|
1136 | 1136 | 'p' => nil, |
|
1137 | 1137 | 'h1' => nil, |
|
1138 | 1138 | 'h2' => nil, |
|
1139 | 1139 | 'h3' => nil, |
|
1140 | 1140 | 'h4' => nil, |
|
1141 | 1141 | 'h5' => nil, |
|
1142 | 1142 | 'h6' => nil, |
|
1143 | 1143 | 'blockquote' => ['cite'] |
|
1144 | 1144 | } |
|
1145 | 1145 | |
|
1146 | 1146 | def clean_html( text, tags = BASIC_TAGS ) |
|
1147 | 1147 | text.gsub!( /<!\[CDATA\[/, '' ) |
|
1148 | 1148 | text.gsub!( /<(\/*)(\w+)([^>]*)>/ ) do |
|
1149 | 1149 | raw = $~ |
|
1150 | 1150 | tag = raw[2].downcase |
|
1151 | 1151 | if tags.has_key? tag |
|
1152 | 1152 | pcs = [tag] |
|
1153 | 1153 | tags[tag].each do |prop| |
|
1154 | 1154 | ['"', "'", ''].each do |q| |
|
1155 | 1155 | q2 = ( q != '' ? q : '\s' ) |
|
1156 | 1156 | if raw[3] =~ /#{prop}\s*=\s*#{q}([^#{q2}]+)#{q}/i |
|
1157 | 1157 | attrv = $1 |
|
1158 | 1158 | next if prop == 'src' and attrv =~ %r{^(?!http)\w+:} |
|
1159 | 1159 | pcs << "#{prop}=\"#{$1.gsub('"', '\\"')}\"" |
|
1160 | 1160 | break |
|
1161 | 1161 | end |
|
1162 | 1162 | end |
|
1163 | 1163 | end if tags[tag] |
|
1164 | 1164 | "<#{raw[1]}#{pcs.join " "}>" |
|
1165 | 1165 | else |
|
1166 | 1166 | " " |
|
1167 | 1167 | end |
|
1168 | 1168 | end |
|
1169 | 1169 | end |
|
1170 | 1170 | |
|
1171 | 1171 | ALLOWED_TAGS = %w(redpre pre code notextile) |
|
1172 | 1172 | |
|
1173 | 1173 | def escape_html_tags(text) |
|
1174 | 1174 | text.gsub!(%r{<(\/?([!\w]+)[^<>\n]*)(>?)}) {|m| ALLOWED_TAGS.include?($2) ? "<#{$1}#{$3}" : "<#{$1}#{'>' unless $3.blank?}" } |
|
1175 | 1175 | end |
|
1176 | 1176 | end |
|
1177 | 1177 |
@@ -1,247 +1,247 | |||
|
1 | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
|
2 | 2 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> |
|
3 | 3 | <head> |
|
4 | 4 | <title>RedmineWikiFormatting</title> |
|
5 | 5 | <meta http-equiv="content-type" content="text/html; charset=utf-8" /> |
|
6 | 6 | <style type="text/css"> |
|
7 | 7 | body { font:80% Verdana,Tahoma,Arial,sans-serif; } |
|
8 | 8 | h1, h2, h3, h4 { font-family: Trebuchet MS,Georgia,"Times New Roman",serif; } |
|
9 | 9 | pre, code { font-size:120%; } |
|
10 | 10 | pre code { font-size:100%; } |
|
11 | 11 | pre { |
|
12 | 12 | margin: 1em 1em 1em 1.6em; |
|
13 | 13 | padding: 2px; |
|
14 | 14 | background-color: #fafafa; |
|
15 | 15 | border: 1px solid #dadada; |
|
16 | 16 | width:95%; |
|
17 | 17 | overflow-x: auto; |
|
18 | 18 | } |
|
19 | 19 | a.new { color: #b73535; } |
|
20 | 20 | |
|
21 | 21 | .CodeRay .c { color:#666; } |
|
22 | 22 | |
|
23 | 23 | .CodeRay .cl { color:#B06; font-weight:bold } |
|
24 | 24 | .CodeRay .dl { color:black } |
|
25 | 25 | .CodeRay .fu { color:#06B; font-weight:bold } |
|
26 | 26 | |
|
27 | 27 | .CodeRay .il { background: #eee } |
|
28 | 28 | .CodeRay .il .idl { font-weight: bold; color: #888 } |
|
29 | 29 | |
|
30 | 30 | .CodeRay .iv { color:#33B } |
|
31 | 31 | .CodeRay .r { color:#080; font-weight:bold } |
|
32 | 32 | |
|
33 | 33 | .CodeRay .s { background-color:#fff0f0 } |
|
34 | 34 | .CodeRay .s .dl { color:#710 } |
|
35 | 35 | </style> |
|
36 | 36 | </head> |
|
37 | 37 | |
|
38 | 38 | <body> |
|
39 | 39 | <h1><a name="1" class="wiki-page"></a>Wiki formatting</h1> |
|
40 | 40 | |
|
41 | 41 | <h2><a name="2" class="wiki-page"></a>Links</h2> |
|
42 | 42 | |
|
43 | 43 | <h3><a name="3" class="wiki-page"></a>Redmine links</h3> |
|
44 | 44 | |
|
45 | 45 | <p>Redmine allows hyperlinking between issues, changesets and wiki pages from anywhere wiki formatting is used.</p> |
|
46 | 46 | <ul> |
|
47 | 47 | <li>Link to an issue: <strong>#124</strong> (displays <del><a href="/issues/show/124" class="issue" title="bulk edit doesn't change the category or fixed version properties (Closed)">#124</a></del>, link is striked-through if the issue is closed)</li> |
|
48 | 48 | <li>Link to a changeset: <strong>r758</strong> (displays <a href="/repositories/revision/1?rev=758" class="changeset" title="Search engine now only searches objects the user is allowed to view.">r758</a>)</li> |
|
49 | 49 | <li>Link to a changeset with a non-numeric hash: <strong>commit:c6f4d0fd</strong> (displays c6f4d0fd). Added in <a href="/repositories/revision/1?rev=1236" class="changeset" title="Merged Git support branch (r1200 to r1226).">r1236</a>.</li> |
|
50 | 50 | </ul> |
|
51 | 51 | |
|
52 | 52 | <p>Wiki links:</p> |
|
53 | 53 | |
|
54 | 54 | <ul> |
|
55 | 55 | <li><strong>[[Guide]]</strong> displays a link to the page named 'Guide': <a href="Guide.html" class="wiki-page">Guide</a></li> |
|
56 | 56 | <li><strong>[[Guide#further-reading]]</strong> takes you to the anchor "further-reading". Headings get automatically assigned anchors so that you can refer to them: <a href="Guide.html#further-reading" class="wiki-page">Guide</a></li> |
|
57 | 57 | <li><strong>[[Guide|User manual]]</strong> displays a link to the same page but with a different text: <a href="Guide.html" class="wiki-page">User manual</a></li> |
|
58 | 58 | </ul> |
|
59 | 59 | |
|
60 | 60 | <p>You can also link to pages of an other project wiki:</p> |
|
61 | 61 | |
|
62 | 62 | <ul> |
|
63 | 63 | <li><strong>[[sandbox:some page]]</strong> displays a link to the page named 'Some page' of the Sandbox wiki</li> |
|
64 | <li><strong>[[sandbox]]</strong> displays a link to the Sandbox wiki main page</li> | |
|
64 | <li><strong>[[sandbox:]]</strong> displays a link to the Sandbox wiki main page</li> | |
|
65 | 65 | </ul> |
|
66 | 66 | |
|
67 | 67 | <p>Wiki links are displayed in red if the page doesn't exist yet, eg: <a href="Nonexistent_page.html" class="wiki-page new">Nonexistent page</a>.</p> |
|
68 | 68 | |
|
69 | 69 | <p>Links to others resources (0.7):</p> |
|
70 | 70 | |
|
71 | 71 | <ul> |
|
72 | 72 | <li>Documents: |
|
73 | 73 | <ul> |
|
74 | 74 | <li><strong>document#17</strong> (link to document with id 17)</li> |
|
75 | 75 | <li><strong>document:Greetings</strong> (link to the document with title "Greetings")</li> |
|
76 | 76 | <li><strong>document:"Some document"</strong> (double quotes can be used when document title contains spaces)</li> |
|
77 | 77 | </ul></li> |
|
78 | 78 | </ul> |
|
79 | 79 | |
|
80 | 80 | <ul> |
|
81 | 81 | <li>Versions: |
|
82 | 82 | <ul> |
|
83 | 83 | <li><strong>version#3</strong> (link to version with id 3)</li> |
|
84 | 84 | <li><strong>version:1.0.0</strong> (link to version named "1.0.0")</li> |
|
85 | 85 | <li><strong>version:"1.0 beta 2"</strong></li> |
|
86 | 86 | </ul></li> |
|
87 | 87 | </ul> |
|
88 | 88 | |
|
89 | 89 | <ul> |
|
90 | 90 | <li>Attachments: |
|
91 | 91 | <ul> |
|
92 | 92 | <li><strong>attachment:file.zip</strong> (link to the attachment of the current object named file.zip)</li> |
|
93 | 93 | <li>For now, attachments of the current object can be referenced only (if you're on an issue, it's possible to reference attachments of this issue only)</li> |
|
94 | 94 | </ul></li> |
|
95 | 95 | </ul> |
|
96 | 96 | |
|
97 | 97 | <ul> |
|
98 | 98 | <li>Repository files |
|
99 | 99 | <ul> |
|
100 | 100 | <li><strong>source:some/file</strong> -- Link to the file located at /some/file in the project's repository</li> |
|
101 | 101 | <li><strong>source:some/file@52</strong> -- Link to the file's revision 52</li> |
|
102 | 102 | <li><strong>source:some/file#L120</strong> -- Link to line 120 of the file</li> |
|
103 | 103 | <li><strong>source:some/file@52#L120</strong> -- Link to line 120 of the file's revision 52</li> |
|
104 | 104 | <li><strong>export:some/file</strong> -- Force the download of the file</li> |
|
105 | 105 | </ul></li> |
|
106 | 106 | </ul> |
|
107 | 107 | |
|
108 | 108 | <p>Escaping (0.7):</p> |
|
109 | 109 | |
|
110 | 110 | <ul> |
|
111 | 111 | <li>You can prevent Redmine links from being parsed by preceding them with an exclamation mark: !</li> |
|
112 | 112 | </ul> |
|
113 | 113 | |
|
114 | 114 | |
|
115 | 115 | <h3><a name="4" class="wiki-page"></a>External links</h3> |
|
116 | 116 | |
|
117 | 117 | <p>HTTP URLs and email addresses are automatically turned into clickable links:</p> |
|
118 | 118 | |
|
119 | 119 | <pre> |
|
120 | 120 | http://www.redmine.org, someone@foo.bar |
|
121 | 121 | </pre> |
|
122 | 122 | |
|
123 | 123 | <p>displays: <a class="external" href="http://www.redmine.org">http://www.redmine.org</a>, <a href="mailto:someone@foo.bar" class="email">someone@foo.bar</a></p> |
|
124 | 124 | |
|
125 | 125 | <p>If you want to display a specific text instead of the URL, you can use the standard textile syntax:</p> |
|
126 | 126 | |
|
127 | 127 | <pre> |
|
128 | 128 | "Redmine web site":http://www.redmine.org |
|
129 | 129 | </pre> |
|
130 | 130 | |
|
131 | 131 | <p>displays: <a href="http://www.redmine.org" class="external">Redmine web site</a></p> |
|
132 | 132 | |
|
133 | 133 | |
|
134 | 134 | <h2><a name="5" class="wiki-page"></a>Text formatting</h2> |
|
135 | 135 | |
|
136 | 136 | |
|
137 | 137 | <p>For things such as headlines, bold, tables, lists, Redmine supports Textile syntax. See <a class="external" href="http://hobix.com/textile/">http://hobix.com/textile/</a> for information on using any of these features. A few samples are included below, but the engine is capable of much more of that.</p> |
|
138 | 138 | |
|
139 | 139 | <h3><a name="6" class="wiki-page"></a>Font style</h3> |
|
140 | 140 | |
|
141 | 141 | <pre> |
|
142 | 142 | * *bold* |
|
143 | 143 | * _italic_ |
|
144 | 144 | * _*bold italic*_ |
|
145 | 145 | * +underline+ |
|
146 | 146 | * -strike-through- |
|
147 | 147 | </pre> |
|
148 | 148 | |
|
149 | 149 | <p>Display:</p> |
|
150 | 150 | |
|
151 | 151 | <ul> |
|
152 | 152 | <li><strong>bold</strong></li> |
|
153 | 153 | <li><em>italic</em></li> |
|
154 | 154 | <li><em>*bold italic*</em></li> |
|
155 | 155 | <li><ins>underline</ins></li> |
|
156 | 156 | <li><del>strike-through</del></li> |
|
157 | 157 | </ul> |
|
158 | 158 | |
|
159 | 159 | <h3><a name="7" class="wiki-page"></a>Inline images</h3> |
|
160 | 160 | |
|
161 | 161 | <ul> |
|
162 | 162 | <li><strong>!image_url!</strong> displays an image located at image_url (textile syntax)</li> |
|
163 | 163 | <li><strong>!>image_url!</strong> right floating image</li> |
|
164 | 164 | <li>If you have an image attached to your wiki page, it can be displayed inline using its filename: <strong>!attached_image.png!</strong></li> |
|
165 | 165 | </ul> |
|
166 | 166 | |
|
167 | 167 | <h3><a name="8" class="wiki-page"></a>Headings</h3> |
|
168 | 168 | |
|
169 | 169 | <pre> |
|
170 | 170 | h1. Heading |
|
171 | 171 | h2. Subheading |
|
172 | 172 | h3. Subsubheading |
|
173 | 173 | </pre> |
|
174 | 174 | |
|
175 | 175 | <p>Redmine assigns an anchor to each of those headings thus you can link to them with "#Heading", "#Subheading" and so forth.</p> |
|
176 | 176 | |
|
177 | 177 | |
|
178 | 178 | <h3><a name="9" class="wiki-page"></a>Paragraphs</h3> |
|
179 | 179 | |
|
180 | 180 | <pre> |
|
181 | 181 | p>. right aligned |
|
182 | 182 | p=. centered |
|
183 | 183 | </pre> |
|
184 | 184 | |
|
185 | 185 | <p style="text-align:center;">This is centered paragraph.</p> |
|
186 | 186 | |
|
187 | 187 | |
|
188 | 188 | <h3><a name="10" class="wiki-page"></a>Blockquotes</h3> |
|
189 | 189 | |
|
190 | 190 | <p>Start the paragraph with <strong>bq.</strong></p> |
|
191 | 191 | |
|
192 | 192 | <pre> |
|
193 | 193 | bq. Rails is a full-stack framework for developing database-backed web applications according to the Model-View-Control pattern. |
|
194 | 194 | To go live, all you need to add is a database and a web server. |
|
195 | 195 | </pre> |
|
196 | 196 | |
|
197 | 197 | <p>Display:</p> |
|
198 | 198 | |
|
199 | 199 | <blockquote> |
|
200 | 200 | <p>Rails is a full-stack framework for developing database-backed web applications according to the Model-View-Control pattern.<br />To go live, all you need to add is a database and a web server.</p> |
|
201 | 201 | </blockquote> |
|
202 | 202 | |
|
203 | 203 | |
|
204 | 204 | <h3><a name="11" class="wiki-page"></a>Table of content</h3> |
|
205 | 205 | |
|
206 | 206 | <pre> |
|
207 | 207 | {{toc}} => left aligned toc |
|
208 | 208 | {{>toc}} => right aligned toc |
|
209 | 209 | </pre> |
|
210 | 210 | |
|
211 | 211 | <h2><a name="12" class="wiki-page"></a>Macros</h2> |
|
212 | 212 | |
|
213 | 213 | <p>Redmine has the following builtin macros:</p> |
|
214 | 214 | |
|
215 | 215 | <p><dl><dt><code>hello_world</code></dt><dd><p>Sample macro.</p></dd><dt><code>include</code></dt><dd><p>Include a wiki page. Example:</p> |
|
216 | 216 | |
|
217 | 217 | <pre><code>{{include(Foo)}}</code></pre></dd><dt><code>macro_list</code></dt><dd><p>Displays a list of all available macros, including description if available.</p></dd></dl></p> |
|
218 | 218 | |
|
219 | 219 | |
|
220 | 220 | <h2><a name="13" class="wiki-page"></a>Code highlighting</h2> |
|
221 | 221 | |
|
222 | 222 | <p>Code highlightment relies on <a href="http://coderay.rubychan.de/" class="external">CodeRay</a>, a fast syntax highlighting library written completely in Ruby. It currently supports c, html, javascript, rhtml, ruby, scheme, xml languages.</p> |
|
223 | 223 | |
|
224 | 224 | <p>You can highlight code in your wiki page using this syntax:</p> |
|
225 | 225 | |
|
226 | 226 | <pre> |
|
227 | 227 | <pre><code class="ruby"> |
|
228 | 228 | Place you code here. |
|
229 | 229 | </code></pre> |
|
230 | 230 | </pre> |
|
231 | 231 | |
|
232 | 232 | <p>Example:</p> |
|
233 | 233 | |
|
234 | 234 | <pre><code class="ruby CodeRay"><span class="no"> 1</span> <span class="c"># The Greeter class</span> |
|
235 | 235 | <span class="no"> 2</span> <span class="r">class</span> <span class="cl">Greeter</span> |
|
236 | 236 | <span class="no"> 3</span> <span class="r">def</span> <span class="fu">initialize</span>(name) |
|
237 | 237 | <span class="no"> 4</span> <span class="iv">@name</span> = name.capitalize |
|
238 | 238 | <span class="no"> 5</span> <span class="r">end</span> |
|
239 | 239 | <span class="no"> 6</span> |
|
240 | 240 | <span class="no"> 7</span> <span class="r">def</span> <span class="fu">salute</span> |
|
241 | 241 | <span class="no"> 8</span> puts <span class="s"><span class="dl">"</span><span class="k">Hello </span><span class="il"><span class="idl">#{</span><span class="iv">@name</span><span class="idl">}</span></span><span class="k">!</span><span class="dl">"</span></span> |
|
242 | 242 | <span class="no"> 9</span> <span class="r">end</span> |
|
243 | 243 | <span class="no"><strong>10</strong></span> <span class="r">end</span> |
|
244 | 244 | </code> |
|
245 | 245 | </pre> |
|
246 | 246 | </body> |
|
247 | 247 | </html> |
@@ -1,447 +1,449 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.dirname(__FILE__) + '/../../test_helper' |
|
19 | 19 | |
|
20 | 20 | class ApplicationHelperTest < HelperTestCase |
|
21 | 21 | include ApplicationHelper |
|
22 | 22 | include ActionView::Helpers::TextHelper |
|
23 | 23 | fixtures :projects, :roles, :enabled_modules, :users, |
|
24 | 24 | :repositories, :changesets, |
|
25 | 25 | :trackers, :issue_statuses, :issues, :versions, :documents, |
|
26 | 26 | :wikis, :wiki_pages, :wiki_contents, |
|
27 | 27 | :boards, :messages, |
|
28 | 28 | :attachments |
|
29 | 29 | |
|
30 | 30 | def setup |
|
31 | 31 | super |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | def test_auto_links |
|
35 | 35 | to_test = { |
|
36 | 36 | 'http://foo.bar' => '<a class="external" href="http://foo.bar">http://foo.bar</a>', |
|
37 | 37 | 'http://foo.bar/~user' => '<a class="external" href="http://foo.bar/~user">http://foo.bar/~user</a>', |
|
38 | 38 | 'http://foo.bar.' => '<a class="external" href="http://foo.bar">http://foo.bar</a>.', |
|
39 | 39 | 'https://foo.bar.' => '<a class="external" href="https://foo.bar">https://foo.bar</a>.', |
|
40 | 40 | 'This is a link: http://foo.bar.' => 'This is a link: <a class="external" href="http://foo.bar">http://foo.bar</a>.', |
|
41 | 41 | 'A link (eg. http://foo.bar).' => 'A link (eg. <a class="external" href="http://foo.bar">http://foo.bar</a>).', |
|
42 | 42 | 'http://foo.bar/foo.bar#foo.bar.' => '<a class="external" href="http://foo.bar/foo.bar#foo.bar">http://foo.bar/foo.bar#foo.bar</a>.', |
|
43 | 43 | 'http://www.foo.bar/Test_(foobar)' => '<a class="external" href="http://www.foo.bar/Test_(foobar)">http://www.foo.bar/Test_(foobar)</a>', |
|
44 | 44 | '(see inline link : http://www.foo.bar/Test_(foobar))' => '(see inline link : <a class="external" href="http://www.foo.bar/Test_(foobar)">http://www.foo.bar/Test_(foobar)</a>)', |
|
45 | 45 | '(see inline link : http://www.foo.bar/Test)' => '(see inline link : <a class="external" href="http://www.foo.bar/Test">http://www.foo.bar/Test</a>)', |
|
46 | 46 | '(see inline link : http://www.foo.bar/Test).' => '(see inline link : <a class="external" href="http://www.foo.bar/Test">http://www.foo.bar/Test</a>).', |
|
47 | 47 | '(see "inline link":http://www.foo.bar/Test_(foobar))' => '(see <a href="http://www.foo.bar/Test_(foobar)" class="external">inline link</a>)', |
|
48 | 48 | '(see "inline link":http://www.foo.bar/Test)' => '(see <a href="http://www.foo.bar/Test" class="external">inline link</a>)', |
|
49 | 49 | '(see "inline link":http://www.foo.bar/Test).' => '(see <a href="http://www.foo.bar/Test" class="external">inline link</a>).', |
|
50 | 50 | 'www.foo.bar' => '<a class="external" href="http://www.foo.bar">www.foo.bar</a>', |
|
51 | 51 | 'http://foo.bar/page?p=1&t=z&s=' => '<a class="external" href="http://foo.bar/page?p=1&t=z&s=">http://foo.bar/page?p=1&t=z&s=</a>', |
|
52 | 52 | 'http://foo.bar/page#125' => '<a class="external" href="http://foo.bar/page#125">http://foo.bar/page#125</a>', |
|
53 | 53 | 'http://foo@www.bar.com' => '<a class="external" href="http://foo@www.bar.com">http://foo@www.bar.com</a>', |
|
54 | 54 | 'http://foo:bar@www.bar.com' => '<a class="external" href="http://foo:bar@www.bar.com">http://foo:bar@www.bar.com</a>', |
|
55 | 55 | 'ftp://foo.bar' => '<a class="external" href="ftp://foo.bar">ftp://foo.bar</a>', |
|
56 | 56 | 'ftps://foo.bar' => '<a class="external" href="ftps://foo.bar">ftps://foo.bar</a>', |
|
57 | 57 | 'sftp://foo.bar' => '<a class="external" href="sftp://foo.bar">sftp://foo.bar</a>', |
|
58 | 58 | } |
|
59 | 59 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
60 | 60 | end |
|
61 | 61 | |
|
62 | 62 | def test_auto_mailto |
|
63 | 63 | assert_equal '<p><a href="mailto:test@foo.bar" class="email">test@foo.bar</a></p>', |
|
64 | 64 | textilizable('test@foo.bar') |
|
65 | 65 | end |
|
66 | 66 | |
|
67 | 67 | def test_inline_images |
|
68 | 68 | to_test = { |
|
69 | 69 | '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />', |
|
70 | 70 | 'floating !>http://foo.bar/image.jpg!' => 'floating <div style="float:right"><img src="http://foo.bar/image.jpg" alt="" /></div>', |
|
71 | 71 | 'with class !(some-class)http://foo.bar/image.jpg!' => 'with class <img src="http://foo.bar/image.jpg" class="some-class" alt="" />', |
|
72 | 72 | # inline styles should be stripped |
|
73 | 73 | 'with style !{width:100px;height100px}http://foo.bar/image.jpg!' => 'with style <img src="http://foo.bar/image.jpg" alt="" />', |
|
74 | 74 | 'with title !http://foo.bar/image.jpg(This is a title)!' => 'with title <img src="http://foo.bar/image.jpg" title="This is a title" alt="This is a title" />', |
|
75 | 75 | 'with title !http://foo.bar/image.jpg(This is a double-quoted "title")!' => 'with title <img src="http://foo.bar/image.jpg" title="This is a double-quoted "title"" alt="This is a double-quoted "title"" />', |
|
76 | 76 | } |
|
77 | 77 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
78 | 78 | end |
|
79 | 79 | |
|
80 | 80 | def test_acronyms |
|
81 | 81 | to_test = { |
|
82 | 82 | 'this is an acronym: GPL(General Public License)' => 'this is an acronym: <acronym title="General Public License">GPL</acronym>', |
|
83 | 83 | 'GPL(This is a double-quoted "title")' => '<acronym title="This is a double-quoted "title"">GPL</acronym>', |
|
84 | 84 | } |
|
85 | 85 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
86 | 86 | |
|
87 | 87 | end |
|
88 | 88 | |
|
89 | 89 | def test_attached_images |
|
90 | 90 | to_test = { |
|
91 | 91 | 'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />', |
|
92 | 'Inline image: !logo.GIF!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />' | |
|
92 | 'Inline image: !logo.GIF!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />', | |
|
93 | 'No match: !ogo.gif!' => 'No match: <img src="ogo.gif" alt="" />', | |
|
94 | 'No match: !ogo.GIF!' => 'No match: <img src="ogo.GIF" alt="" />' | |
|
93 | 95 | } |
|
94 | 96 | attachments = Attachment.find(:all) |
|
95 | 97 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) } |
|
96 | 98 | end |
|
97 | 99 | |
|
98 | 100 | def test_textile_external_links |
|
99 | 101 | to_test = { |
|
100 | 102 | 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>', |
|
101 | 103 | 'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>', |
|
102 | 104 | '"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>', |
|
103 | 105 | '"link (Link title with "double-quotes")":http://foo.bar' => '<a href="http://foo.bar" title="Link title with "double-quotes"" class="external">link</a>', |
|
104 | 106 | "This is not a \"Link\":\n\nAnother paragraph" => "This is not a \"Link\":</p>\n\n\n\t<p>Another paragraph", |
|
105 | 107 | # no multiline link text |
|
106 | 108 | "This is a double quote \"on the first line\nand another on a second line\":test" => "This is a double quote \"on the first line<br />\nand another on a second line\":test" |
|
107 | 109 | } |
|
108 | 110 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
109 | 111 | end |
|
110 | 112 | |
|
111 | 113 | def test_redmine_links |
|
112 | 114 | issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3}, |
|
113 | 115 | :class => 'issue', :title => 'Error 281 when updating a recipe (New)') |
|
114 | 116 | |
|
115 | 117 | changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1}, |
|
116 | 118 | :class => 'changeset', :title => 'My very first commit') |
|
117 | 119 | |
|
118 | 120 | document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1}, |
|
119 | 121 | :class => 'document') |
|
120 | 122 | |
|
121 | 123 | version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2}, |
|
122 | 124 | :class => 'version') |
|
123 | 125 | |
|
124 | 126 | message_url = {:controller => 'messages', :action => 'show', :board_id => 1, :id => 4} |
|
125 | 127 | |
|
126 | 128 | source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']} |
|
127 | 129 | source_url_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']} |
|
128 | 130 | |
|
129 | 131 | to_test = { |
|
130 | 132 | # tickets |
|
131 | 133 | '#3, #3 and #3.' => "#{issue_link}, #{issue_link} and #{issue_link}.", |
|
132 | 134 | # changesets |
|
133 | 135 | 'r1' => changeset_link, |
|
134 | 136 | # documents |
|
135 | 137 | 'document#1' => document_link, |
|
136 | 138 | 'document:"Test document"' => document_link, |
|
137 | 139 | # versions |
|
138 | 140 | 'version#2' => version_link, |
|
139 | 141 | 'version:1.0' => version_link, |
|
140 | 142 | 'version:"1.0"' => version_link, |
|
141 | 143 | # source |
|
142 | 144 | 'source:/some/file' => link_to('source:/some/file', source_url, :class => 'source'), |
|
143 | 145 | 'source:/some/file.' => link_to('source:/some/file', source_url, :class => 'source') + ".", |
|
144 | 146 | 'source:/some/file.ext.' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".", |
|
145 | 147 | 'source:/some/file. ' => link_to('source:/some/file', source_url, :class => 'source') + ".", |
|
146 | 148 | 'source:/some/file.ext. ' => link_to('source:/some/file.ext', source_url_with_ext, :class => 'source') + ".", |
|
147 | 149 | 'source:/some/file, ' => link_to('source:/some/file', source_url, :class => 'source') + ",", |
|
148 | 150 | 'source:/some/file@52' => link_to('source:/some/file@52', source_url.merge(:rev => 52), :class => 'source'), |
|
149 | 151 | 'source:/some/file.ext@52' => link_to('source:/some/file.ext@52', source_url_with_ext.merge(:rev => 52), :class => 'source'), |
|
150 | 152 | 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url.merge(:anchor => 'L110'), :class => 'source'), |
|
151 | 153 | 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext.merge(:anchor => 'L110'), :class => 'source'), |
|
152 | 154 | 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url.merge(:rev => 52, :anchor => 'L110'), :class => 'source'), |
|
153 | 155 | 'export:/some/file' => link_to('export:/some/file', source_url.merge(:format => 'raw'), :class => 'source download'), |
|
154 | 156 | # message |
|
155 | 157 | 'message#4' => link_to('Post 2', message_url, :class => 'message'), |
|
156 | 158 | 'message#5' => link_to('RE: post 2', message_url.merge(:anchor => 'message-5'), :class => 'message'), |
|
157 | 159 | # escaping |
|
158 | 160 | '!#3.' => '#3.', |
|
159 | 161 | '!r1' => 'r1', |
|
160 | 162 | '!document#1' => 'document#1', |
|
161 | 163 | '!document:"Test document"' => 'document:"Test document"', |
|
162 | 164 | '!version#2' => 'version#2', |
|
163 | 165 | '!version:1.0' => 'version:1.0', |
|
164 | 166 | '!version:"1.0"' => 'version:"1.0"', |
|
165 | 167 | '!source:/some/file' => 'source:/some/file', |
|
166 | 168 | # invalid expressions |
|
167 | 169 | 'source:' => 'source:', |
|
168 | 170 | # url hash |
|
169 | 171 | "http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>', |
|
170 | 172 | } |
|
171 | 173 | @project = Project.find(1) |
|
172 | 174 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
173 | 175 | end |
|
174 | 176 | |
|
175 | 177 | def test_wiki_links |
|
176 | 178 | to_test = { |
|
177 | 179 | '[[CookBook documentation]]' => '<a href="/wiki/ecookbook/CookBook_documentation" class="wiki-page">CookBook documentation</a>', |
|
178 | 180 | '[[Another page|Page]]' => '<a href="/wiki/ecookbook/Another_page" class="wiki-page">Page</a>', |
|
179 | 181 | # link with anchor |
|
180 | 182 | '[[CookBook documentation#One-section]]' => '<a href="/wiki/ecookbook/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>', |
|
181 | 183 | '[[Another page#anchor|Page]]' => '<a href="/wiki/ecookbook/Another_page#anchor" class="wiki-page">Page</a>', |
|
182 | 184 | # page that doesn't exist |
|
183 | 185 | '[[Unknown page]]' => '<a href="/wiki/ecookbook/Unknown_page" class="wiki-page new">Unknown page</a>', |
|
184 | 186 | '[[Unknown page|404]]' => '<a href="/wiki/ecookbook/Unknown_page" class="wiki-page new">404</a>', |
|
185 | 187 | # link to another project wiki |
|
186 | 188 | '[[onlinestore:]]' => '<a href="/wiki/onlinestore/" class="wiki-page">onlinestore</a>', |
|
187 | 189 | '[[onlinestore:|Wiki]]' => '<a href="/wiki/onlinestore/" class="wiki-page">Wiki</a>', |
|
188 | 190 | '[[onlinestore:Start page]]' => '<a href="/wiki/onlinestore/Start_page" class="wiki-page">Start page</a>', |
|
189 | 191 | '[[onlinestore:Start page|Text]]' => '<a href="/wiki/onlinestore/Start_page" class="wiki-page">Text</a>', |
|
190 | 192 | '[[onlinestore:Unknown page]]' => '<a href="/wiki/onlinestore/Unknown_page" class="wiki-page new">Unknown page</a>', |
|
191 | 193 | # striked through link |
|
192 | 194 | '-[[Another page|Page]]-' => '<del><a href="/wiki/ecookbook/Another_page" class="wiki-page">Page</a></del>', |
|
193 | 195 | '-[[Another page|Page]] link-' => '<del><a href="/wiki/ecookbook/Another_page" class="wiki-page">Page</a> link</del>', |
|
194 | 196 | # escaping |
|
195 | 197 | '![[Another page|Page]]' => '[[Another page|Page]]', |
|
196 | 198 | } |
|
197 | 199 | @project = Project.find(1) |
|
198 | 200 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
199 | 201 | end |
|
200 | 202 | |
|
201 | 203 | def test_html_tags |
|
202 | 204 | to_test = { |
|
203 | 205 | "<div>content</div>" => "<p><div>content</div></p>", |
|
204 | 206 | "<div class=\"bold\">content</div>" => "<p><div class=\"bold\">content</div></p>", |
|
205 | 207 | "<script>some script;</script>" => "<p><script>some script;</script></p>", |
|
206 | 208 | # do not escape pre/code tags |
|
207 | 209 | "<pre>\nline 1\nline2</pre>" => "<pre>\nline 1\nline2</pre>", |
|
208 | 210 | "<pre><code>\nline 1\nline2</code></pre>" => "<pre><code>\nline 1\nline2</code></pre>", |
|
209 | 211 | "<pre><div>content</div></pre>" => "<pre><div>content</div></pre>", |
|
210 | 212 | "HTML comment: <!-- no comments -->" => "<p>HTML comment: <!-- no comments --></p>", |
|
211 | 213 | "<!-- opening comment" => "<p><!-- opening comment</p>", |
|
212 | 214 | # remove attributes except class |
|
213 | 215 | "<pre class='foo'>some text</pre>" => "<pre class='foo'>some text</pre>", |
|
214 | 216 | "<pre onmouseover='alert(1)'>some text</pre>" => "<pre>some text</pre>", |
|
215 | 217 | } |
|
216 | 218 | to_test.each { |text, result| assert_equal result, textilizable(text) } |
|
217 | 219 | end |
|
218 | 220 | |
|
219 | 221 | def test_allowed_html_tags |
|
220 | 222 | to_test = { |
|
221 | 223 | "<pre>preformatted text</pre>" => "<pre>preformatted text</pre>", |
|
222 | 224 | "<notextile>no *textile* formatting</notextile>" => "no *textile* formatting", |
|
223 | 225 | "<notextile>this is <tag>a tag</tag></notextile>" => "this is <tag>a tag</tag>" |
|
224 | 226 | } |
|
225 | 227 | to_test.each { |text, result| assert_equal result, textilizable(text) } |
|
226 | 228 | end |
|
227 | 229 | |
|
228 | 230 | def syntax_highlight |
|
229 | 231 | raw = <<-RAW |
|
230 | 232 | <pre><code class="ruby"> |
|
231 | 233 | # Some ruby code here |
|
232 | 234 | </pre></code> |
|
233 | 235 | RAW |
|
234 | 236 | |
|
235 | 237 | expected = <<-EXPECTED |
|
236 | 238 | <pre><code class="ruby CodeRay"><span class="no">1</span> <span class="c"># Some ruby code here</span> |
|
237 | 239 | </pre></code> |
|
238 | 240 | EXPECTED |
|
239 | 241 | |
|
240 | 242 | assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '') |
|
241 | 243 | end |
|
242 | 244 | |
|
243 | 245 | def test_wiki_links_in_tables |
|
244 | 246 | to_test = {"|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" => |
|
245 | 247 | '<tr><td><a href="/wiki/ecookbook/Page" class="wiki-page new">Link title</a></td>' + |
|
246 | 248 | '<td><a href="/wiki/ecookbook/Other_Page" class="wiki-page new">Other title</a></td>' + |
|
247 | 249 | '</tr><tr><td>Cell 21</td><td><a href="/wiki/ecookbook/Last_page" class="wiki-page new">Last page</a></td></tr>' |
|
248 | 250 | } |
|
249 | 251 | @project = Project.find(1) |
|
250 | 252 | to_test.each { |text, result| assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '') } |
|
251 | 253 | end |
|
252 | 254 | |
|
253 | 255 | def test_text_formatting |
|
254 | 256 | to_test = {'*_+bold, italic and underline+_*' => '<strong><em><ins>bold, italic and underline</ins></em></strong>', |
|
255 | 257 | '(_text within parentheses_)' => '(<em>text within parentheses</em>)', |
|
256 | 258 | 'a *Humane Web* Text Generator' => 'a <strong>Humane Web</strong> Text Generator', |
|
257 | 259 | 'a H *umane* W *eb* T *ext* G *enerator*' => 'a H <strong>umane</strong> W <strong>eb</strong> T <strong>ext</strong> G <strong>enerator</strong>', |
|
258 | 260 | 'a *H* umane *W* eb *T* ext *G* enerator' => 'a <strong>H</strong> umane <strong>W</strong> eb <strong>T</strong> ext <strong>G</strong> enerator', |
|
259 | 261 | } |
|
260 | 262 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
261 | 263 | end |
|
262 | 264 | |
|
263 | 265 | def test_wiki_horizontal_rule |
|
264 | 266 | assert_equal '<hr />', textilizable('---') |
|
265 | 267 | assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---') |
|
266 | 268 | end |
|
267 | 269 | |
|
268 | 270 | def test_acronym |
|
269 | 271 | assert_equal '<p>This is an acronym: <acronym title="American Civil Liberties Union">ACLU</acronym>.</p>', |
|
270 | 272 | textilizable('This is an acronym: ACLU(American Civil Liberties Union).') |
|
271 | 273 | end |
|
272 | 274 | |
|
273 | 275 | def test_footnotes |
|
274 | 276 | raw = <<-RAW |
|
275 | 277 | This is some text[1]. |
|
276 | 278 | |
|
277 | 279 | fn1. This is the foot note |
|
278 | 280 | RAW |
|
279 | 281 | |
|
280 | 282 | expected = <<-EXPECTED |
|
281 | 283 | <p>This is some text<sup><a href=\"#fn1\">1</a></sup>.</p> |
|
282 | 284 | <p id="fn1" class="footnote"><sup>1</sup> This is the foot note</p> |
|
283 | 285 | EXPECTED |
|
284 | 286 | |
|
285 | 287 | assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '') |
|
286 | 288 | end |
|
287 | 289 | |
|
288 | 290 | def test_table_of_content |
|
289 | 291 | raw = <<-RAW |
|
290 | 292 | {{toc}} |
|
291 | 293 | |
|
292 | 294 | h1. Title |
|
293 | 295 | |
|
294 | 296 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero. |
|
295 | 297 | |
|
296 | 298 | h2. Subtitle |
|
297 | 299 | |
|
298 | 300 | Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor. |
|
299 | 301 | |
|
300 | 302 | h2. Subtitle with %{color:red}red text% |
|
301 | 303 | |
|
302 | 304 | h1. Another title |
|
303 | 305 | |
|
304 | 306 | RAW |
|
305 | 307 | |
|
306 | 308 | expected = '<ul class="toc">' + |
|
307 | 309 | '<li class="heading1"><a href="#Title">Title</a></li>' + |
|
308 | 310 | '<li class="heading2"><a href="#Subtitle">Subtitle</a></li>' + |
|
309 | 311 | '<li class="heading2"><a href="#Subtitle-with-red-text">Subtitle with red text</a></li>' + |
|
310 | 312 | '<li class="heading1"><a href="#Another-title">Another title</a></li>' + |
|
311 | 313 | '</ul>' |
|
312 | 314 | |
|
313 | 315 | assert textilizable(raw).gsub("\n", "").include?(expected) |
|
314 | 316 | end |
|
315 | 317 | |
|
316 | 318 | def test_blockquote |
|
317 | 319 | # orig raw text |
|
318 | 320 | raw = <<-RAW |
|
319 | 321 | John said: |
|
320 | 322 | > Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero. |
|
321 | 323 | > Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor. |
|
322 | 324 | > * Donec odio lorem, |
|
323 | 325 | > * sagittis ac, |
|
324 | 326 | > * malesuada in, |
|
325 | 327 | > * adipiscing eu, dolor. |
|
326 | 328 | > |
|
327 | 329 | > >Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus. |
|
328 | 330 | > Proin a tellus. Nam vel neque. |
|
329 | 331 | |
|
330 | 332 | He's right. |
|
331 | 333 | RAW |
|
332 | 334 | |
|
333 | 335 | # expected html |
|
334 | 336 | expected = <<-EXPECTED |
|
335 | 337 | <p>John said:</p> |
|
336 | 338 | <blockquote> |
|
337 | 339 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero. |
|
338 | 340 | Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor. |
|
339 | 341 | <ul> |
|
340 | 342 | <li>Donec odio lorem,</li> |
|
341 | 343 | <li>sagittis ac,</li> |
|
342 | 344 | <li>malesuada in,</li> |
|
343 | 345 | <li>adipiscing eu, dolor.</li> |
|
344 | 346 | </ul> |
|
345 | 347 | <blockquote> |
|
346 | 348 | <p>Nulla varius pulvinar diam. Proin id arcu id lorem scelerisque condimentum. Proin vehicula turpis vitae lacus.</p> |
|
347 | 349 | </blockquote> |
|
348 | 350 | <p>Proin a tellus. Nam vel neque.</p> |
|
349 | 351 | </blockquote> |
|
350 | 352 | <p>He's right.</p> |
|
351 | 353 | EXPECTED |
|
352 | 354 | |
|
353 | 355 | assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '') |
|
354 | 356 | end |
|
355 | 357 | |
|
356 | 358 | def test_table |
|
357 | 359 | raw = <<-RAW |
|
358 | 360 | This is a table with empty cells: |
|
359 | 361 | |
|
360 | 362 | |cell11|cell12|| |
|
361 | 363 | |cell21||cell23| |
|
362 | 364 | |cell31|cell32|cell33| |
|
363 | 365 | RAW |
|
364 | 366 | |
|
365 | 367 | expected = <<-EXPECTED |
|
366 | 368 | <p>This is a table with empty cells:</p> |
|
367 | 369 | |
|
368 | 370 | <table> |
|
369 | 371 | <tr><td>cell11</td><td>cell12</td><td></td></tr> |
|
370 | 372 | <tr><td>cell21</td><td></td><td>cell23</td></tr> |
|
371 | 373 | <tr><td>cell31</td><td>cell32</td><td>cell33</td></tr> |
|
372 | 374 | </table> |
|
373 | 375 | EXPECTED |
|
374 | 376 | |
|
375 | 377 | assert_equal expected.gsub(%r{\s+}, ''), textilizable(raw).gsub(%r{\s+}, '') |
|
376 | 378 | end |
|
377 | 379 | |
|
378 | 380 | def test_default_formatter |
|
379 | 381 | Setting.text_formatting = 'unknown' |
|
380 | 382 | text = 'a *link*: http://www.example.net/' |
|
381 | 383 | assert_equal '<p>a *link*: <a href="http://www.example.net/">http://www.example.net/</a></p>', textilizable(text) |
|
382 | 384 | Setting.text_formatting = 'textile' |
|
383 | 385 | end |
|
384 | 386 | |
|
385 | 387 | def test_date_format_default |
|
386 | 388 | today = Date.today |
|
387 | 389 | Setting.date_format = '' |
|
388 | 390 | assert_equal l_date(today), format_date(today) |
|
389 | 391 | end |
|
390 | 392 | |
|
391 | 393 | def test_date_format |
|
392 | 394 | today = Date.today |
|
393 | 395 | Setting.date_format = '%d %m %Y' |
|
394 | 396 | assert_equal today.strftime('%d %m %Y'), format_date(today) |
|
395 | 397 | end |
|
396 | 398 | |
|
397 | 399 | def test_time_format_default |
|
398 | 400 | now = Time.now |
|
399 | 401 | Setting.date_format = '' |
|
400 | 402 | Setting.time_format = '' |
|
401 | 403 | assert_equal l_datetime(now), format_time(now) |
|
402 | 404 | assert_equal l_time(now), format_time(now, false) |
|
403 | 405 | end |
|
404 | 406 | |
|
405 | 407 | def test_time_format |
|
406 | 408 | now = Time.now |
|
407 | 409 | Setting.date_format = '%d %m %Y' |
|
408 | 410 | Setting.time_format = '%H %M' |
|
409 | 411 | assert_equal now.strftime('%d %m %Y %H %M'), format_time(now) |
|
410 | 412 | assert_equal now.strftime('%H %M'), format_time(now, false) |
|
411 | 413 | end |
|
412 | 414 | |
|
413 | 415 | def test_utc_time_format |
|
414 | 416 | now = Time.now.utc |
|
415 | 417 | Setting.date_format = '%d %m %Y' |
|
416 | 418 | Setting.time_format = '%H %M' |
|
417 | 419 | assert_equal Time.now.strftime('%d %m %Y %H %M'), format_time(now) |
|
418 | 420 | assert_equal Time.now.strftime('%H %M'), format_time(now, false) |
|
419 | 421 | end |
|
420 | 422 | |
|
421 | 423 | def test_due_date_distance_in_words |
|
422 | 424 | to_test = { Date.today => 'Due in 0 days', |
|
423 | 425 | Date.today + 1 => 'Due in 1 day', |
|
424 | 426 | Date.today + 100 => 'Due in 100 days', |
|
425 | 427 | Date.today + 20000 => 'Due in 20000 days', |
|
426 | 428 | Date.today - 1 => '1 day late', |
|
427 | 429 | Date.today - 100 => '100 days late', |
|
428 | 430 | Date.today - 20000 => '20000 days late', |
|
429 | 431 | } |
|
430 | 432 | to_test.each do |date, expected| |
|
431 | 433 | assert_equal expected, due_date_distance_in_words(date) |
|
432 | 434 | end |
|
433 | 435 | end |
|
434 | 436 | |
|
435 | 437 | def test_avatar |
|
436 | 438 | # turn on avatars |
|
437 | 439 | Setting.gravatar_enabled = '1' |
|
438 | 440 | assert avatar(User.find_by_mail('jsmith@somenet.foo')).include?(Digest::MD5.hexdigest('jsmith@somenet.foo')) |
|
439 | 441 | assert avatar('jsmith <jsmith@somenet.foo>').include?(Digest::MD5.hexdigest('jsmith@somenet.foo')) |
|
440 | 442 | assert_nil avatar('jsmith') |
|
441 | 443 | assert_nil avatar(nil) |
|
442 | 444 | |
|
443 | 445 | # turn off avatars |
|
444 | 446 | Setting.gravatar_enabled = '0' |
|
445 | 447 | assert_nil avatar(User.find_by_mail('jsmith@somenet.foo')) |
|
446 | 448 | end |
|
447 | 449 | end |
General Comments 0
You need to be logged in to leave comments.
Login now