Adds an option for formatter display name.

git-svn-id: http://svn.redmine.org/redmine/trunk@12450 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2013-12-23 12:33:42 +00:00
parent 0fabbd281e
commit 0dc98aabe6
3 changed files with 17 additions and 4 deletions

View File

@ -18,7 +18,7 @@
<p><%= setting_select :protocol, [['HTTP', 'http'], ['HTTPS', 'https']] %></p>
<p><%= setting_select :text_formatting, Redmine::WikiFormatting.format_names.collect{|name| [name, name.to_s]}, :blank => :label_none %></p>
<p><%= setting_select :text_formatting, Redmine::WikiFormatting.formats_for_select, :blank => :label_none %></p>
<p><%= setting_check_box :cache_formatted_text %></p>

View File

@ -28,9 +28,14 @@ module Redmine
yield self
end
def register(name, formatter, helper)
raise ArgumentError, "format name '#{name}' is already taken" if @@formatters[name.to_s]
@@formatters[name.to_s] = {:formatter => formatter, :helper => helper}
def register(name, formatter, helper, options={})
name = name.to_s
raise ArgumentError, "format name '#{name}' is already taken" if @@formatters[name]
@@formatters[name] = {
:formatter => formatter,
:helper => helper,
:label => options[:label] || name.humanize
}
end
def formatter
@ -51,6 +56,10 @@ module Redmine
@@formatters.keys.map
end
def formats_for_select
@@formatters.map {|name, options| [options[:label], name]}
end
def to_html(format, text, options = {})
text = if Setting.cache_formatted_text? && text.size > 2.kilobyte && cache_store && cache_key = cache_key_for(format, text, options[:object], options[:attribute])
# Text retrieved from the cache store may be frozen

View File

@ -30,6 +30,10 @@ class Redmine::WikiFormattingTest < ActiveSupport::TestCase
assert_equal Redmine::WikiFormatting::NullFormatter::Helper, Redmine::WikiFormatting.helper_for('')
end
def test_formats_for_select
assert_include ['Textile', 'textile'], Redmine::WikiFormatting.formats_for_select
end
def test_should_link_urls_and_email_addresses
raw = <<-DIFF
This is a sample *text* with a link: http://www.redmine.org