remove definition of l() from Widget, we include ReportingHelper for good

pull/6827/head
Tim Felgentreff 14 years ago
parent 970454d914
commit 6ebb599cbd
  1. 19
      lib/reporting_helper.rb
  2. 6
      lib/widget.rb

@ -0,0 +1,19 @@
##
# A minimal ReportingHelper module. This is included in Widget and
# Controller and can be used to extend the specific widgets and
# controller functionality.
#
# It is the default hook for translations, and calls to l() in Widgets
# or Controllers will go to this module, first. The default behavior
# is to pass translation work on to I18n.t() or I18n.l(), depending on
# the type of arguments.
module ReportingHelper
def l(*values)
return values.first if values.size == 1 and values.first.respond_to? :to_str
if [Date, DateTime, Time].include? values.first.class
::I18n.l(values.first)
else
::I18n.t(*values)
end
end
end

@ -3,6 +3,7 @@ class Widget < ActionView::Base
include ActionView::Helpers::AssetTagHelper include ActionView::Helpers::AssetTagHelper
include ActionView::Helpers::FormTagHelper include ActionView::Helpers::FormTagHelper
include ActionView::Helpers::JavaScriptHelper include ActionView::Helpers::JavaScriptHelper
include ReportingHelper
attr_accessor :output_buffer, :controller, :config, :_content_for, :_routes, :subject attr_accessor :output_buffer, :controller, :config, :_content_for, :_routes, :subject
@ -14,11 +15,6 @@ class Widget < ActionView::Base
end end
end end
# FIXME: There's a better one in ReportingHelper, remove this one
def l(s)
::I18n.t(s.to_sym, :default => s.to_s.humanize)
end
def current_language def current_language
::I18n.locale ::I18n.locale
end end

Loading…
Cancel
Save