Class: Tenjin::SafeTemplate

Inherits:
Template show all
Defined in:
lib/tenjin.rb

Constant Summary collapse

ESCAPE_FUNCTION =
'safe_escape'

Constants inherited from Template

Template::TRACE

Instance Attribute Summary

Attributes inherited from Template

#_last_checked_at, #args, #escapefunc, #filename, #initbuf, #newline, #script, #timestamp

Instance Method Summary collapse

Methods inherited from Template

TRACE=, #convert, #convert_file, #finish_buf_expr, #init_buf_expr, #render

Constructor Details

#initialize(filename = nil, options = {}) ⇒ SafeTemplate

Returns a new instance of SafeTemplate.



971
972
973
974
975
# File 'lib/tenjin.rb', line 971

def initialize(filename=nil, options={})
  options, filename = filename, nil if filename.is_a?(Hash)
  options[:escapefunc] ||= 'safe_escape'
  super(filename, options)
end

Instance Method Details

#escape_str(str) ⇒ Object

escape ‘#’ in addition ‘\’ and ‘`’



978
979
980
981
982
# File 'lib/tenjin.rb', line 978

def escape_str(str)
  str.gsub!(/[`\#\\]/, '\\\\\&')
  str.gsub!(/\r\n/, "\\r\r\n") if @newline == "\r\n"
  return str
end