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