Module: RageRender::TemplateFunctions
- Defined in:
- lib/ragerender/functions.rb
Constant Summary collapse
- STRIP_HTML_BLOCKS =
github.com/Shopify/liquid/blob/9bb7fbf123e6e2bd61e00189b1c83159f375d3f3/lib/liquid/standardfilters.rb#L24-L29 Used under the MIT License.
Regexp.union( %r{<script.*?</script>}m, /<!--.*?-->/m, %r{<style.*?</style>}m, )
- STRIP_HTML_TAGS =
/<.*?>/m
Instance Method Summary collapse
- #js(str) ⇒ Object
- #randomnumber(a, b) ⇒ Object
-
#rawhtml(str) ⇒ Object
Unescape all HTML entities in the input.
-
#removehtmltags(str) ⇒ Object
This is only used for ERB – for Liquid, we use the native
strip_htmlThis pretty much mirrors the Liquid implementation.
Instance Method Details
#js(str) ⇒ Object
8 9 10 11 12 |
# File 'lib/ragerender/functions.rb', line 8 def js str JSON.generate(str, script_safe: true, ascii_only: true).gsub(/[<>'&]|\\"/) do |m| '\u' + sprintf('%04x', m.chars.last.ord).upcase end end |
#randomnumber(a, b) ⇒ Object
14 15 16 |
# File 'lib/ragerender/functions.rb', line 14 def randomnumber a, b rand a.to_i..b.to_i end |
#rawhtml(str) ⇒ Object
Unescape all HTML entities in the input
19 20 21 |
# File 'lib/ragerender/functions.rb', line 19 def rawhtml str CGI.unescape_html str end |
#removehtmltags(str) ⇒ Object
This is only used for ERB – for Liquid, we use the native strip_html This pretty much mirrors the Liquid implementation.
34 35 36 |
# File 'lib/ragerender/functions.rb', line 34 def str str.gsub(STRIP_HTML_BLOCKS, '').gsub(STRIP_HTML_TAGS, '') end |