opal/opal-haml.rb in opal-haml-0.4.2 vs opal/opal-haml.rb in opal-haml-0.4.3
- old
+ new
@@ -1,6 +1,35 @@
require 'template'
+module Haml
+ module Buffer
+ def rstrip!
+ self
+ end
+ end
+
+ module Helpers
+ def self.html_escape(string)
+ # http://stackoverflow.com/a/9756789
+ %x{
+ return ('' + string) /* Forces the conversion to string. */
+ .replace(/&/g, '&') /* This MUST be the 1st replacement. */
+ .replace(/'/g, ''') /* The 4 other predefined entities, required. */
+ .replace(/"/g, '"')
+ .replace(/</g, '<')
+ .replace(/>/g, '>')
+ /*
+ You may add other replacements here for HTML only
+ (but it's not necessary).
+ Or for XML, only if the named entities are defined in its DTD.
+ */
+ .replace(/\r\n/g, ' ') /* Must be before the next replacement. */
+ .replace(/[\r\n]/g, ' ');
+ }
+ end
+ end
+end
+
class Template
class OutputBuffer
alias << append
# allow tags in haml to have dynamic attributes