comparison app/helpers/.svn/text-base/application_helper.rb.svn-base @ 119:8661b858af72

* Update to Redmine trunk rev 4705
author Chris Cannam
date Thu, 13 Jan 2011 14:12:06 +0000
parents 94944d00e43c
children cd2282d2aa55 0579821a129a
comparison
equal deleted inserted replaced
39:150ceac17a8d 119:8661b858af72
102 # Generates a link to a SCM revision 102 # Generates a link to a SCM revision
103 # Options: 103 # Options:
104 # * :text - Link text (default to the formatted revision) 104 # * :text - Link text (default to the formatted revision)
105 def link_to_revision(revision, project, options={}) 105 def link_to_revision(revision, project, options={})
106 text = options.delete(:text) || format_revision(revision) 106 text = options.delete(:text) || format_revision(revision)
107 107 rev = revision.respond_to?(:identifier) ? revision.identifier : revision
108 link_to(text, {:controller => 'repositories', :action => 'revision', :id => project, :rev => revision}, :title => l(:label_revision_id, revision)) 108
109 link_to(text, {:controller => 'repositories', :action => 'revision', :id => project, :rev => rev},
110 :title => l(:label_revision_id, format_revision(revision)))
109 end 111 end
110 112
111 # Generates a link to a project if active 113 # Generates a link to a project if active
112 # Examples: 114 # Examples:
113 # 115 #
447 return '' if text.blank? 449 return '' if text.blank?
448 project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil) 450 project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
449 only_path = options.delete(:only_path) == false ? false : true 451 only_path = options.delete(:only_path) == false ? false : true
450 452
451 text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) { |macro, args| exec_macro(macro, obj, args) } 453 text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) { |macro, args| exec_macro(macro, obj, args) }
452 454
453 parse_non_pre_blocks(text) do |text| 455 @parsed_headings = []
456 text = parse_non_pre_blocks(text) do |text|
454 [:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links, :parse_headings].each do |method_name| 457 [:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links, :parse_headings].each do |method_name|
455 send method_name, text, project, obj, attr, only_path, options 458 send method_name, text, project, obj, attr, only_path, options
456 end 459 end
457 end 460 end
461
462 if @parsed_headings.any?
463 replace_toc(text, @parsed_headings)
464 end
465
466 text
458 end 467 end
459 468
460 def parse_non_pre_blocks(text) 469 def parse_non_pre_blocks(text)
461 s = StringScanner.new(text) 470 s = StringScanner.new(text)
462 tags = [] 471 tags = []
640 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version}, 649 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
641 :class => 'version' 650 :class => 'version'
642 end 651 end
643 when 'commit' 652 when 'commit'
644 if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"])) 653 if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
645 link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision}, 654 link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.identifier},
646 :class => 'changeset', 655 :class => 'changeset',
647 :title => truncate_single_line(changeset.comments, :length => 100) 656 :title => truncate_single_line(changeset.comments, :length => 100)
648 end 657 end
649 when 'source', 'export' 658 when 'source', 'export'
650 if project && project.repository 659 if project && project.repository
672 end 681 end
673 leading + (link || "#{prefix}#{sep}#{identifier}") 682 leading + (link || "#{prefix}#{sep}#{identifier}")
674 end 683 end
675 end 684 end
676 685
677 TOC_RE = /<p>\{\{([<>]?)toc\}\}<\/p>/i unless const_defined?(:TOC_RE)
678 HEADING_RE = /<h(1|2|3|4)( [^>]+)?>(.+?)<\/h(1|2|3|4)>/i unless const_defined?(:HEADING_RE) 686 HEADING_RE = /<h(1|2|3|4)( [^>]+)?>(.+?)<\/h(1|2|3|4)>/i unless const_defined?(:HEADING_RE)
679 687
680 # Headings and TOC 688 # Headings and TOC
681 # Adds ids and links to headings and renders the TOC if needed unless options[:headings] is set to false 689 # Adds ids and links to headings unless options[:headings] is set to false
682 def parse_headings(text, project, obj, attr, only_path, options) 690 def parse_headings(text, project, obj, attr, only_path, options)
683 headings = [] 691 return if options[:headings] == false
692
684 text.gsub!(HEADING_RE) do 693 text.gsub!(HEADING_RE) do
685 level, attrs, content = $1.to_i, $2, $3 694 level, attrs, content = $1.to_i, $2, $3
686 item = strip_tags(content).strip 695 item = strip_tags(content).strip
687 anchor = item.gsub(%r{[^\w\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-') 696 anchor = item.gsub(%r{[^\w\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-')
688 headings << [level, anchor, item] 697 @parsed_headings << [level, anchor, item]
689 "<h#{level} #{attrs} id=\"#{anchor}\">#{content}<a href=\"##{anchor}\" class=\"wiki-anchor\">&para;</a></h#{level}>" 698 "<h#{level} #{attrs} id=\"#{anchor}\">#{content}<a href=\"##{anchor}\" class=\"wiki-anchor\">&para;</a></h#{level}>"
690 end unless options[:headings] == false 699 end
691 700 end
701
702 TOC_RE = /<p>\{\{([<>]?)toc\}\}<\/p>/i unless const_defined?(:TOC_RE)
703
704 # Renders the TOC with given headings
705 def replace_toc(text, headings)
692 text.gsub!(TOC_RE) do 706 text.gsub!(TOC_RE) do
693 if headings.empty? 707 if headings.empty?
694 '' 708 ''
695 else 709 else
696 div_class = 'toc' 710 div_class = 'toc'
864 end 878 end
865 879
866 def favicon 880 def favicon
867 "<link rel='shortcut icon' href='#{image_path('/favicon.ico')}' />" 881 "<link rel='shortcut icon' href='#{image_path('/favicon.ico')}' />"
868 end 882 end
869 883
884 # Returns true if arg is expected in the API response
885 def include_in_api_response?(arg)
886 unless @included_in_api_response
887 param = params[:include]
888 @included_in_api_response = param.is_a?(Array) ? param.collect(&:to_s) : param.to_s.split(',')
889 @included_in_api_response.collect!(&:strip)
890 end
891 @included_in_api_response.include?(arg.to_s)
892 end
893
894 # Returns options or nil if nometa param or X-Redmine-Nometa header
895 # was set in the request
896 def api_meta(options)
897 if params[:nometa].present? || request.headers['X-Redmine-Nometa']
898 # compatibility mode for activeresource clients that raise
899 # an error when unserializing an array with attributes
900 nil
901 else
902 options
903 end
904 end
905
870 private 906 private
871 907
872 def wiki_helper 908 def wiki_helper
873 helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting) 909 helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting)
874 extend helper 910 extend helper