~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/activesupport/lib/active_support/core_ext/string/output_safety.rb

  • Committer: Michael Forrest
  • Date: 2010-10-15 16:28:50 UTC
  • Revision ID: michael.forrest@canonical.com-20101015162850-tj2vchanv0kr0dun
refrozeĀ gems

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
module ActiveSupport #:nodoc:
 
2
  module CoreExtensions #:nodoc:
 
3
    module String #:nodoc:
 
4
      module OutputSafety
 
5
        def self.included(base)
 
6
          base.class_eval do
 
7
            alias_method :add_without_safety, :+
 
8
            alias_method :+, :add_with_safety
 
9
            alias_method_chain :concat, :safety
 
10
            undef_method :<<
 
11
            alias_method :<<, :concat_with_safety
 
12
          end
 
13
        end
 
14
 
 
15
        def html_safe?
 
16
          defined?(@_rails_html_safe) && @_rails_html_safe
 
17
        end
 
18
 
 
19
        def html_safe!
 
20
          @_rails_html_safe = true
 
21
          self
 
22
        end
 
23
 
 
24
        def add_with_safety(other)
 
25
          result = add_without_safety(other)
 
26
          if html_safe? && also_html_safe?(other)
 
27
            result.html_safe!
 
28
          else
 
29
            result
 
30
          end
 
31
        end
 
32
 
 
33
        def concat_with_safety(other_or_fixnum)
 
34
          result = concat_without_safety(other_or_fixnum)
 
35
          unless html_safe? && also_html_safe?(other_or_fixnum)
 
36
            @_rails_html_safe = false
 
37
          end
 
38
          result
 
39
        end
 
40
 
 
41
        private
 
42
          def also_html_safe?(other)
 
43
            other.respond_to?(:html_safe?) && other.html_safe?
 
44
          end
 
45
      end
 
46
    end
 
47
  end
 
48
end
 
 
b'\\ No newline at end of file'