Module: Spree::JsonLdHelper
- Defined in:
- app/helpers/spree/json_ld_helper.rb
Instance Method Summary collapse
-
#json_ld_script(data, **html_attrs) ⇒ Object
spree_api globally sets ActiveSupport::JSON::Encoding.escape_html_entities_in_json = false, so a literal ‘</script>` in any field would break out of the surrounding script tag.
Instance Method Details
#json_ld_script(data, **html_attrs) ⇒ Object
spree_api globally sets ActiveSupport::JSON::Encoding.escape_html_entities_in_json = false, so a literal ‘</script>` in any field would break out of the surrounding script tag. ERB::Util.json_escape post-processes the encoded JSON to escape `<`, `>`, `&` regardless of that global flag.
7 8 9 10 |
# File 'app/helpers/spree/json_ld_helper.rb', line 7 def json_ld_script(data, **html_attrs) json = ERB::Util.json_escape(data.to_json) content_tag(:script, json.html_safe, type: 'application/ld+json', **html_attrs) end |