@@ -0,0 +1,81 | |||
|
1 | # redMine - project management software | |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
|
3 | # | |
|
4 | # This program is free software; you can redistribute it and/or | |
|
5 | # modify it under the terms of the GNU General Public License | |
|
6 | # as published by the Free Software Foundation; either version 2 | |
|
7 | # of the License, or (at your option) any later version. | |
|
8 | # | |
|
9 | # This program is distributed in the hope that it will be useful, | |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
12 | # GNU General Public License for more details. | |
|
13 | # | |
|
14 | # You should have received a copy of the GNU General Public License | |
|
15 | # along with this program; if not, write to the Free Software | |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
|
17 | ||
|
18 | module Redmine | |
|
19 | module WikiFormatting | |
|
20 | module Macros | |
|
21 | module Definitions | |
|
22 | def exec_macro(name, obj, args) | |
|
23 | method_name = "macro_#{name}" | |
|
24 | send(method_name, obj, args) if respond_to?(method_name) | |
|
25 | end | |
|
26 | end | |
|
27 | ||
|
28 | @@available_macros = {} | |
|
29 | ||
|
30 | class << self | |
|
31 | # Called with a block to define additional macros. | |
|
32 | # Macro blocks accept 2 arguments: | |
|
33 | # * obj: the object that is rendered | |
|
34 | # * args: macro arguments | |
|
35 | # | |
|
36 | # Plugins can use this method to define new macros: | |
|
37 | # | |
|
38 | # Redmine::WikiFormatting::Macros.register do | |
|
39 | # desc "This is my macro" | |
|
40 | # macro :my_macro do |obj, args| | |
|
41 | # "My macro output" | |
|
42 | # end | |
|
43 | # end | |
|
44 | def register(&block) | |
|
45 | class_eval(&block) if block_given? | |
|
46 | end | |
|
47 | ||
|
48 | private | |
|
49 | # Defines a new macro with the given name and block. | |
|
50 | def macro(name, &block) | |
|
51 | name = name.to_sym if name.is_a?(String) | |
|
52 | @@available_macros[name] = @@desc || '' | |
|
53 | @@desc = nil | |
|
54 | raise "Can not create a macro without a block!" unless block_given? | |
|
55 | Definitions.send :define_method, "macro_#{name}".downcase, &block | |
|
56 | end | |
|
57 | ||
|
58 | # Sets description for the next macro to be defined | |
|
59 | def desc(txt) | |
|
60 | @@desc = txt | |
|
61 | end | |
|
62 | end | |
|
63 | ||
|
64 | # Builtin macros | |
|
65 | desc "Example macro." | |
|
66 | macro :hello_world do |obj, args| | |
|
67 | "Hello world! Object: #{obj.class.name}, " + (args.empty? ? "Called with no argument." : "Arguments: #{args.join(', ')}") | |
|
68 | end | |
|
69 | ||
|
70 | desc "Displays a list of all available macros, including description if available." | |
|
71 | macro :macro_list do | |
|
72 | out = '' | |
|
73 | @@available_macros.keys.collect(&:to_s).sort.each do |macro| | |
|
74 | out << content_tag('dt', content_tag('code', macro)) | |
|
75 | out << content_tag('dd', simple_format(@@available_macros[macro.to_sym])) | |
|
76 | end | |
|
77 | content_tag('dl', out) | |
|
78 | end | |
|
79 | end | |
|
80 | end | |
|
81 | end |
@@ -1,369 +1,384 | |||
|
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 | module ApplicationHelper |
|
19 | include Redmine::WikiFormatting::Macros::Definitions | |
|
19 | 20 | |
|
20 | 21 | def current_role |
|
21 | 22 | @current_role ||= User.current.role_for_project(@project) |
|
22 | 23 | end |
|
23 | 24 | |
|
24 | 25 | # Return true if user is authorized for controller/action, otherwise false |
|
25 | 26 | def authorize_for(controller, action) |
|
26 | 27 | User.current.allowed_to?({:controller => controller, :action => action}, @project) |
|
27 | 28 | end |
|
28 | 29 | |
|
29 | 30 | # Display a link if user is authorized |
|
30 | 31 | def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference) |
|
31 | 32 | link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action]) |
|
32 | 33 | end |
|
33 | 34 | |
|
34 | 35 | # Display a link to user's account page |
|
35 | 36 | def link_to_user(user) |
|
36 | 37 | link_to user.name, :controller => 'account', :action => 'show', :id => user |
|
37 | 38 | end |
|
38 | 39 | |
|
39 | 40 | def link_to_issue(issue) |
|
40 | 41 | link_to "#{issue.tracker.name} ##{issue.id}", :controller => "issues", :action => "show", :id => issue |
|
41 | 42 | end |
|
42 | 43 | |
|
43 | 44 | def toggle_link(name, id, options={}) |
|
44 | 45 | onclick = "Element.toggle('#{id}'); " |
|
45 | 46 | onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ") |
|
46 | 47 | onclick << "return false;" |
|
47 | 48 | link_to(name, "#", :onclick => onclick) |
|
48 | 49 | end |
|
49 | 50 | |
|
50 | 51 | def show_and_goto_link(name, id, options={}) |
|
51 | 52 | onclick = "Element.show('#{id}'); " |
|
52 | 53 | onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ") |
|
53 | 54 | onclick << "location.href='##{id}-anchor'; " |
|
54 | 55 | onclick << "return false;" |
|
55 | 56 | link_to(name, "#", options.merge(:onclick => onclick)) |
|
56 | 57 | end |
|
57 | 58 | |
|
58 | 59 | def image_to_function(name, function, html_options = {}) |
|
59 | 60 | html_options.symbolize_keys! |
|
60 | 61 | tag(:input, html_options.merge({ |
|
61 | 62 | :type => "image", :src => image_path(name), |
|
62 | 63 | :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};" |
|
63 | 64 | })) |
|
64 | 65 | end |
|
65 | 66 | |
|
66 | 67 | def prompt_to_remote(name, text, param, url, html_options = {}) |
|
67 | 68 | html_options[:onclick] = "promptToRemote('#{text}', '#{param}', '#{url_for(url)}'); return false;" |
|
68 | 69 | link_to name, {}, html_options |
|
69 | 70 | end |
|
70 | 71 | |
|
71 | 72 | def format_date(date) |
|
72 | 73 | return nil unless date |
|
73 | 74 | @date_format ||= (Setting.date_format.to_i == 0 ? l(:general_fmt_date) : "%Y-%m-%d") |
|
74 | 75 | date.strftime(@date_format) |
|
75 | 76 | end |
|
76 | 77 | |
|
77 | 78 | def format_time(time) |
|
78 | 79 | return nil unless time |
|
79 | 80 | @date_format_setting ||= Setting.date_format.to_i |
|
80 | 81 | time = time.to_time if time.is_a?(String) |
|
81 | 82 | @date_format_setting == 0 ? l_datetime(time) : (time.strftime("%Y-%m-%d") + ' ' + l_time(time)) |
|
82 | 83 | end |
|
83 | 84 | |
|
84 | 85 | def authoring(created, author) |
|
85 | 86 | time_tag = content_tag('acronym', distance_of_time_in_words(Time.now, created), :title => format_time(created)) |
|
86 | 87 | l(:label_added_time_by, author.name, time_tag) |
|
87 | 88 | end |
|
88 | 89 | |
|
89 | 90 | def day_name(day) |
|
90 | 91 | l(:general_day_names).split(',')[day-1] |
|
91 | 92 | end |
|
92 | 93 | |
|
93 | 94 | def month_name(month) |
|
94 | 95 | l(:actionview_datehelper_select_month_names).split(',')[month-1] |
|
95 | 96 | end |
|
96 | 97 | |
|
97 | 98 | def pagination_links_full(paginator, options={}, html_options={}) |
|
98 | 99 | page_param = options.delete(:page_param) || :page |
|
99 | 100 | |
|
100 | 101 | html = '' |
|
101 | 102 | html << link_to_remote(('« ' + l(:label_previous)), |
|
102 | 103 | {:update => "content", :url => options.merge(page_param => paginator.current.previous)}, |
|
103 | 104 | {:href => url_for(:params => options.merge(page_param => paginator.current.previous))}) + ' ' if paginator.current.previous |
|
104 | 105 | |
|
105 | 106 | html << (pagination_links_each(paginator, options) do |n| |
|
106 | 107 | link_to_remote(n.to_s, |
|
107 | 108 | {:url => {:params => options.merge(page_param => n)}, :update => 'content'}, |
|
108 | 109 | {:href => url_for(:params => options.merge(page_param => n))}) |
|
109 | 110 | end || '') |
|
110 | 111 | |
|
111 | 112 | html << ' ' + link_to_remote((l(:label_next) + ' »'), |
|
112 | 113 | {:update => "content", :url => options.merge(page_param => paginator.current.next)}, |
|
113 | 114 | {:href => url_for(:params => options.merge(page_param => paginator.current.next))}) if paginator.current.next |
|
114 | 115 | html |
|
115 | 116 | end |
|
116 | 117 | |
|
117 | 118 | def set_html_title(text) |
|
118 | 119 | @html_header_title = text |
|
119 | 120 | end |
|
120 | 121 | |
|
121 | 122 | def html_title |
|
122 | 123 | title = [] |
|
123 | 124 | title << @project.name if @project |
|
124 | 125 | title << @html_header_title |
|
125 | 126 | title << Setting.app_title |
|
126 | 127 | title.compact.join(' - ') |
|
127 | 128 | end |
|
128 | 129 | |
|
129 | 130 | ACCESSKEYS = {:edit => 'e', |
|
130 | 131 | :preview => 'r', |
|
131 | 132 | :quick_search => 'f', |
|
132 | 133 | :search => '4', |
|
133 | }.freeze | |
|
134 | }.freeze unless const_defined?(:ACCESSKEYS) | |
|
134 | 135 | |
|
135 | 136 | def accesskey(s) |
|
136 | 137 | ACCESSKEYS[s] |
|
137 | 138 | end |
|
138 | 139 | |
|
139 |
# |
|
|
140 | def textilizable(text, options = {}) | |
|
141 | return "" if text.blank? | |
|
140 | # Formats text according to system settings. | |
|
141 | # 2 ways to call this method: | |
|
142 | # * with a String: textilizable(text, options) | |
|
143 | # * with an object and one of its attribute: textilizable(issue, :description, options) | |
|
144 | def textilizable(*args) | |
|
145 | options = args.last.is_a?(Hash) ? args.pop : {} | |
|
146 | case args.size | |
|
147 | when 1 | |
|
148 | obj = nil | |
|
149 | text = args.shift || '' | |
|
150 | when 2 | |
|
151 | obj = args.shift | |
|
152 | text = obj.send(args.shift) | |
|
153 | else | |
|
154 | raise ArgumentError, 'invalid arguments to textilizable' | |
|
155 | end | |
|
142 | 156 | |
|
143 | 157 | # when using an image link, try to use an attachment, if possible |
|
144 | 158 | attachments = options[:attachments] |
|
145 | 159 | if attachments |
|
146 | 160 | text = text.gsub(/!([<>=]*)(\S+\.(gif|jpg|jpeg|png))!/) do |m| |
|
147 | 161 | align = $1 |
|
148 | 162 | filename = $2 |
|
149 | 163 | rf = Regexp.new(filename, Regexp::IGNORECASE) |
|
150 | 164 | # search for the picture in attachments |
|
151 | 165 | if found = attachments.detect { |att| att.filename =~ rf } |
|
152 | 166 | image_url = url_for :controller => 'attachments', :action => 'download', :id => found.id |
|
153 | 167 | "!#{align}#{image_url}!" |
|
154 | 168 | else |
|
155 | 169 | "!#{align}#{filename}!" |
|
156 | 170 | end |
|
157 | 171 | end |
|
158 | 172 | end |
|
159 | 173 | |
|
160 | 174 | text = (Setting.text_formatting == 'textile') ? |
|
161 | Redmine::WikiFormatting.to_html(text) : simple_format(auto_link(h(text))) | |
|
175 | Redmine::WikiFormatting.to_html(text) { |macro, args| exec_macro(macro, obj, args) } : | |
|
176 | simple_format(auto_link(h(text))) | |
|
162 | 177 | |
|
163 | 178 | # different methods for formatting wiki links |
|
164 | 179 | case options[:wiki_links] |
|
165 | 180 | when :local |
|
166 | 181 | # used for local links to html files |
|
167 | 182 | format_wiki_link = Proc.new {|project, title| "#{title}.html" } |
|
168 | 183 | when :anchor |
|
169 | 184 | # used for single-file wiki export |
|
170 | 185 | format_wiki_link = Proc.new {|project, title| "##{title}" } |
|
171 | 186 | else |
|
172 | 187 | format_wiki_link = Proc.new {|project, title| url_for :controller => 'wiki', :action => 'index', :id => project, :page => title } |
|
173 | 188 | end |
|
174 | 189 | |
|
175 | 190 | project = options[:project] || @project |
|
176 | 191 | |
|
177 | 192 | # turn wiki links into html links |
|
178 | 193 | # example: |
|
179 | 194 | # [[mypage]] |
|
180 | 195 | # [[mypage|mytext]] |
|
181 | 196 | # wiki links can refer other project wikis, using project name or identifier: |
|
182 | 197 | # [[project:]] -> wiki starting page |
|
183 | 198 | # [[project:|mytext]] |
|
184 | 199 | # [[project:mypage]] |
|
185 | 200 | # [[project:mypage|mytext]] |
|
186 | 201 | text = text.gsub(/\[\[([^\]\|]+)(\|([^\]\|]+))?\]\]/) do |m| |
|
187 | 202 | link_project = project |
|
188 | 203 | page = $1 |
|
189 | 204 | title = $3 |
|
190 | 205 | if page =~ /^([^\:]+)\:(.*)$/ |
|
191 | 206 | link_project = Project.find_by_name($1) || Project.find_by_identifier($1) |
|
192 | 207 | page = title || $2 |
|
193 | 208 | title = $1 if page.blank? |
|
194 | 209 | end |
|
195 | 210 | |
|
196 | 211 | if link_project && link_project.wiki |
|
197 | 212 | # check if page exists |
|
198 | 213 | wiki_page = link_project.wiki.find_page(page) |
|
199 | 214 | link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page)), |
|
200 | 215 | :class => ('wiki-page' + (wiki_page ? '' : ' new'))) |
|
201 | 216 | else |
|
202 | 217 | # project or wiki doesn't exist |
|
203 | 218 | title || page |
|
204 | 219 | end |
|
205 | 220 | end |
|
206 | 221 | |
|
207 | 222 | # turn issue and revision ids into links |
|
208 | 223 | # example: |
|
209 | 224 | # #52 -> <a href="/issues/show/52">#52</a> |
|
210 | 225 | # r52 -> <a href="/repositories/revision/6?rev=52">r52</a> (project.id is 6) |
|
211 | 226 | text = text.gsub(%r{([\s,-^])(#|r)(\d+)(?=[[:punct:]]|\s|<|$)}) do |m| |
|
212 | 227 | leading, otype, oid = $1, $2, $3 |
|
213 | 228 | link = nil |
|
214 | 229 | if otype == 'r' |
|
215 | 230 | if project && (changeset = project.changesets.find_by_revision(oid)) |
|
216 | 231 | link = link_to("r#{oid}", {:controller => 'repositories', :action => 'revision', :id => project.id, :rev => oid}, :class => 'changeset', |
|
217 | 232 | :title => truncate(changeset.comments, 100)) |
|
218 | 233 | end |
|
219 | 234 | else |
|
220 | 235 | if issue = Issue.find_by_id(oid.to_i, :include => [:project, :status], :conditions => Project.visible_by(User.current)) |
|
221 | 236 | link = link_to("##{oid}", {:controller => 'issues', :action => 'show', :id => oid}, :class => 'issue', |
|
222 | 237 | :title => "#{truncate(issue.subject, 100)} (#{issue.status.name})") |
|
223 | 238 | link = content_tag('del', link) if issue.closed? |
|
224 | 239 | end |
|
225 | 240 | end |
|
226 | 241 | leading + (link || "#{otype}#{oid}") |
|
227 | 242 | end |
|
228 | 243 | |
|
229 | 244 | text |
|
230 | 245 | end |
|
231 | 246 | |
|
232 | 247 | # Same as Rails' simple_format helper without using paragraphs |
|
233 | 248 | def simple_format_without_paragraph(text) |
|
234 | 249 | text.to_s. |
|
235 | 250 | gsub(/\r\n?/, "\n"). # \r\n and \r -> \n |
|
236 | 251 | gsub(/\n\n+/, "<br /><br />"). # 2+ newline -> 2 br |
|
237 | 252 | gsub(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br |
|
238 | 253 | end |
|
239 | 254 | |
|
240 | 255 | def error_messages_for(object_name, options = {}) |
|
241 | 256 | options = options.symbolize_keys |
|
242 | 257 | object = instance_variable_get("@#{object_name}") |
|
243 | 258 | if object && !object.errors.empty? |
|
244 | 259 | # build full_messages here with controller current language |
|
245 | 260 | full_messages = [] |
|
246 | 261 | object.errors.each do |attr, msg| |
|
247 | 262 | next if msg.nil? |
|
248 | 263 | msg = msg.first if msg.is_a? Array |
|
249 | 264 | if attr == "base" |
|
250 | 265 | full_messages << l(msg) |
|
251 | 266 | else |
|
252 | 267 | full_messages << "« " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " » " + l(msg) unless attr == "custom_values" |
|
253 | 268 | end |
|
254 | 269 | end |
|
255 | 270 | # retrieve custom values error messages |
|
256 | 271 | if object.errors[:custom_values] |
|
257 | 272 | object.custom_values.each do |v| |
|
258 | 273 | v.errors.each do |attr, msg| |
|
259 | 274 | next if msg.nil? |
|
260 | 275 | msg = msg.first if msg.is_a? Array |
|
261 | 276 | full_messages << "« " + v.custom_field.name + " » " + l(msg) |
|
262 | 277 | end |
|
263 | 278 | end |
|
264 | 279 | end |
|
265 | 280 | content_tag("div", |
|
266 | 281 | content_tag( |
|
267 | 282 | options[:header_tag] || "span", lwr(:gui_validation_error, full_messages.length) + ":" |
|
268 | 283 | ) + |
|
269 | 284 | content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }), |
|
270 | 285 | "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation" |
|
271 | 286 | ) |
|
272 | 287 | else |
|
273 | 288 | "" |
|
274 | 289 | end |
|
275 | 290 | end |
|
276 | 291 | |
|
277 | 292 | def lang_options_for_select(blank=true) |
|
278 | 293 | (blank ? [["(auto)", ""]] : []) + |
|
279 | 294 | GLoc.valid_languages.collect{|lang| [ ll(lang.to_s, :general_lang_name), lang.to_s]}.sort{|x,y| x.first <=> y.first } |
|
280 | 295 | end |
|
281 | 296 | |
|
282 | 297 | def label_tag_for(name, option_tags = nil, options = {}) |
|
283 | 298 | label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "") |
|
284 | 299 | content_tag("label", label_text) |
|
285 | 300 | end |
|
286 | 301 | |
|
287 | 302 | def labelled_tabular_form_for(name, object, options, &proc) |
|
288 | 303 | options[:html] ||= {} |
|
289 | 304 | options[:html].store :class, "tabular" |
|
290 | 305 | form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc) |
|
291 | 306 | end |
|
292 | 307 | |
|
293 | 308 | def check_all_links(form_name) |
|
294 | 309 | link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") + |
|
295 | 310 | " | " + |
|
296 | 311 | link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)") |
|
297 | 312 | end |
|
298 | 313 | |
|
299 | 314 | def context_menu_link(name, url, options={}) |
|
300 | 315 | options[:class] ||= '' |
|
301 | 316 | if options.delete(:selected) |
|
302 | 317 | options[:class] << ' icon-checked disabled' |
|
303 | 318 | options[:disabled] = true |
|
304 | 319 | end |
|
305 | 320 | if options.delete(:disabled) |
|
306 | 321 | options.delete(:method) |
|
307 | 322 | options.delete(:confirm) |
|
308 | 323 | options.delete(:onclick) |
|
309 | 324 | options[:class] << ' disabled' |
|
310 | 325 | url = '#' |
|
311 | 326 | end |
|
312 | 327 | link_to name, url, options |
|
313 | 328 | end |
|
314 | 329 | |
|
315 | 330 | def calendar_for(field_id) |
|
316 | 331 | image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) + |
|
317 | 332 | javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });") |
|
318 | 333 | end |
|
319 | 334 | |
|
320 | 335 | def wikitoolbar_for(field_id) |
|
321 | 336 | return '' unless Setting.text_formatting == 'textile' |
|
322 | 337 | javascript_include_tag('jstoolbar') + javascript_tag("var toolbar = new jsToolBar($('#{field_id}')); toolbar.draw();") |
|
323 | 338 | end |
|
324 | 339 | |
|
325 | 340 | def content_for(name, content = nil, &block) |
|
326 | 341 | @has_content ||= {} |
|
327 | 342 | @has_content[name] = true |
|
328 | 343 | super(name, content, &block) |
|
329 | 344 | end |
|
330 | 345 | |
|
331 | 346 | def has_content?(name) |
|
332 | 347 | (@has_content && @has_content[name]) || false |
|
333 | 348 | end |
|
334 | 349 | end |
|
335 | 350 | |
|
336 | 351 | class TabularFormBuilder < ActionView::Helpers::FormBuilder |
|
337 | 352 | include GLoc |
|
338 | 353 | |
|
339 | 354 | def initialize(object_name, object, template, options, proc) |
|
340 | 355 | set_language_if_valid options.delete(:lang) |
|
341 | 356 | @object_name, @object, @template, @options, @proc = object_name, object, template, options, proc |
|
342 | 357 | end |
|
343 | 358 | |
|
344 | 359 | (field_helpers - %w(radio_button hidden_field) + %w(date_select)).each do |selector| |
|
345 | 360 | src = <<-END_SRC |
|
346 | 361 | def #{selector}(field, options = {}) |
|
347 | 362 | return super if options.delete :no_label |
|
348 | 363 | label_text = l(options[:label]) if options[:label] |
|
349 | 364 | label_text ||= l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) |
|
350 | 365 | label_text << @template.content_tag("span", " *", :class => "required") if options.delete(:required) |
|
351 | 366 | label = @template.content_tag("label", label_text, |
|
352 | 367 | :class => (@object && @object.errors[field] ? "error" : nil), |
|
353 | 368 | :for => (@object_name.to_s + "_" + field.to_s)) |
|
354 | 369 | label + super |
|
355 | 370 | end |
|
356 | 371 | END_SRC |
|
357 | 372 | class_eval src, __FILE__, __LINE__ |
|
358 | 373 | end |
|
359 | 374 | |
|
360 | 375 | def select(field, choices, options = {}, html_options = {}) |
|
361 | 376 | label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "") |
|
362 | 377 | label = @template.content_tag("label", label_text, |
|
363 | 378 | :class => (@object && @object.errors[field] ? "error" : nil), |
|
364 | 379 | :for => (@object_name.to_s + "_" + field.to_s)) |
|
365 | 380 | label + super |
|
366 | 381 | end |
|
367 | 382 | |
|
368 | 383 | end |
|
369 | 384 |
@@ -1,123 +1,123 | |||
|
1 | 1 | <div class="contextual"> |
|
2 | 2 | <%= show_and_goto_link(l(:label_add_note), 'add-note', :class => 'icon icon-note') if authorize_for('issues', 'add_note') %> |
|
3 | 3 | <%= link_to_if_authorized l(:button_edit), {:controller => 'issues', :action => 'edit', :id => @issue}, :class => 'icon icon-edit', :accesskey => accesskey(:edit) %> |
|
4 | 4 | <%= link_to_if_authorized l(:button_log_time), {:controller => 'timelog', :action => 'edit', :issue_id => @issue}, :class => 'icon icon-time' %> |
|
5 | 5 | <%= watcher_tag(@issue, User.current) %> |
|
6 | 6 | <%= link_to_if_authorized l(:button_copy), {:controller => 'projects', :action => 'add_issue', :id => @project, :copy_from => @issue }, :class => 'icon icon-copy' %> |
|
7 | 7 | <%= link_to_if_authorized l(:button_move), {:controller => 'projects', :action => 'move_issues', :id => @project, "issue_ids[]" => @issue.id }, :class => 'icon icon-move' %> |
|
8 | 8 | <%= link_to_if_authorized l(:button_delete), {:controller => 'issues', :action => 'destroy', :id => @issue}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %> |
|
9 | 9 | </div> |
|
10 | 10 | |
|
11 | 11 | <h2><%= @issue.tracker.name %> #<%= @issue.id %></h2> |
|
12 | 12 | |
|
13 | 13 | <div class="issue"> |
|
14 | 14 | <h3><%=h @issue.subject %></h3> |
|
15 | 15 | <p class="author"> |
|
16 | 16 | <%= authoring @issue.created_on, @issue.author %>. |
|
17 | 17 | <%= l(:label_updated_time, distance_of_time_in_words(Time.now, @issue.updated_on)) if @issue.created_on != @issue.updated_on %>. |
|
18 | 18 | </p> |
|
19 | 19 | |
|
20 | 20 | <table width="100%"> |
|
21 | 21 | <tr> |
|
22 | 22 | <td style="width:15%"><b><%=l(:field_status)%> :</b></td><td style="width:35%"><%= @issue.status.name %></td> |
|
23 | 23 | <td style="width:15%"><b><%=l(:field_start_date)%> :</b></td><td style="width:35%"><%= format_date(@issue.start_date) %></td> |
|
24 | 24 | </tr> |
|
25 | 25 | <tr> |
|
26 | 26 | <td><b><%=l(:field_priority)%> :</b></td><td><%= @issue.priority.name %></td> |
|
27 | 27 | <td><b><%=l(:field_due_date)%> :</b></td><td><%= format_date(@issue.due_date) %></td> |
|
28 | 28 | </tr> |
|
29 | 29 | <tr> |
|
30 | 30 | <td><b><%=l(:field_assigned_to)%> :</b></td><td><%= @issue.assigned_to ? link_to_user(@issue.assigned_to) : "-" %></td> |
|
31 | 31 | <td><b><%=l(:field_done_ratio)%> :</b></td><td><%= @issue.done_ratio %> %</td> |
|
32 | 32 | </tr> |
|
33 | 33 | <tr> |
|
34 | 34 | <td><b><%=l(:field_category)%> :</b></td><td><%=h @issue.category ? @issue.category.name : "-" %></td> |
|
35 | 35 | <% if User.current.allowed_to?(:view_time_entries, @project) %> |
|
36 | 36 | <td><b><%=l(:label_spent_time)%> :</b></td> |
|
37 | 37 | <td><%= @issue.spent_hours > 0 ? (link_to lwr(:label_f_hour, @issue.spent_hours), {:controller => 'timelog', :action => 'details', :issue_id => @issue}, :class => 'icon icon-time') : "-" %></td> |
|
38 | 38 | <% end %> |
|
39 | 39 | </tr> |
|
40 | 40 | <tr> |
|
41 | 41 | <td><b><%=l(:field_fixed_version)%> :</b></td><td><%= @issue.fixed_version ? link_to_version(@issue.fixed_version) : "-" %></td> |
|
42 | 42 | <% if @issue.estimated_hours %> |
|
43 | 43 | <td><b><%=l(:field_estimated_hours)%> :</b></td><td><%= lwr(:label_f_hour, @issue.estimated_hours) %></td> |
|
44 | 44 | <% end %> |
|
45 | 45 | </tr> |
|
46 | 46 | <tr> |
|
47 | 47 | <% n = 0 |
|
48 | 48 | for custom_value in @custom_values %> |
|
49 | 49 | <td valign="top"><b><%= custom_value.custom_field.name %> :</b></td><td valign="top"><%= simple_format(h(show_value(custom_value))) %></td> |
|
50 | 50 | <% n = n + 1 |
|
51 | 51 | if (n > 1) |
|
52 | 52 | n = 0 %> |
|
53 | 53 | </tr><tr> |
|
54 | 54 | <%end |
|
55 | 55 | end %> |
|
56 | 56 | </tr> |
|
57 | 57 | </table> |
|
58 | 58 | <hr /> |
|
59 | 59 | |
|
60 | 60 | <% if @issue.changesets.any? %> |
|
61 | 61 | <div style="float:right;"> |
|
62 | 62 | <em><%= l(:label_revision_plural) %>: <%= @issue.changesets.collect{|changeset| link_to(changeset.revision, :controller => 'repositories', :action => 'revision', :id => @project, :rev => changeset.revision)}.join(", ") %></em> |
|
63 | 63 | </div> |
|
64 | 64 | <% end %> |
|
65 | 65 | |
|
66 | 66 | <p><strong><%=l(:field_description)%></strong></p> |
|
67 |
<%= textilizable @issue |
|
|
67 | <%= textilizable @issue, :description, :attachments => @issue.attachments %> | |
|
68 | 68 | |
|
69 | 69 | <% if @issue.attachments.any? %> |
|
70 | 70 | <%= link_to_attachments @issue.attachments, :delete_url => (authorize_for('issues', 'destroy_attachment') ? {:controller => 'issues', :action => 'destroy_attachment', :id => @issue} : nil) %> |
|
71 | 71 | <% end %> |
|
72 | 72 | |
|
73 | 73 | <% if authorize_for('issue_relations', 'new') || @issue.relations.any? %> |
|
74 | 74 | <hr /> |
|
75 | 75 | <div id="relations"> |
|
76 | 76 | <%= render :partial => 'relations' %> |
|
77 | 77 | </div> |
|
78 | 78 | <% end %> |
|
79 | 79 | |
|
80 | 80 | </div> |
|
81 | 81 | |
|
82 | 82 | <% if authorize_for('issues', 'change_status') and @status_options and !@status_options.empty? %> |
|
83 | 83 | <% form_tag({:controller => 'issues', :action => 'change_status', :id => @issue}) do %> |
|
84 | 84 | <p><%=l(:label_change_status)%> : |
|
85 | 85 | <select name="new_status_id"> |
|
86 | 86 | <%= options_from_collection_for_select @status_options, "id", "name" %> |
|
87 | 87 | </select> |
|
88 | 88 | <%= submit_tag l(:button_change) %></p> |
|
89 | 89 | <% end %> |
|
90 | 90 | <% end %> |
|
91 | 91 | |
|
92 | 92 | <% if @journals.any? %> |
|
93 | 93 | <div id="history"> |
|
94 | 94 | <h3><%=l(:label_history)%></h3> |
|
95 | 95 | <%= render :partial => 'history', :locals => { :journals => @journals } %> |
|
96 | 96 | </div> |
|
97 | 97 | <% end %> |
|
98 | 98 | |
|
99 | 99 | <% if authorize_for('issues', 'add_note') %> |
|
100 | 100 | <a name="add-note-anchor"></a> |
|
101 | 101 | <div id="add-note" class="box" style="display:none;"> |
|
102 | 102 | <h3><%= l(:label_add_note) %></h3> |
|
103 | 103 | <% form_tag({:controller => 'issues', :action => 'add_note', :id => @issue}, :class => "tabular", :multipart => true) do %> |
|
104 | 104 | <p><label for="notes"><%=l(:field_notes)%></label> |
|
105 | 105 | <%= text_area_tag 'notes', '', :cols => 60, :rows => 10, :class => 'wiki-edit' %></p> |
|
106 | 106 | <%= wikitoolbar_for 'notes' %> |
|
107 | 107 | <%= render :partial => 'attachments/form' %> |
|
108 | 108 | <%= submit_tag l(:button_add) %> |
|
109 | 109 | <%= toggle_link l(:button_cancel), 'add-note' %> |
|
110 | 110 | <% end %> |
|
111 | 111 | </div> |
|
112 | 112 | <% end %> |
|
113 | 113 | |
|
114 | 114 | <div class="contextual"> |
|
115 | 115 | <%= l(:label_export_to) %><%= link_to 'PDF', {:format => 'pdf'}, :class => 'icon icon-pdf' %> |
|
116 | 116 | </div> |
|
117 | 117 | |
|
118 | 118 | |
|
119 | 119 | <% set_html_title "#{@issue.tracker.name} ##{@issue.id}: #{@issue.subject}" %> |
|
120 | 120 | |
|
121 | 121 | <% content_for :sidebar do %> |
|
122 | 122 | <%= render :partial => 'issues/sidebar' %> |
|
123 | 123 | <% end %> |
@@ -1,3 +1,3 | |||
|
1 | 1 | <div class="wiki"> |
|
2 |
<%= textilizable content |
|
|
2 | <%= textilizable content, :text, :attachments => content.page.attachments %> | |
|
3 | 3 | </div> |
@@ -1,14 +1,14 | |||
|
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 | 8 | h1, h2, h3, h4 { font-family: Trebuchet MS,Georgia,"Times New Roman",serif; } |
|
9 | 9 | </style> |
|
10 | 10 | </head> |
|
11 | 11 | <body> |
|
12 |
<%= textilizable @content |
|
|
12 | <%= textilizable @content, :text, :wiki_links => :local %> | |
|
13 | 13 | </body> |
|
14 | 14 | </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 | 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 |
<%= textilizable page.content |
|
|
23 | <%= textilizable page.content ,:text, :wiki_links => :anchor %> | |
|
24 | 24 | <% end %> |
|
25 | 25 | |
|
26 | 26 | </body> |
|
27 | 27 | </html> |
@@ -1,122 +1,160 | |||
|
1 | # redMine - project management software | |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
|
3 | # | |
|
4 | # This program is free software; you can redistribute it and/or | |
|
5 | # modify it under the terms of the GNU General Public License | |
|
6 | # as published by the Free Software Foundation; either version 2 | |
|
7 | # of the License, or (at your option) any later version. | |
|
8 | # | |
|
9 | # This program is distributed in the hope that it will be useful, | |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
12 | # GNU General Public License for more details. | |
|
13 | # | |
|
14 | # You should have received a copy of the GNU General Public License | |
|
15 | # along with this program; if not, write to the Free Software | |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
|
17 | ||
|
1 | 18 | require 'redcloth' |
|
2 | 19 | require 'coderay' |
|
3 | require 'pp' | |
|
20 | ||
|
4 | 21 | module Redmine |
|
5 | 22 | module WikiFormatting |
|
6 | 23 | |
|
7 | 24 | private |
|
8 | 25 | |
|
9 |
class TextileFormatter < RedCloth |
|
|
10 | RULES = [:inline_auto_link, :inline_auto_mailto, :textile, :inline_toc] | |
|
26 | class TextileFormatter < RedCloth | |
|
27 | ||
|
28 | RULES = [:inline_auto_link, :inline_auto_mailto, :textile, :inline_toc, :inline_macros] | |
|
11 | 29 | |
|
12 | 30 | def initialize(*args) |
|
13 | 31 | super |
|
14 | 32 | self.hard_breaks=true |
|
15 | 33 | self.no_span_caps=true |
|
16 | 34 | end |
|
17 | 35 | |
|
18 | def to_html | |
|
36 | def to_html(*rules, &block) | |
|
19 | 37 | @toc = [] |
|
38 | @macros_runner = block | |
|
20 | 39 | super(*RULES).to_s |
|
21 | 40 | end |
|
22 | 41 | |
|
23 | 42 | private |
|
24 | 43 | |
|
25 | 44 | # Patch for RedCloth. Fixed in RedCloth r128 but _why hasn't released it yet. |
|
26 | 45 | # <a href="http://code.whytheluckystiff.net/redcloth/changeset/128">http://code.whytheluckystiff.net/redcloth/changeset/128</a> |
|
27 | 46 | def hard_break( text ) |
|
28 | 47 | text.gsub!( /(.)\n(?!\n|\Z| *([#*=]+(\s|$)|[{|]))/, "\\1<br />" ) if hard_breaks |
|
29 | 48 | end |
|
30 | 49 | |
|
31 | 50 | # Patch to add code highlighting support to RedCloth |
|
32 | 51 | def smooth_offtags( text ) |
|
33 | 52 | unless @pre_list.empty? |
|
34 | 53 | ## replace <pre> content |
|
35 | 54 | text.gsub!(/<redpre#(\d+)>/) do |
|
36 | 55 | content = @pre_list[$1.to_i] |
|
37 | 56 | if content.match(/<code\s+class="(\w+)">\s?(.+)/m) |
|
38 | 57 | content = "<code class=\"#{$1} CodeRay\">" + |
|
39 | 58 | CodeRay.scan($2, $1).html(:escape => false, :line_numbers => :inline) |
|
40 | 59 | end |
|
41 | 60 | content |
|
42 | 61 | end |
|
43 | 62 | end |
|
44 | 63 | end |
|
45 | 64 | |
|
46 | 65 | # Patch to add 'table of content' support to RedCloth |
|
47 | 66 | def textile_p_withtoc(tag, atts, cite, content) |
|
48 | 67 | if tag =~ /^h(\d)$/ |
|
49 | 68 | @toc << [$1.to_i, content] |
|
50 | 69 | end |
|
51 | 70 | content = "<a name=\"#{@toc.length}\" class=\"wiki-page\"></a>" + content |
|
52 | 71 | textile_p(tag, atts, cite, content) |
|
53 | 72 | end |
|
54 | 73 | |
|
55 | 74 | alias :textile_h1 :textile_p_withtoc |
|
56 | 75 | alias :textile_h2 :textile_p_withtoc |
|
57 | 76 | alias :textile_h3 :textile_p_withtoc |
|
58 | 77 | |
|
59 | 78 | def inline_toc(text) |
|
60 | 79 | text.gsub!(/<p>\{\{([<>]?)toc\}\}<\/p>/i) do |
|
61 | 80 | div_class = 'toc' |
|
62 | 81 | div_class << ' right' if $1 == '>' |
|
63 | 82 | div_class << ' left' if $1 == '<' |
|
64 | 83 | out = "<div class=\"#{div_class}\">" |
|
65 | 84 | @toc.each_with_index do |heading, index| |
|
66 | 85 | # remove wiki links from the item |
|
67 | 86 | toc_item = heading.last.gsub(/(\[\[|\]\])/, '') |
|
68 | 87 | out << "<a href=\"##{index+1}\" class=\"heading#{heading.first}\">#{toc_item}</a>" |
|
69 | 88 | end |
|
70 | 89 | out << '</div>' |
|
71 | 90 | out |
|
72 | 91 | end |
|
73 | 92 | end |
|
74 | 93 | |
|
94 | MACROS_RE = / | |
|
95 | \{\{ # opening tag | |
|
96 | ([\w]+) # macro name | |
|
97 | (\(([^\}]*)\))? # optional arguments | |
|
98 | \}\} # closing tag | |
|
99 | /x unless const_defined?(:MACROS_RE) | |
|
100 | ||
|
101 | def inline_macros(text) | |
|
102 | text.gsub!(MACROS_RE) do | |
|
103 | all, macro = $&, $1.downcase | |
|
104 | args = ($3 || '').split(',').each(&:strip) | |
|
105 | begin | |
|
106 | @macros_runner.call(macro, args) | |
|
107 | rescue => e | |
|
108 | "<div class=\"flash error\">Error executing the <strong>#{macro}</strong> macro (#{e})</div>" | |
|
109 | end || all | |
|
110 | end | |
|
111 | end | |
|
112 | ||
|
75 | 113 | AUTO_LINK_RE = %r{ |
|
76 | 114 | ( # leading text |
|
77 | 115 | <\w+.*?>| # leading HTML tag, or |
|
78 | 116 | [^=<>!:'"/]| # leading punctuation, or |
|
79 | 117 | ^ # beginning of line |
|
80 | 118 | ) |
|
81 | 119 | ( |
|
82 | 120 | (?:https?://)| # protocol spec, or |
|
83 | 121 | (?:www\.) # www.* |
|
84 | 122 | ) |
|
85 | 123 | ( |
|
86 | 124 | (\S+?) # url |
|
87 | 125 | (\/)? # slash |
|
88 | 126 | ) |
|
89 | 127 | ([^\w\=\/;]*?) # post |
|
90 | 128 | (?=<|\s|$) |
|
91 | 129 | }x unless const_defined?(:AUTO_LINK_RE) |
|
92 | 130 | |
|
93 | 131 | # Turns all urls into clickable links (code from Rails). |
|
94 | 132 | def inline_auto_link(text) |
|
95 | 133 | text.gsub!(AUTO_LINK_RE) do |
|
96 | 134 | all, leading, proto, url, post = $&, $1, $2, $3, $6 |
|
97 | 135 | if leading =~ /<a\s/i || leading =~ /![<>=]?/ |
|
98 | 136 | # don't replace URL's that are already linked |
|
99 | 137 | # and URL's prefixed with ! !> !< != (textile images) |
|
100 | 138 | all |
|
101 | 139 | else |
|
102 | 140 | %(#{leading}<a class="external" href="#{proto=="www."?"http://www.":proto}#{url}">#{proto + url}</a>#{post}) |
|
103 | 141 | end |
|
104 | 142 | end |
|
105 | 143 | end |
|
106 | 144 | |
|
107 | 145 | # Turns all email addresses into clickable links (code from Rails). |
|
108 | 146 | def inline_auto_mailto(text) |
|
109 | 147 | text.gsub!(/([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/) do |
|
110 | 148 | text = $1 |
|
111 | 149 | %{<a href="mailto:#{$1}" class="email">#{text}</a>} |
|
112 | 150 | end |
|
113 | 151 | end |
|
114 | 152 | end |
|
115 | 153 | |
|
116 | 154 | public |
|
117 | 155 | |
|
118 | def self.to_html(text, options = {}) | |
|
119 |
TextileFormatter.new(text).to_html |
|
|
156 | def self.to_html(text, options = {}, &block) | |
|
157 | TextileFormatter.new(text).to_html(&block) | |
|
120 | 158 | end |
|
121 | 159 | end |
|
122 | 160 | end |
@@ -1,73 +1,78 | |||
|
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, :repositories, :changesets, :trackers, :issue_statuses, :issues |
|
24 | 24 | |
|
25 | 25 | def setup |
|
26 | 26 | super |
|
27 | 27 | end |
|
28 | 28 | |
|
29 | 29 | def test_auto_links |
|
30 | 30 | to_test = { |
|
31 | 31 | 'http://foo.bar' => '<a class="external" href="http://foo.bar">http://foo.bar</a>', |
|
32 | 32 | 'http://foo.bar/~user' => '<a class="external" href="http://foo.bar/~user">http://foo.bar/~user</a>', |
|
33 | 33 | 'http://foo.bar.' => '<a class="external" href="http://foo.bar">http://foo.bar</a>.', |
|
34 | 34 | '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>.', |
|
35 | 35 | 'www.foo.bar' => '<a class="external" href="http://www.foo.bar">www.foo.bar</a>', |
|
36 | 36 | '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>', |
|
37 | 37 | 'http://foo.bar/page#125' => '<a class="external" href="http://foo.bar/page#125">http://foo.bar/page#125</a>' |
|
38 | 38 | } |
|
39 | 39 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
40 | 40 | end |
|
41 | 41 | |
|
42 | 42 | def test_auto_mailto |
|
43 | 43 | assert_equal '<p><a href="mailto:test@foo.bar" class="email">test@foo.bar</a></p>', |
|
44 | 44 | textilizable('test@foo.bar') |
|
45 | 45 | end |
|
46 | 46 | |
|
47 | 47 | def test_textile_tags |
|
48 | 48 | to_test = { |
|
49 | 49 | # inline images |
|
50 | 50 | '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />', |
|
51 | 51 | 'floating !>http://foo.bar/image.jpg!' => 'floating <div style="float:right"><img src="http://foo.bar/image.jpg" alt="" /></div>', |
|
52 | 52 | # textile links |
|
53 | 53 | 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>', |
|
54 | 54 | 'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>', |
|
55 | 55 | '"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>' |
|
56 | 56 | } |
|
57 | 57 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
58 | 58 | end |
|
59 | 59 | |
|
60 | 60 | def test_redmine_links |
|
61 | 61 | issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3}, |
|
62 | 62 | :class => 'issue', :title => 'Error 281 when updating a recipe (New)') |
|
63 | 63 | changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 1, :rev => 1}, |
|
64 | 64 | :class => 'changeset', :title => 'My very first commit') |
|
65 | 65 | |
|
66 | 66 | to_test = { |
|
67 | 67 | '#3, #3 and #3.' => "#{issue_link}, #{issue_link} and #{issue_link}.", |
|
68 | 68 | 'r1' => changeset_link |
|
69 | 69 | } |
|
70 | 70 | @project = Project.find(1) |
|
71 | 71 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
72 | 72 | end |
|
73 | ||
|
74 | def test_macro_hello_world | |
|
75 | text = "{{hello_world}}" | |
|
76 | assert textilizable(text).match(/Hello world!/) | |
|
77 | end | |
|
73 | 78 | end |
General Comments 0
You need to be logged in to leave comments.
Login now