Class: Kitchen::PageElement
- Inherits:
-
ElementBase
- Object
- ElementBase
- Kitchen::PageElement
- Defined in:
- lib/kitchen/page_element.rb
Overview
An element for a page
Instance Attribute Summary
Attributes inherited from ElementBase
#ancestors, #document, #enumerator_class, #search_query_that_found_me, #short_type
Class Method Summary collapse
-
.short_type ⇒ Symbol
Returns the short type.
Instance Method Summary collapse
-
#count_in_chapter_without_intro_page ⇒ Integer
Returns replaces generic call to page.count_in(:chapter).
-
#free_response ⇒ Element
Returns the free response questions.
-
#initialize(node:, document: nil) ⇒ PageElement
constructor
Creates a new
PageElement
. -
#is_appendix? ⇒ Boolean
Returns true if this page is an appendix.
-
#is_handbook? ⇒ Boolean
Returns true if this page is a handbook.
-
#is_introduction? ⇒ Boolean
Returns true if this page is an introduction.
-
#is_preface? ⇒ Boolean
Returns true if this page is a preface.
-
#metadata ⇒ Element
Returns the metadata element.
-
#summary ⇒ Element?
Returns the summary element.
-
#title(reload: false) ⇒ Element
Returns the title element.
-
#title_children ⇒ Element
Returns the title’s primary children regardless of whether the title has been baked.
-
#title_text ⇒ String
Returns the title’s text regardless of whether the title has been baked.
-
#titles ⇒ ElementEnumerator
Returns an enumerator for titles.
Methods inherited from ElementBase
#[], #[]=, #add_ancestor, #add_ancestors, #add_class, #add_platform_media, #ancestor, #ancestor_elements, #append, #as_enumerator, #children, #classes, #clone, #config, #contains?, #contains_blockish?, #content, #copy, #count_in, #custom_target_label_for_modules, #cut, #data_sm, #data_sm_formatted, #data_source, #data_type, descendant, descendant!, #element_children, #first, #first!, #has_ancestor?, #has_class?, #href, #href=, #id, #id=, #inner_html=, #inspect, #is?, is_the_element_class_for?, #key?, #mark_as_current_location!, #name, #name=, #pages, #pantry, #parent, #paste, #path, #preceded_by_text, #prepend, #previous, #raw, #raw_search, #remember_that_a_sub_element_was_counted, #remove_attribute, #remove_class, #replace_children, #rex_link, #say_source_or_nil, #search, #search_history, #selectors, #set, #sub_header_name, #target_label, #text, #to_html, #to_s, #to_xhtml, #to_xml, #trash, #uncount, #wrap, #wrap_children
Methods included from Mixins::BlockErrorIf
Constructor Details
#initialize(node:, document: nil) ⇒ PageElement
Creates a new PageElement
13 14 15 16 17 |
# File 'lib/kitchen/page_element.rb', line 13 def initialize(node:, document: nil) super(node: node, document: document, enumerator_class: PageElementEnumerator) end |
Class Method Details
.short_type ⇒ Symbol
Returns the short type
22 23 24 |
# File 'lib/kitchen/page_element.rb', line 22 def self.short_type :page end |
Instance Method Details
#count_in_chapter_without_intro_page ⇒ Integer
Returns replaces generic call to page.count_in(:chapter)
83 84 85 86 87 |
# File 'lib/kitchen/page_element.rb', line 83 def count_in_chapter_without_intro_page raise 'Introduction pages cannot be counted with this method' if is_introduction? count_in(:chapter) - (ancestor(:chapter).has_introduction? ? 1 : 0) end |
#free_response ⇒ Element
Returns the free response questions
126 127 128 |
# File 'lib/kitchen/page_element.rb', line 126 def free_response search('section.free-response') end |
#is_appendix? ⇒ Boolean
Returns true if this page is an appendix
101 102 103 |
# File 'lib/kitchen/page_element.rb', line 101 def is_appendix? has_class?('appendix') end |
#is_handbook? ⇒ Boolean
Returns true if this page is a handbook
134 135 136 |
# File 'lib/kitchen/page_element.rb', line 134 def is_handbook? has_class?('handbook') end |
#is_introduction? ⇒ Boolean
Returns true if this page is an introduction
74 75 76 |
# File 'lib/kitchen/page_element.rb', line 74 def is_introduction? @is_introduction ||= has_class?('introduction') end |
#is_preface? ⇒ Boolean
Returns true if this page is a preface
93 94 95 |
# File 'lib/kitchen/page_element.rb', line 93 def is_preface? has_class?('preface') end |
#metadata ⇒ Element
Returns the metadata element.
110 111 112 |
# File 'lib/kitchen/page_element.rb', line 110 def first!("div[data-type='metadata']") end |
#summary ⇒ Element?
Returns the summary element.
118 119 120 |
# File 'lib/kitchen/page_element.rb', line 118 def summary first(selectors.page_summary) end |
#title(reload: false) ⇒ Element
Returns the title element. This method is aware that the title of the introduction page moves during the baking process.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/kitchen/page_element.rb', line 32 def title(reload: false) # The selector for intro titles changes during the baking process @title ||= begin selector = is_introduction? ? selectors.title_in_introduction_page : selectors.title_in_page search(selector, reload: reload).map do |title| next if title.parent[:'data-type'] == 'metadata' return title end raise "Title not found for page id=#{id}" end end |
#title_children ⇒ Element
Returns the title’s primary children regardless of whether the title has been baked
57 58 59 60 |
# File 'lib/kitchen/page_element.rb', line 57 def title_children title_os_text = title.search('.os-text').first # module titles which are already baked title_os_text ? title_os_text.children : title.children end |
#title_text ⇒ String
Returns the title’s text regardless of whether the title has been baked
49 50 51 |
# File 'lib/kitchen/page_element.rb', line 49 def title_text title.children.one? ? title.text : title.first('.os-text').text end |
#titles ⇒ ElementEnumerator
Returns an enumerator for titles.
66 67 68 |
# File 'lib/kitchen/page_element.rb', line 66 def titles search("div[data-type='document-title']") end |