Sha256: cb1a97919fff93f2c81d6e75e5577606af1942acb8127e31864b46c313530cb2

Contents?: true

Size: 1.79 KB

Versions: 4

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

module Kitchen
  # An element for a composite page
  #
  class CompositePageElement < ElementBase

    # Creates a new +CompositePageElement+
    #
    # @param node [Nokogiri::XML::Node] the node this element wraps
    # @param document [Document] this element's document
    #
    def initialize(node:, document: nil)
      super(node: node,
            document: document,
            enumerator_class: CompositePageElementEnumerator)
    end

    # Returns the short type
    # @return [Symbol]
    #
    def self.short_type
      :composite_page
    end

    # Returns the title element (the one in the immediate children, not the one in the metadata)
    #
    # @raise [ElementNotFoundError] if no matching element is found
    # @return [Element]
    #
    def title
      first!('h3[data-type="title"], h2[data-type="document-title"],' \
             'h1[data-type="document-title"]')
    end

    # Returns true if this page is a book index
    #
    # @return [Boolean]
    #
    def is_index?
      has_class?('os-index-container')
    end

    # In books we can find two types of EOB References.
    #
    # One of them has form similar to footnotes. There are citation links in the text that provides
    # to the reference note at the end of the book.
    #
    # Second one is a section with references on the Introduction page that is moved to the EOB.
    #
    # Difference in classes is important.

    # Returns true if this page is a book citation reference
    #
    # @return [Boolean]
    #
    def is_citation_reference?
      has_class?('os-eob os-reference-container')
    end

    # Returns true if this page is a book section reference
    #
    # @return [Boolean]
    #
    def is_section_reference?
      has_class?('os-eob os-references-container')
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
openstax_kitchen-11.0.0 lib/kitchen/composite_page_element.rb
openstax_kitchen-10.0.0 lib/kitchen/composite_page_element.rb
openstax_kitchen-9.2.0 lib/kitchen/composite_page_element.rb
openstax_kitchen-9.1.0 lib/kitchen/composite_page_element.rb