Change the case statement into a method call based on the name
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3674 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
d22723ed04
commit
4cb943571a
|
@ -30,6 +30,24 @@ module Redmine
|
||||||
self.order = options[:order]
|
self.order = options[:order]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def format(value)
|
||||||
|
send "format_as_#{name}", value
|
||||||
|
end
|
||||||
|
|
||||||
|
def format_as_date(value)
|
||||||
|
begin; format_date(value.to_date); rescue; value end
|
||||||
|
end
|
||||||
|
|
||||||
|
def format_as_bool(value)
|
||||||
|
l(value == "1" ? :general_text_Yes : :general_text_No)
|
||||||
|
end
|
||||||
|
|
||||||
|
['string','text','int','float','list'].each do |name|
|
||||||
|
define_method("format_as_#{name}") {|value|
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def map(&block)
|
def map(&block)
|
||||||
yield self
|
yield self
|
||||||
|
@ -64,11 +82,9 @@ module Redmine
|
||||||
|
|
||||||
def format_value(value, field_format)
|
def format_value(value, field_format)
|
||||||
return "" unless value && !value.empty?
|
return "" unless value && !value.empty?
|
||||||
case field_format
|
|
||||||
when "date"
|
if format_type = find_by_name(field_format)
|
||||||
begin; format_date(value.to_date); rescue; value end
|
format_type.format(value)
|
||||||
when "bool"
|
|
||||||
l(value == "1" ? :general_text_Yes : :general_text_No)
|
|
||||||
else
|
else
|
||||||
value
|
value
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue