Class: Erubis::XmlEruby

Inherits:
Eruby
  • Object
show all
Defined in:
lib/erubis.rb

Overview

do sanitizing of <%= %>

Direct Known Subclasses

FastXmlEruby, PrintXmlEruby, StdoutXmlEruby

Instance Attribute Summary

Attributes inherited from Eruby

#filename, #src

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Eruby

#compile, #evaluate, #initialize, load_file, #result

Constructor Details

This class inherits a constructor from Erubis::Eruby

Class Method Details

.escape(obj) ⇒ Object



162
163
164
165
166
167
168
169
170
171
# File 'lib/erubis.rb', line 162

def self.escape(obj)
  str = obj.to_s.dup
  #str = obj.to_s
  #str = str.dup if obj.__id__ == str.__id__
  str.gsub!(/&/, '&amp;')
  str.gsub!(/</, '&lt;')
  str.gsub!(/>/, '&gt;')
  str.gsub!(/"/, '&quot;')   #"
  return str
end

Instance Method Details

#add_src_expr(src, code, indicator) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/erubis.rb', line 173

def add_src_expr(src, code, indicator)
  case indicator
  when '='    # <%= %>
    src << "_out << Erubis::XmlEruby.escape(#{code}); "
  when '=='   # <%== %>
    super
  when '==='  # <%=== %>
    code.strip!
    s = code.dump
    s.sub!(/\A"/, '')
    s.sub!(/"\z/, '')
    src << "$stderr.puts(\"** erubis: #{s} = \#{(#{code}).inspect}\"); "
  else
    # nothing
  end
end