Class: Kentico::Kontent::Delivery::Resolvers::InlineContentItemResolver
- Inherits:
-
Object
- Object
- Kentico::Kontent::Delivery::Resolvers::InlineContentItemResolver
- Defined in:
- lib/delivery/resolvers/inline_content_item_resolver.rb
Overview
Locates <object data-type=“item”> tags in content and calls a user-defined method to supply the output for the content item. See github.com/Kentico/kontent-delivery-sdk-ruby#resolving-inline-content
Instance Method Summary collapse
-
#initialize(callback = nil) ⇒ InlineContentItemResolver
constructor
A new instance of InlineContentItemResolver.
-
#resolve(content, inline_items) ⇒ Object
Resolves all inline content items in the content.
Constructor Details
#initialize(callback = nil) ⇒ InlineContentItemResolver
Returns a new instance of InlineContentItemResolver.
11 12 13 |
# File 'lib/delivery/resolvers/inline_content_item_resolver.rb', line 11 def initialize(callback = nil) @callback = callback end |
Instance Method Details
#resolve(content, inline_items) ⇒ Object
Resolves all inline content items in the content.
-
Args:
-
content (
string
) The string value stored in the element -
inline_items (
Array
) ContentItems referenced by the content from the ‘modular_content’ JSON node
-
-
Returns:
-
string
The original content passed, with all <object data-type=“item”> replaced with custom output
-
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/delivery/resolvers/inline_content_item_resolver.rb', line 23 def resolve(content, inline_items) doc = Nokogiri::HTML.parse(content).xpath('//body') = doc.xpath('//object[@type="application/kenticocloud"][@data-type="item"]') .each do |tag| output = resolve_tag tag, inline_items el = doc.at_xpath( '//object[@type="application/kenticocloud"][@data-type="item"][@data-codename=$value]', nil, value: tag['data-codename'] ) el.swap(output) unless output.nil? end doc.inner_html end |