##// END OF EJS Templates
remove trailing white-spaces from application helper source....
Toshi MARUYAMA -
r5712:c42fdcd26abe
parent child
Show More
@@ -63,7 +63,7 module ApplicationHelper
63
63
64 # Displays a link to +issue+ with its subject.
64 # Displays a link to +issue+ with its subject.
65 # Examples:
65 # Examples:
66 #
66 #
67 # link_to_issue(issue) # => Defect #6: This is the subject
67 # link_to_issue(issue) # => Defect #6: This is the subject
68 # link_to_issue(issue, :truncate => 6) # => Defect #6: This i...
68 # link_to_issue(issue, :truncate => 6) # => Defect #6: This i...
69 # link_to_issue(issue, :subject => false) # => Defect #6
69 # link_to_issue(issue, :subject => false) # => Defect #6
@@ -80,7 +80,7 module ApplicationHelper
80 subject = truncate(subject, :length => options[:truncate])
80 subject = truncate(subject, :length => options[:truncate])
81 end
81 end
82 end
82 end
83 s = link_to "#{issue.tracker} ##{issue.id}", {:controller => "issues", :action => "show", :id => issue},
83 s = link_to "#{issue.tracker} ##{issue.id}", {:controller => "issues", :action => "show", :id => issue},
84 :class => issue.css_classes,
84 :class => issue.css_classes,
85 :title => title
85 :title => title
86 s << ": #{h subject}" if subject
86 s << ": #{h subject}" if subject
@@ -109,7 +109,7 module ApplicationHelper
109 link_to(text, {:controller => 'repositories', :action => 'revision', :id => project, :rev => rev},
109 link_to(text, {:controller => 'repositories', :action => 'revision', :id => project, :rev => rev},
110 :title => l(:label_revision_id, format_revision(revision)))
110 :title => l(:label_revision_id, format_revision(revision)))
111 end
111 end
112
112
113 # Generates a link to a message
113 # Generates a link to a message
114 def link_to_message(message, options={}, html_options = nil)
114 def link_to_message(message, options={}, html_options = nil)
115 link_to(
115 link_to(
@@ -126,7 +126,7 module ApplicationHelper
126
126
127 # Generates a link to a project if active
127 # Generates a link to a project if active
128 # Examples:
128 # Examples:
129 #
129 #
130 # link_to_project(project) # => link to the specified project overview
130 # link_to_project(project) # => link to the specified project overview
131 # link_to_project(project, :action=>'settings') # => link to project settings
131 # link_to_project(project, :action=>'settings') # => link to project settings
132 # link_to_project(project, {:only_path => false}, :class => "project") # => 3rd arg adds html options
132 # link_to_project(project, {:only_path => false}, :class => "project") # => 3rd arg adds html options
@@ -160,15 +160,15 module ApplicationHelper
160 html_options[:onclick] = "promptToRemote('#{text}', '#{param}', '#{url_for(url)}'); return false;"
160 html_options[:onclick] = "promptToRemote('#{text}', '#{param}', '#{url_for(url)}'); return false;"
161 link_to name, {}, html_options
161 link_to name, {}, html_options
162 end
162 end
163
163
164 def format_activity_title(text)
164 def format_activity_title(text)
165 h(truncate_single_line(text, :length => 100))
165 h(truncate_single_line(text, :length => 100))
166 end
166 end
167
167
168 def format_activity_day(date)
168 def format_activity_day(date)
169 date == Date.today ? l(:label_today).titleize : format_date(date)
169 date == Date.today ? l(:label_today).titleize : format_date(date)
170 end
170 end
171
171
172 def format_activity_description(text)
172 def format_activity_description(text)
173 h(truncate(text.to_s, :length => 120).gsub(%r{[\r\n]*<(pre|code)>.*$}m, '...')).gsub(/[\r\n]+/, "<br />")
173 h(truncate(text.to_s, :length => 120).gsub(%r{[\r\n]*<(pre|code)>.*$}m, '...')).gsub(/[\r\n]+/, "<br />")
174 end
174 end
@@ -180,7 +180,7 module ApplicationHelper
180 h("#{version.project} - #{version}")
180 h("#{version.project} - #{version}")
181 end
181 end
182 end
182 end
183
183
184 def due_date_distance_in_words(date)
184 def due_date_distance_in_words(date)
185 if date
185 if date
186 l((date < Date.today ? :label_roadmap_overdue : :label_roadmap_due_in), distance_of_date_in_words(Date.today, date))
186 l((date < Date.today ? :label_roadmap_overdue : :label_roadmap_due_in), distance_of_date_in_words(Date.today, date))
@@ -202,7 +202,7 module ApplicationHelper
202 end
202 end
203 content
203 content
204 end
204 end
205
205
206 # Renders flash messages
206 # Renders flash messages
207 def render_flash_messages
207 def render_flash_messages
208 s = ''
208 s = ''
@@ -211,7 +211,7 module ApplicationHelper
211 end
211 end
212 s
212 s
213 end
213 end
214
214
215 # Renders tabs and their content
215 # Renders tabs and their content
216 def render_tabs(tabs)
216 def render_tabs(tabs)
217 if tabs.any?
217 if tabs.any?
@@ -220,7 +220,7 module ApplicationHelper
220 content_tag 'p', l(:label_no_data), :class => "nodata"
220 content_tag 'p', l(:label_no_data), :class => "nodata"
221 end
221 end
222 end
222 end
223
223
224 # Renders the project quick-jump box
224 # Renders the project quick-jump box
225 def render_project_jump_box
225 def render_project_jump_box
226 return unless User.current.logged?
226 return unless User.current.logged?
@@ -236,7 +236,7 module ApplicationHelper
236 s
236 s
237 end
237 end
238 end
238 end
239
239
240 def project_tree_options_for_select(projects, options = {})
240 def project_tree_options_for_select(projects, options = {})
241 s = ''
241 s = ''
242 project_tree(projects) do |project, level|
242 project_tree(projects) do |project, level|
@@ -252,14 +252,14 module ApplicationHelper
252 end
252 end
253 s
253 s
254 end
254 end
255
255
256 # Yields the given block for each project with its level in the tree
256 # Yields the given block for each project with its level in the tree
257 #
257 #
258 # Wrapper for Project#project_tree
258 # Wrapper for Project#project_tree
259 def project_tree(projects, &block)
259 def project_tree(projects, &block)
260 Project.project_tree(projects, &block)
260 Project.project_tree(projects, &block)
261 end
261 end
262
262
263 def project_nested_ul(projects, &block)
263 def project_nested_ul(projects, &block)
264 s = ''
264 s = ''
265 if projects.any?
265 if projects.any?
@@ -270,7 +270,7 module ApplicationHelper
270 else
270 else
271 ancestors.pop
271 ancestors.pop
272 s << "</li>"
272 s << "</li>"
273 while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
273 while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
274 ancestors.pop
274 ancestors.pop
275 s << "</ul></li>\n"
275 s << "</ul></li>\n"
276 end
276 end
@@ -283,20 +283,20 module ApplicationHelper
283 end
283 end
284 s
284 s
285 end
285 end
286
286
287 def principals_check_box_tags(name, principals)
287 def principals_check_box_tags(name, principals)
288 s = ''
288 s = ''
289 principals.sort.each do |principal|
289 principals.sort.each do |principal|
290 s << "<label>#{ check_box_tag name, principal.id, false } #{h principal}</label>\n"
290 s << "<label>#{ check_box_tag name, principal.id, false } #{h principal}</label>\n"
291 end
291 end
292 s
292 s
293 end
293 end
294
294
295 # Truncates and returns the string as a single line
295 # Truncates and returns the string as a single line
296 def truncate_single_line(string, *args)
296 def truncate_single_line(string, *args)
297 truncate(string.to_s, *args).gsub(%r{[\r\n]+}m, ' ')
297 truncate(string.to_s, *args).gsub(%r{[\r\n]+}m, ' ')
298 end
298 end
299
299
300 # Truncates at line break after 250 characters or options[:length]
300 # Truncates at line break after 250 characters or options[:length]
301 def truncate_lines(string, options={})
301 def truncate_lines(string, options={})
302 length = options[:length] || 250
302 length = options[:length] || 250
@@ -314,7 +314,7 module ApplicationHelper
314 def authoring(created, author, options={})
314 def authoring(created, author, options={})
315 l(options[:label] || :label_added_time_by, :author => link_to_user(author), :age => time_tag(created))
315 l(options[:label] || :label_added_time_by, :author => link_to_user(author), :age => time_tag(created))
316 end
316 end
317
317
318 def time_tag(time)
318 def time_tag(time)
319 text = distance_of_time_in_words(Time.now, time)
319 text = distance_of_time_in_words(Time.now, time)
320 if @project
320 if @project
@@ -345,7 +345,7 module ApplicationHelper
345 html << (pagination_links_each(paginator, options) do |n|
345 html << (pagination_links_each(paginator, options) do |n|
346 link_to_content_update(n.to_s, url_param.merge(page_param => n))
346 link_to_content_update(n.to_s, url_param.merge(page_param => n))
347 end || '')
347 end || '')
348
348
349 if paginator.current.next
349 if paginator.current.next
350 html << ' ' + link_to_content_update((l(:label_next) + ' &#187;'), url_param.merge(page_param => paginator.current.next))
350 html << ' ' + link_to_content_update((l(:label_next) + ' &#187;'), url_param.merge(page_param => paginator.current.next))
351 end
351 end
@@ -359,14 +359,14 module ApplicationHelper
359
359
360 html
360 html
361 end
361 end
362
362
363 def per_page_links(selected=nil)
363 def per_page_links(selected=nil)
364 links = Setting.per_page_options_array.collect do |n|
364 links = Setting.per_page_options_array.collect do |n|
365 n == selected ? n : link_to_content_update(n, params.merge(:per_page => n))
365 n == selected ? n : link_to_content_update(n, params.merge(:per_page => n))
366 end
366 end
367 links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil
367 links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil
368 end
368 end
369
369
370 def reorder_links(name, url)
370 def reorder_links(name, url)
371 link_to(image_tag('2uparrow.png', :alt => l(:label_sort_highest)), url.merge({"#{name}[move_to]" => 'highest'}), :method => :post, :title => l(:label_sort_highest)) +
371 link_to(image_tag('2uparrow.png', :alt => l(:label_sort_highest)), url.merge({"#{name}[move_to]" => 'highest'}), :method => :post, :title => l(:label_sort_highest)) +
372 link_to(image_tag('1uparrow.png', :alt => l(:label_sort_higher)), url.merge({"#{name}[move_to]" => 'higher'}), :method => :post, :title => l(:label_sort_higher)) +
372 link_to(image_tag('1uparrow.png', :alt => l(:label_sort_higher)), url.merge({"#{name}[move_to]" => 'higher'}), :method => :post, :title => l(:label_sort_higher)) +
@@ -378,13 +378,13 module ApplicationHelper
378 elements = args.flatten
378 elements = args.flatten
379 elements.any? ? content_tag('p', args.join(' &#187; ') + ' &#187; ', :class => 'breadcrumb') : nil
379 elements.any? ? content_tag('p', args.join(' &#187; ') + ' &#187; ', :class => 'breadcrumb') : nil
380 end
380 end
381
381
382 def other_formats_links(&block)
382 def other_formats_links(&block)
383 concat('<p class="other-formats">' + l(:label_export_to))
383 concat('<p class="other-formats">' + l(:label_export_to))
384 yield Redmine::Views::OtherFormatsBuilder.new(self)
384 yield Redmine::Views::OtherFormatsBuilder.new(self)
385 concat('</p>')
385 concat('</p>')
386 end
386 end
387
387
388 def page_header_title
388 def page_header_title
389 if @project.nil? || @project.new_record?
389 if @project.nil? || @project.new_record?
390 h(Setting.app_title)
390 h(Setting.app_title)
@@ -457,21 +457,21 module ApplicationHelper
457 only_path = options.delete(:only_path) == false ? false : true
457 only_path = options.delete(:only_path) == false ? false : true
458
458
459 text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) { |macro, args| exec_macro(macro, obj, args) }
459 text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) { |macro, args| exec_macro(macro, obj, args) }
460
460
461 @parsed_headings = []
461 @parsed_headings = []
462 text = parse_non_pre_blocks(text) do |text|
462 text = parse_non_pre_blocks(text) do |text|
463 [:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links, :parse_headings].each do |method_name|
463 [:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links, :parse_headings].each do |method_name|
464 send method_name, text, project, obj, attr, only_path, options
464 send method_name, text, project, obj, attr, only_path, options
465 end
465 end
466 end
466 end
467
467
468 if @parsed_headings.any?
468 if @parsed_headings.any?
469 replace_toc(text, @parsed_headings)
469 replace_toc(text, @parsed_headings)
470 end
470 end
471
471
472 text
472 text
473 end
473 end
474
474
475 def parse_non_pre_blocks(text)
475 def parse_non_pre_blocks(text)
476 s = StringScanner.new(text)
476 s = StringScanner.new(text)
477 tags = []
477 tags = []
@@ -500,13 +500,13 module ApplicationHelper
500 end
500 end
501 parsed
501 parsed
502 end
502 end
503
503
504 def parse_inline_attachments(text, project, obj, attr, only_path, options)
504 def parse_inline_attachments(text, project, obj, attr, only_path, options)
505 # when using an image link, try to use an attachment, if possible
505 # when using an image link, try to use an attachment, if possible
506 if options[:attachments] || (obj && obj.respond_to?(:attachments))
506 if options[:attachments] || (obj && obj.respond_to?(:attachments))
507 attachments = nil
507 attachments = nil
508 text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m|
508 text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m|
509 filename, ext, alt, alttext = $1.downcase, $2, $3, $4
509 filename, ext, alt, alttext = $1.downcase, $2, $3, $4
510 attachments ||= (options[:attachments] || obj.attachments).sort_by(&:created_on).reverse
510 attachments ||= (options[:attachments] || obj.attachments).sort_by(&:created_on).reverse
511 # search for the picture in attachments
511 # search for the picture in attachments
512 if found = attachments.detect { |att| att.filename.downcase == filename }
512 if found = attachments.detect { |att| att.filename.downcase == filename }
@@ -569,7 +569,7 module ApplicationHelper
569 end
569 end
570 end
570 end
571 end
571 end
572
572
573 # Redmine links
573 # Redmine links
574 #
574 #
575 # Examples:
575 # Examples:
@@ -692,14 +692,14 module ApplicationHelper
692 leading + (link || "#{project_prefix}#{prefix}#{sep}#{identifier}")
692 leading + (link || "#{project_prefix}#{prefix}#{sep}#{identifier}")
693 end
693 end
694 end
694 end
695
695
696 HEADING_RE = /<h(1|2|3|4)( [^>]+)?>(.+?)<\/h(1|2|3|4)>/i unless const_defined?(:HEADING_RE)
696 HEADING_RE = /<h(1|2|3|4)( [^>]+)?>(.+?)<\/h(1|2|3|4)>/i unless const_defined?(:HEADING_RE)
697
697
698 # Headings and TOC
698 # Headings and TOC
699 # Adds ids and links to headings unless options[:headings] is set to false
699 # Adds ids and links to headings unless options[:headings] is set to false
700 def parse_headings(text, project, obj, attr, only_path, options)
700 def parse_headings(text, project, obj, attr, only_path, options)
701 return if options[:headings] == false
701 return if options[:headings] == false
702
702
703 text.gsub!(HEADING_RE) do
703 text.gsub!(HEADING_RE) do
704 level, attrs, content = $1.to_i, $2, $3
704 level, attrs, content = $1.to_i, $2, $3
705 item = strip_tags(content).strip
705 item = strip_tags(content).strip
@@ -708,9 +708,9 module ApplicationHelper
708 "<a name=\"#{anchor}\"></a>\n<h#{level} #{attrs}>#{content}<a href=\"##{anchor}\" class=\"wiki-anchor\">&para;</a></h#{level}>"
708 "<a name=\"#{anchor}\"></a>\n<h#{level} #{attrs}>#{content}<a href=\"##{anchor}\" class=\"wiki-anchor\">&para;</a></h#{level}>"
709 end
709 end
710 end
710 end
711
711
712 TOC_RE = /<p>\{\{([<>]?)toc\}\}<\/p>/i unless const_defined?(:TOC_RE)
712 TOC_RE = /<p>\{\{([<>]?)toc\}\}<\/p>/i unless const_defined?(:TOC_RE)
713
713
714 # Renders the TOC with given headings
714 # Renders the TOC with given headings
715 def replace_toc(text, headings)
715 def replace_toc(text, headings)
716 text.gsub!(TOC_RE) do
716 text.gsub!(TOC_RE) do
@@ -793,13 +793,13 module ApplicationHelper
793 ), :class => 'progress', :style => "width: #{width};") +
793 ), :class => 'progress', :style => "width: #{width};") +
794 content_tag('p', legend, :class => 'pourcent')
794 content_tag('p', legend, :class => 'pourcent')
795 end
795 end
796
796
797 def checked_image(checked=true)
797 def checked_image(checked=true)
798 if checked
798 if checked
799 image_tag 'toggle_check.png'
799 image_tag 'toggle_check.png'
800 end
800 end
801 end
801 end
802
802
803 def context_menu(url)
803 def context_menu(url)
804 unless @context_menu_included
804 unless @context_menu_included
805 content_for :header_tags do
805 content_for :header_tags do
@@ -852,10 +852,10 module ApplicationHelper
852 else
852 else
853 '' # use language
853 '' # use language
854 end
854 end
855
855
856 javascript_include_tag('calendar/calendar') +
856 javascript_include_tag('calendar/calendar') +
857 javascript_include_tag("calendar/lang/calendar-#{current_language.to_s.downcase}.js") +
857 javascript_include_tag("calendar/lang/calendar-#{current_language.to_s.downcase}.js") +
858 javascript_tag(start_of_week) +
858 javascript_tag(start_of_week) +
859 javascript_include_tag('calendar/calendar-setup') +
859 javascript_include_tag('calendar/calendar-setup') +
860 stylesheet_link_tag('calendar')
860 stylesheet_link_tag('calendar')
861 end
861 end
@@ -888,7 +888,7 module ApplicationHelper
888 ''
888 ''
889 end
889 end
890 end
890 end
891
891
892 # Returns the javascript tags that are included in the html layout head
892 # Returns the javascript tags that are included in the html layout head
893 def javascript_heads
893 def javascript_heads
894 tags = javascript_include_tag(:defaults)
894 tags = javascript_include_tag(:defaults)
@@ -905,7 +905,7 module ApplicationHelper
905 def robot_exclusion_tag
905 def robot_exclusion_tag
906 '<meta name="robots" content="noindex,follow,noarchive" />'
906 '<meta name="robots" content="noindex,follow,noarchive" />'
907 end
907 end
908
908
909 # Returns true if arg is expected in the API response
909 # Returns true if arg is expected in the API response
910 def include_in_api_response?(arg)
910 def include_in_api_response?(arg)
911 unless @included_in_api_response
911 unless @included_in_api_response
@@ -927,7 +927,7 module ApplicationHelper
927 options
927 options
928 end
928 end
929 end
929 end
930
930
931 private
931 private
932
932
933 def wiki_helper
933 def wiki_helper
@@ -935,7 +935,7 module ApplicationHelper
935 extend helper
935 extend helper
936 return self
936 return self
937 end
937 end
938
938
939 def link_to_content_update(text, url_params = {}, html_options = {})
939 def link_to_content_update(text, url_params = {}, html_options = {})
940 link_to(text, url_params, html_options)
940 link_to(text, url_params, html_options)
941 end
941 end
General Comments 0
You need to be logged in to leave comments. Login now