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).
-
#exercises ⇒ Element
Returns the exercises element.
-
#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_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, #ancestor, #ancestor_elements, #append, #as_enumerator, #children, #classes, #clone, #config, #contains?, #content, #copied_id, #copy, #count_in, #cut, #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, #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)
69 70 71 72 73 |
# File 'lib/kitchen/page_element.rb', line 69 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 |
#exercises ⇒ Element
Returns the exercises element.
113 114 115 |
# File 'lib/kitchen/page_element.rb', line 113 def exercises first!('section.exercises') end |
#free_response ⇒ Element
Returns the free response questions
121 122 123 |
# File 'lib/kitchen/page_element.rb', line 121 def free_response search('section.free-response') end |
#is_appendix? ⇒ Boolean
Returns true if this page is an appendix
87 88 89 |
# File 'lib/kitchen/page_element.rb', line 87 def is_appendix? has_class?('appendix') end |
#is_handbook? ⇒ Boolean
Returns true if this page is a handbook
129 130 131 |
# File 'lib/kitchen/page_element.rb', line 129 def is_handbook? has_class?('handbook') end |
#is_introduction? ⇒ Boolean
Returns true if this page is an introduction
60 61 62 |
# File 'lib/kitchen/page_element.rb', line 60 def is_introduction? @is_introduction ||= has_class?('introduction') end |
#is_preface? ⇒ Boolean
Returns true if this page is a preface
79 80 81 |
# File 'lib/kitchen/page_element.rb', line 79 def is_preface? has_class?('preface') end |
#metadata ⇒ Element
Returns the metadata element.
96 97 98 |
# File 'lib/kitchen/page_element.rb', line 96 def first!("div[data-type='metadata']") end |
#summary ⇒ Element?
Returns the summary element.
104 105 106 |
# File 'lib/kitchen/page_element.rb', line 104 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 |
# 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 first!(selector, reload: reload) end end |
#title_text ⇒ String
Returns the title’s text regardless of whether the title has been baked
44 45 46 |
# File 'lib/kitchen/page_element.rb', line 44 def title_text title.children.one? ? title.text : title.first('.os-text').text end |
#titles ⇒ ElementEnumerator
Returns an enumerator for titles.
52 53 54 |
# File 'lib/kitchen/page_element.rb', line 52 def titles search("div[data-type='document-title']") end |