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