module SolidusSeo::Jsonld::TagHelper
Public Instance Methods
captured_jsonld()
click to toggle source
# File lib/solidus_seo/jsonld/tag_helper.rb, line 26 def captured_jsonld @captured_jsonld ||= {} @captured_jsonld.values.join("\n").html_safe end
dump_jsonld()
click to toggle source
# File lib/solidus_seo/jsonld/tag_helper.rb, line 31 def dump_jsonld captured_jsonld + jsonld(current_store) end
jsonld(item, opts = {})
click to toggle source
@param item [Object] A jsonld hash or any object that implements `to_jsonld` method @param opts [Array] Blacklist of attributes from jsonld @param opts [Array] Whitelist of attributes from jsonld @param opts [Boolean] Force cache miss
@return [String] Retrieves jsonld tag markup.
# File lib/solidus_seo/jsonld/tag_helper.rb, line 14 def jsonld(item, opts = {}) jsonld_fetch(:base, item, opts.symbolize_keys) end
jsonld_list(collection)
click to toggle source
# File lib/solidus_seo/jsonld/tag_helper.rb, line 18 def jsonld_list(collection) capture_jsonld(:list, jsonld_fetch(:list, collection)) end
Private Instance Methods
capture_jsonld(key, value)
click to toggle source
# File lib/solidus_seo/jsonld/tag_helper.rb, line 37 def capture_jsonld(key, value) @captured_jsonld ||= {} return unless value @captured_jsonld[key.to_sym] = value nil # Ensure no output is returned end
jsonld_fetch(type = :base, items = nil, opts = {})
click to toggle source
# File lib/solidus_seo/jsonld/tag_helper.rb, line 45 def jsonld_fetch(type = :base, items = nil, opts = {}) force = opts.delete(:force) || false jsonld_cache_key = [:jsonld, items, *opts.values].compact Rails.cache.fetch(jsonld_cache_key, force: force) do jsonld_builder_class = "::SolidusSeo::Jsonld::#{type.to_s.titleize}".constantize jsonld_builder_class.new(items).print(opts) end end