File: string_interpolate_fix.rb

package info (click to toggle)
ruby-gettext-i18n-rails 1.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 148 kB
  • sloc: ruby: 515; makefile: 6
file content (20 lines) | stat: -rw-r--r-- 537 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
needed = "".respond_to?(:html_safe) and
  (
    "".html_safe % {:x => '<br/>'} == '<br/>' or
    not ("".html_safe % {:x=>'a'}).html_safe?
  )

if needed
  class String
    alias :interpolate_without_html_safe :%

    def %(*args)
      if args.first.is_a?(Hash) and html_safe?
        safe_replacement = Hash[args.first.map{|k,v| [k,ERB::Util.h(v)] }]
        interpolate_without_html_safe(safe_replacement).html_safe
      else
        interpolate_without_html_safe(*args).dup # make sure its not html_safe
      end
    end
  end
end