class OpenStax::Content::Fragment::Embedded
Constants
- CLASS_ATTRIBUTES
- LABEL_ATTRIBUTE
Used to get the title if there are no title nodes
- TAGGED_URL_CSS
CSS to find embedded content urls
- TITLE_CSS
Used to get the title
- UNTAGGED_URL_CSS
Attributes
height[R]
url[R]
width[R]
Public Class Methods
inherited(subclass)
click to toggle source
# File lib/openstax/content/fragment/embedded.rb, line 19 def inherited(subclass) CLASS_ATTRIBUTES.each do |class_attribute| subclass.send "#{class_attribute}=", send(class_attribute) end end
new(node:, title: nil, labels: nil)
click to toggle source
Calls superclass method
OpenStax::Content::Fragment::Html::new
# File lib/openstax/content/fragment/embedded.rb, line 35 def initialize(node:, title: nil, labels: nil) super @title ||= begin title_nodes = @node.css(TITLE_CSS) titles = title_nodes.empty? ? @node.css(LABEL_ATTRIBUTE).map do |label| label.attr('data-label') end : title_nodes.map { |node| node.content.strip } titles.uniq.join('; ') end url_node = @node.at_css(TAGGED_URL_CSS) || @node.css(UNTAGGED_URL_CSS).last @width = url_node&.[]('width') || default_width @height = url_node&.[]('height') || default_height @url = url_node&.[]('src') || url_node&.[]('href') if url_node&.name == 'iframe' node_classes = url_node['class'].to_s.split(' ') + iframe_classes url_node['class'] = node_classes.uniq.join(' ') url_node['title'] ||= iframe_title # To always force the default iframe size, change ||= to = url_node['width'] ||= default_width url_node['height'] ||= default_height end @to_html = @node.to_html end
Public Instance Methods
blank?()
click to toggle source
# File lib/openstax/content/fragment/embedded.rb, line 64 def blank? url.nil? || url.empty? end