From 0dc98aabe6352df8875c3a02b6326d0c96fad0c7 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Mon, 23 Dec 2013 12:33:42 +0000 Subject: [PATCH] Adds an option for formatter display name. git-svn-id: http://svn.redmine.org/redmine/trunk@12450 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/views/settings/_general.html.erb | 2 +- lib/redmine/wiki_formatting.rb | 15 ++++++++++++--- test/unit/lib/redmine/wiki_formatting_test.rb | 4 ++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/views/settings/_general.html.erb b/app/views/settings/_general.html.erb index 4ec01995a..9cba46ccb 100644 --- a/app/views/settings/_general.html.erb +++ b/app/views/settings/_general.html.erb @@ -18,7 +18,7 @@

<%= setting_select :protocol, [['HTTP', 'http'], ['HTTPS', 'https']] %>

-

<%= setting_select :text_formatting, Redmine::WikiFormatting.format_names.collect{|name| [name, name.to_s]}, :blank => :label_none %>

+

<%= setting_select :text_formatting, Redmine::WikiFormatting.formats_for_select, :blank => :label_none %>

<%= setting_check_box :cache_formatted_text %>

diff --git a/lib/redmine/wiki_formatting.rb b/lib/redmine/wiki_formatting.rb index 9a62bf6b8..748e366e7 100644 --- a/lib/redmine/wiki_formatting.rb +++ b/lib/redmine/wiki_formatting.rb @@ -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 diff --git a/test/unit/lib/redmine/wiki_formatting_test.rb b/test/unit/lib/redmine/wiki_formatting_test.rb index a799c6c78..e8a457c9d 100644 --- a/test/unit/lib/redmine/wiki_formatting_test.rb +++ b/test/unit/lib/redmine/wiki_formatting_test.rb @@ -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