stdlib/erb.rb in opal-0.4.3 vs stdlib/erb.rb in opal-0.4.4
- old
+ new
@@ -1,26 +1,17 @@
-module Template
- @_cache = {}
- def self.[](name)
- @_cache[name]
- end
+require 'template'
- def self.[]=(name, instance)
- @_cache[name] = instance
- end
-end
-
class ERB
- def initialize(name, &body)
- @body = body
- @name = name
- Template[name] = self
- end
+ module Util
- def inspect
- "#<ERB: name=#{@name.inspect}>"
- end
+ `var escapes = { '&': '&', '<': '<', '>': '>', '"': '"', "'": '''};`
+ `var escape_regexp = /[&<>"']/g;`
- def render(ctx = self)
- ctx.instance_exec([], &@body)
+ def html_escape(str)
+ `return ("" + str).replace(escape_regexp, function (m) { return escapes[m] });`
+ end
+
+ alias h html_escape
+ module_function :h
+ module_function :html_escape
end
end