module ArticleJSON::Export::Common::HTML::Elements::Embed

Public Instance Methods

export() click to toggle source

Generate the embedded element node @return [Nokogiri::XML::NodeSet]

# File lib/article_json/export/common/html/elements/embed.rb, line 11
def export
  create_element(:figure) do |figure|
    figure.add_child(embed_node)
    if @element.caption&.any?
      figure.add_child(caption_node(:figcaption))
    end
  end
end

Private Instance Methods

embed_node() click to toggle source
# File lib/article_json/export/common/html/elements/embed.rb, line 22
def embed_node
  type = @element.embed_type.to_s.tr('_','-')
  create_element(:div, class: "embed #{type}") do |div|
    div.add_child(embedded_object)
  end
end
embedded_object() click to toggle source
# File lib/article_json/export/common/html/elements/embed.rb, line 29
def embedded_object
  return unavailable_node unless @element.oembed_data
  Nokogiri::HTML.fragment(@element.oembed_data[:html])
end
unavailable_node() click to toggle source
# File lib/article_json/export/common/html/elements/embed.rb, line 34
def unavailable_node
  create_element(:span, class: 'unavailable-embed') do |span|
    @element.oembed_unavailable_message.each do |element|
      span.add_child(base_class.build(element).export)
    end
  end
end