output_safety.rb 524 字节
Newer Older
1
class String
2 3
  attr_accessor :_rails_html_safe
  alias html_safe? _rails_html_safe
4 5 6 7 8

  def html_safe!
    @_rails_html_safe = true
    self
  end
J
Joshua Peek 已提交
9

10 11 12
  def html_safe
    dup.html_safe!
  end
J
Joshua Peek 已提交
13

14 15 16
  alias original_plus +
  def +(other)
    result = original_plus(other)
17 18
    result._rails_html_safe = html_safe? && other.html_safe?
    result
19
  end
J
Joshua Peek 已提交
20

21
  alias original_concat <<
22
  alias safe_concat <<
23
  def <<(other)
24
    @_rails_html_safe = false unless other.html_safe?
25 26
    result = original_concat(other)
  end
J
Joshua Peek 已提交
27

28
  alias concat <<
29
end