aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/i18n_fixes.rb41
-rw-r--r--lib/make_html_4_compliant.rb3
-rw-r--r--lib/tasks/rspec.rake5
-rw-r--r--lib/timezone_fixes.rb4
-rw-r--r--lib/use_spans_for_errors.rb2
5 files changed, 27 insertions, 28 deletions
diff --git a/lib/i18n_fixes.rb b/lib/i18n_fixes.rb
index 6e684d44a..a85faddcb 100644
--- a/lib/i18n_fixes.rb
+++ b/lib/i18n_fixes.rb
@@ -5,39 +5,36 @@
# override behaviour in fast_gettext/translation.rb
# so that we can interpolate our translation strings nicely
+# TODO: We could simplify a lot of this code (as in remove it) if we moved from using the {{value}}
+# convention in the translation strings for interpolation to %{value}. This is apparently the newer
+# convention.
+
def _(key, options = {})
- translation = FastGettext._(key) || key
+ translation = (FastGettext._(key) || key).html_safe
gettext_interpolate(translation, options)
end
-INTERPOLATION_RESERVED_KEYS = %w(scope default)
-MATCH = /(\\\\)?\{\{([^\}]+)\}\}/
+MATCH = /\{\{([^\}]+)\}\}/
def gettext_interpolate(string, values)
return string unless string.is_a?(String)
- if values.is_a?(Hash)
- string.gsub(MATCH) do
- escaped, pattern, key = $1, $2, $2.to_sym
-
- if escaped
- pattern
- elsif INTERPOLATION_RESERVED_KEYS.include?(pattern)
- raise I18n::ReservedInterpolationKey.new(pattern, string)
- elsif !values.include?(key)
- raise I18n::MissingInterpolationArgument.new(pattern, string)
+ # $1, $2 don't work with SafeBuffer so casting to string as workaround
+ safe = string.html_safe?
+ string = string.to_str.gsub(MATCH) do
+ pattern, key = $1, $1.to_sym
+
+ if !values.include?(key)
+ raise I18n::MissingInterpolationArgument.new(pattern, string)
+ else
+ v = values[key].to_s
+ if safe && !v.html_safe?
+ ERB::Util.h(v)
else
- values[key].to_s
+ v
end
end
- else
- reserved_keys = if defined?(I18n::RESERVED_KEYS) # rails 3+
- I18n::RESERVED_KEYS
- else
- I18n::Backend::Base::RESERVED_KEYS
- end
-
- string % values.except(*reserved_keys)
end
+ safe ? string.html_safe : string
end
diff --git a/lib/make_html_4_compliant.rb b/lib/make_html_4_compliant.rb
index 214eb9f1f..8926d5873 100644
--- a/lib/make_html_4_compliant.rb
+++ b/lib/make_html_4_compliant.rb
@@ -3,7 +3,6 @@
ActionView::Helpers::TagHelper.module_eval do
def tag(name, options = nil, open = false, escape = true)
- "<#{name}#{tag_options(options, escape) if options}" + (open ? ">" : ">")
+ "<#{name}#{tag_options(options, escape) if options}#{open ? ">" : ">"}".html_safe
end
end
-
diff --git a/lib/tasks/rspec.rake b/lib/tasks/rspec.rake
index 1eee74aee..d4fd4a9ff 100644
--- a/lib/tasks/rspec.rake
+++ b/lib/tasks/rspec.rake
@@ -23,6 +23,9 @@ rescue MissingSourceFile
module Spec
module Rake
class SpecTask
+ if defined?(::Rake::DSL)
+ include ::Rake::DSL
+ end
def initialize(name)
task name do
# if rspec-rails is a configured gem, this will output helpful material and exit ...
@@ -52,8 +55,6 @@ end
task :default => :spec
task :stats => "spec:statsetup"
-# XXX commonlib tests are not Ruby 1.9 compatible
-#task :spec => ['spec:commonlib']
task :test => ['spec']
task :cruise => ['spec']
diff --git a/lib/timezone_fixes.rb b/lib/timezone_fixes.rb
index e6d2f9470..1bf326ccd 100644
--- a/lib/timezone_fixes.rb
+++ b/lib/timezone_fixes.rb
@@ -4,7 +4,9 @@
# Otherwise times get stored wrong during British Summer Time
-# Hopefully fixed in later Rails. There is a test in spec/libs/timezone_fixes.rb
+# Hopefully fixed in later Rails. There is a test in spec/lib/timezone_fixes_spec.rb
+
+# This fix is applied in Rails 3.x. So, should be possible to remove this then!
# Monkeypatch!
module ActiveRecord
diff --git a/lib/use_spans_for_errors.rb b/lib/use_spans_for_errors.rb
index cda05c588..135453f78 100644
--- a/lib/use_spans_for_errors.rb
+++ b/lib/use_spans_for_errors.rb
@@ -8,5 +8,5 @@
#
# See http://dev.rubyonrails.org/ticket/2210
-ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| %(<span class="fieldWithErrors">#{html_tag}</span>)}
+ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| %(<span class="fieldWithErrors">#{html_tag}</span>).html_safe}