openstax_kitchen 3.0.0 → 4.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/CHANGELOG.md +77 -3
  4. data/Gemfile.lock +13 -14
  5. data/README.md +23 -0
  6. data/codecov.yaml +1 -0
  7. data/docker/ci +0 -1
  8. data/lib/kitchen/book_document.rb +1 -1
  9. data/lib/kitchen/book_element.rb +16 -2
  10. data/lib/kitchen/chapter_element.rb +10 -13
  11. data/lib/kitchen/chapter_element_enumerator.rb +1 -1
  12. data/lib/kitchen/composite_chapter_element.rb +7 -11
  13. data/lib/kitchen/composite_chapter_element_enumerator.rb +21 -0
  14. data/lib/kitchen/composite_page_element.rb +15 -10
  15. data/lib/kitchen/composite_page_element_enumerator.rb +1 -1
  16. data/lib/kitchen/config.rb +14 -0
  17. data/lib/kitchen/directions/bake_chapter_glossary/main.rb +18 -0
  18. data/lib/kitchen/directions/bake_chapter_glossary/v1.rb +30 -0
  19. data/lib/kitchen/directions/bake_chapter_introductions.rb +1 -1
  20. data/lib/kitchen/directions/bake_chapter_key_concepts/main.rb +16 -0
  21. data/lib/kitchen/directions/bake_chapter_key_concepts/v1.rb +35 -0
  22. data/lib/kitchen/directions/bake_chapter_key_equations.rb +27 -20
  23. data/lib/kitchen/directions/bake_chapter_references/main.rb +16 -0
  24. data/lib/kitchen/directions/bake_chapter_references/v1.rb +35 -0
  25. data/lib/kitchen/directions/bake_chapter_section_exercises/main.rb +11 -0
  26. data/lib/kitchen/directions/bake_chapter_section_exercises/v1.rb +28 -0
  27. data/lib/kitchen/directions/bake_chapter_summary.rb +48 -42
  28. data/lib/kitchen/directions/bake_checkpoint.rb +44 -0
  29. data/lib/kitchen/directions/bake_composite_chapters.rb +14 -0
  30. data/lib/kitchen/directions/bake_composite_pages.rb +1 -1
  31. data/lib/kitchen/directions/bake_equations.rb +37 -0
  32. data/lib/kitchen/directions/bake_example.rb +34 -8
  33. data/lib/kitchen/directions/bake_figure.rb +1 -1
  34. data/lib/kitchen/directions/bake_first_elements.rb +16 -0
  35. data/lib/kitchen/directions/bake_footnotes/v1.rb +2 -1
  36. data/lib/kitchen/directions/bake_free_response/free_response.xhtml.erb +10 -0
  37. data/lib/kitchen/directions/bake_free_response/main.rb +11 -0
  38. data/lib/kitchen/directions/bake_free_response/v1.rb +29 -0
  39. data/lib/kitchen/directions/bake_further_research.rb +59 -0
  40. data/lib/kitchen/directions/bake_index/v1.rb +35 -14
  41. data/lib/kitchen/directions/bake_link_placeholders.rb +1 -1
  42. data/lib/kitchen/directions/bake_non_introduction_pages.rb +26 -0
  43. data/lib/kitchen/directions/bake_notes/bake_autotitled_notes.rb +29 -0
  44. data/lib/kitchen/directions/bake_notes/bake_note_subtitle.rb +22 -0
  45. data/lib/kitchen/directions/bake_notes/bake_numbered_notes.rb +51 -0
  46. data/lib/kitchen/directions/bake_notes/bake_unclassified_notes.rb +30 -0
  47. data/lib/kitchen/directions/bake_numbered_exercise/main.rb +15 -0
  48. data/lib/kitchen/directions/bake_numbered_exercise/v1.rb +47 -0
  49. data/lib/kitchen/directions/bake_numbered_table/main.rb +2 -2
  50. data/lib/kitchen/directions/bake_numbered_table/v1.rb +18 -4
  51. data/lib/kitchen/directions/bake_page_abstracts.rb +16 -0
  52. data/lib/kitchen/directions/bake_references/main.rb +16 -0
  53. data/lib/kitchen/directions/bake_references/v1.rb +48 -0
  54. data/lib/kitchen/directions/bake_stepwise.rb +1 -5
  55. data/lib/kitchen/directions/bake_suggested_reading.rb +5 -0
  56. data/lib/kitchen/directions/bake_theorem/main.rb +11 -0
  57. data/lib/kitchen/directions/bake_theorem/v1.rb +28 -0
  58. data/lib/kitchen/directions/bake_toc.rb +10 -2
  59. data/lib/kitchen/directions/book_answer_key_container/eob_solutions_container.xhtml.erb +9 -0
  60. data/lib/kitchen/directions/{bake_exercises → book_answer_key_container}/main.rb +1 -1
  61. data/lib/kitchen/directions/book_answer_key_container/v1.rb +13 -0
  62. data/lib/kitchen/directions/chapter_review_container/chapter_review.xhtml.erb +9 -0
  63. data/lib/kitchen/directions/chapter_review_container/main.rb +11 -0
  64. data/lib/kitchen/directions/chapter_review_container/v1.rb +13 -0
  65. data/lib/kitchen/directions/eoc_section_title_link_snippet.rb +20 -0
  66. data/lib/kitchen/directions/move_exercises_to_eoc/main.rb +27 -0
  67. data/lib/kitchen/directions/move_exercises_to_eoc/v1.rb +36 -0
  68. data/lib/kitchen/directions/move_exercises_to_eoc/v2.rb +49 -0
  69. data/lib/kitchen/directions/move_solutions_to_answer_key/main.rb +14 -0
  70. data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/american_government.rb +19 -0
  71. data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/calculus.rb +41 -0
  72. data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/uphysics.rb +63 -0
  73. data/lib/kitchen/directions/move_solutions_to_answer_key/v1.rb +34 -0
  74. data/lib/kitchen/document.rb +3 -0
  75. data/lib/kitchen/element.rb +9 -3
  76. data/lib/kitchen/element_base.rb +118 -16
  77. data/lib/kitchen/element_enumerator_base.rb +118 -8
  78. data/lib/kitchen/element_enumerator_factory.rb +28 -12
  79. data/lib/kitchen/element_factory.rb +3 -3
  80. data/lib/kitchen/example_element.rb +8 -11
  81. data/lib/kitchen/example_element_enumerator.rb +1 -1
  82. data/lib/kitchen/exercise_element.rb +42 -0
  83. data/lib/kitchen/exercise_element_enumerator.rb +21 -0
  84. data/lib/kitchen/figure_element.rb +8 -11
  85. data/lib/kitchen/figure_element_enumerator.rb +1 -1
  86. data/lib/kitchen/metadata_element.rb +8 -2
  87. data/lib/kitchen/metadata_element_enumerator.rb +1 -1
  88. data/lib/kitchen/note_element.rb +25 -27
  89. data/lib/kitchen/note_element_enumerator.rb +1 -1
  90. data/lib/kitchen/oven.rb +2 -0
  91. data/lib/kitchen/page_element.rb +33 -9
  92. data/lib/kitchen/page_element_enumerator.rb +1 -1
  93. data/lib/kitchen/patches/nokogiri.rb +55 -0
  94. data/lib/kitchen/patches/nokogiri_profiling.rb +60 -0
  95. data/lib/kitchen/recipe.rb +35 -2
  96. data/lib/kitchen/reference_element.rb +27 -0
  97. data/lib/kitchen/references_element_enumerator.rb +20 -0
  98. data/lib/kitchen/search_query.rb +31 -3
  99. data/lib/kitchen/selector.rb +25 -0
  100. data/lib/kitchen/selectors/base.rb +39 -0
  101. data/lib/kitchen/selectors/standard_1.rb +13 -0
  102. data/lib/kitchen/table_element.rb +8 -11
  103. data/lib/kitchen/table_element_enumerator.rb +1 -1
  104. data/lib/kitchen/templates/eob_section_title_template.xhtml.erb +10 -0
  105. data/lib/kitchen/templates/eoc_section_title_template.xhtml.erb +10 -0
  106. data/lib/kitchen/term_element.rb +5 -8
  107. data/lib/kitchen/term_element_enumerator.rb +1 -1
  108. data/lib/kitchen/unit_element.rb +13 -7
  109. data/lib/kitchen/unit_element_enumerator.rb +1 -1
  110. data/lib/kitchen/version.rb +1 -1
  111. data/lib/locales/en.yml +12 -7
  112. data/lib/locales/pl.yml +24 -0
  113. data/lib/openstax_kitchen.rb +2 -1
  114. metadata +54 -6
  115. data/lib/kitchen/directions/bake_chapter_glossary.rb +0 -37
  116. data/lib/kitchen/directions/bake_exercises/v1.rb +0 -166
  117. data/lib/kitchen/directions/bake_notes.rb +0 -58
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f404296c40eba5dbfdeeb4c4de0d11492eb327e94d49c96689b262a03bc838de
4
- data.tar.gz: b97faf532e7e098dba23ef1d1f3c42ca7c051d7fc6ad8351fa6b20209cb99ddd
3
+ metadata.gz: b80bf07271b311949246bf6a63a9d10fe5f14396175f66a129debcc9e9ef15e3
4
+ data.tar.gz: 7a3a7050d134a0b106d3a80dc18add9209742fca1eea4873f351eb0dd4d05034
5
5
  SHA512:
6
- metadata.gz: 7f8e774352355cc44b01765b101e97db3128e19e7416a6d5138d0a83db4378e7910d196e42849237e2130c6f7463db6f13679d53ac666b6a0abf6f867ecf6a36
7
- data.tar.gz: 84fece5f5d36f16324022d3ca34b6827f6549bed21551caedbb2845ff41d5b7b1f4b47c8e07a6fac6b14ed2e5f092435b63618a3b9e0f925a40cda21b04babfb
6
+ metadata.gz: 7fee3b2b4dd92639af2e20520c3f65a31255d944df649e91c5c0e5c8f0a8e1e1f6d19b4477480c5cbc899f7124727c8a40b5a0759985ec94225885baf36b3287
7
+ data.tar.gz: ed62932aa44e597135158cc182daefd2773b89070e1d82750669d4d1f760fa8179f1197c67eddcdec73c1cdc2b1bd7537ca28c8f5603d3a2a7962457d777141f
data/.gitignore CHANGED
@@ -7,6 +7,7 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /vendor/
10
11
 
11
12
  # rspec failure tracking
12
13
  .rspec_status
@@ -17,4 +18,3 @@ tutorial/outputs/*.html
17
18
 
18
19
  tutorials/**/actual_baked.*html
19
20
  tutorials/**/my_recipe.rb
20
-
data/CHANGELOG.md CHANGED
@@ -6,6 +6,80 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [4.1.1] - 2021-05-24
10
+
11
+ * Adds low level Nokogiri caching, disabled by default (patch)
12
+ * Cache Selector objects since they don't change (patch)
13
+ * Use more specific selectors when to reduce bake time (patch)
14
+
15
+ ## [4.1.0] - 2021-05-18
16
+
17
+ * Fixed performance problem with element class detection (patch)
18
+ * Added `BakeChapterReferences` Directions (minor)
19
+
20
+ ## [4.0.0] - 2021-05-18
21
+
22
+ * Changes `default_css_or_xpath` to optionally be a proc to be evaluated w.r.t. a document's config (minor)
23
+ * Support namespaces defined on elements other than the root (minor)
24
+ * Non-splash figures now treated like normal intro-body content in `BakeChapterIntroductions`
25
+ * `BakeNumberedNotes` and the uphysics strategy for `MoveSolutionsToAnswerKey` updated to accomodate multiple exercises in a note.
26
+ * `BakeFootnotes` now looks for footnotes in composite chapters
27
+ * Move exercise pantry label storage to `BakeNumberedExercises` to ensure consistency between exercise number and link text
28
+ * Update `BakeIndex` term capitalization handling to be less case sensitive (minor)
29
+ * Added a title tag variable to choose between h2 and h3 for children of chapter review (minor)
30
+ * Added a fix for examples not to bake table captions (minor)
31
+ * Replaced a .text with .children to include math text (minor)
32
+ * Changed title tag on numbered notes to always be h3 (major)
33
+ * Storing all note subtitles in the pantry for link placeholders (minor)
34
+ * Added another xmlns string option to remove if clone (minor)
35
+ * Add class to reference superscript & add metadata to `BakeSuggestedReading` (minor)
36
+ * Add `BakeFreeResponse` Directions (minor)
37
+ * Add terms from composite pages to index (minor)
38
+ * Access `.pantry` and `.clipboard` through an element instead of just its document (minor)
39
+ * Add `suppress_solution` option to `BakeNumberedExercise` (minor)
40
+ * Add strategy for American Government answer key (minor)
41
+ * Add `BakeReferences` direction (minor)
42
+ * Fix xmlns string replacement done in PR #209 (minor)
43
+ * Move title above metadata in `BakeSuggestedReading` direction (major)
44
+ * Remove depreciated directions `BakeNotes` and `BakeExercises` (major)
45
+ * Adds `eoc_composite_metadata_title` to en.yml and eoc template (major)
46
+ * Add `template` folder to kitchen to hold templates (minor)
47
+ * Add `eoc_section_title_template` (minor)
48
+ * Expand specs with `append_to` to have with/without `append_to` contexts (minor)
49
+ * Add `is?` method to `ElementBase` (minor)
50
+ * Replaced in_composite_chapter to use `is?` (minor)
51
+ * Add callable `short_type` to Elements (minor)
52
+ * Add template for eob titles - `eob_section_title_template` (minor)
53
+
54
+ ## [3.2.0] - 2021-04-20
55
+
56
+ * Adds method to allow unit and page title text to be retrieved regardless of bake status (minor)
57
+ * Rename several directions (major)
58
+ * `BakeChapterReviewExercises` -> `MoveExercisesToEOC`
59
+ * `BakeChapterReview` -> `ChapterReviewContainer`
60
+ * `BakeBookAnswerKey` -> `BookAnswerKeyContainer`
61
+ * `BakeChapterAnswerKey` -> `MoveSolutionsToAnswerKey`
62
+ * Refactors `BakeFirstElements` and `BakeNumberedExercise` (minor)
63
+ * Adds a decorating option of equation numbers on `BakeEquations` (minor)
64
+
65
+ ## [3.1.0] - 2021-04-19
66
+
67
+ * Add the ability to copy an element's ID to `ElementBase` (minor)
68
+ * Create `pl.yml` and add pl to available locals in `StubHelpers` module (minor)
69
+ * Add to `BakeNumberedNotes` directions for baking exercises in a note (with this comes removing bake checkpoints and theorems)
70
+ * Add `BakeEquations` direction (minor)
71
+ * Remove `NoteElement` logging (minor)
72
+ * Adds `BakeChapterReviewExercises` v2 and a u-physics `Strategy` to `BakeChapterAnswerKey` to support baking exercises in u-physics (minor)
73
+ * Have deprecated directions log a warning (minor)
74
+ * Added `wrap_children` method on elements (minor)
75
+ * Refactored `NoteElement` to infer the note title from book-specific locales (minor)
76
+ * Added support for a recipe to infer or be given a book-specific locale file (minor)
77
+ * Added `NumberedTable` support for titles and always captions (minor)
78
+ * Added titles method to `ElementEnumeratorBase` and `ElementBase` (minor)
79
+ * Added a file for baking composite chapters called (`bake_composite_chapters`) and the respective spec.
80
+ (minor change)
81
+ * Added `BakeProblemFirstElements` direction (minor)
82
+
9
83
  ## [3.0.0] - 2021-03-17
10
84
 
11
85
  * Added a subfigure? method to `FigureElements`(minor)
@@ -19,11 +93,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
19
93
  * Added ability to filter searches based on `only` and `except` conditions, which can be names of element methods or blocks of code (minor)
20
94
  * Changed from tracking and using `css_or_xpath` strings and arrays to `search_query` objects that
21
95
  wrap `css_or_xpath` variables along with `only` and `except` conditions. (major?)
96
+ * Refactored bake_exercises to better support parallel work on multiple versions. (minor)
22
97
 
23
98
  ## [2.0.0] - 2020-12-18
24
-
25
- * Refactored bake_exercises to better support parallel work on multiple versions.
26
- (minor change) Does not affect existing recipes.
99
+ * Added a file for baking key concepts called (`bake_chapter_key_concepts`) and the respective specs.
100
+ (minor change) only affects the book if called from the recipe
27
101
  * Changed the main gem source file to have the same name as the gem (`openstax_kitchen`) so that you don't have to `require` a different name than you use in your `gem` call.
28
102
 
29
103
  ## [1.0.0] - 2020-12-15
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openstax_kitchen (3.0.0)
4
+ openstax_kitchen (4.1.1)
5
5
  activesupport
6
6
  i18n
7
7
  nokogiri
@@ -10,21 +10,21 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- activesupport (6.0.3.3)
13
+ activesupport (6.1.3.2)
14
14
  concurrent-ruby (~> 1.0, >= 1.0.2)
15
- i18n (>= 0.7, < 2)
16
- minitest (~> 5.1)
17
- tzinfo (~> 1.1)
18
- zeitwerk (~> 2.2, >= 2.2.2)
15
+ i18n (>= 1.6, < 2)
16
+ minitest (>= 5.1)
17
+ tzinfo (~> 2.0)
18
+ zeitwerk (~> 2.3)
19
19
  ast (2.4.1)
20
20
  byebug (11.1.2)
21
21
  codecov (0.2.13)
22
22
  simplecov (~> 0.18.0)
23
23
  coderay (1.1.3)
24
- concurrent-ruby (1.1.7)
24
+ concurrent-ruby (1.1.8)
25
25
  diff-lcs (1.3)
26
26
  docile (1.3.3)
27
- i18n (1.8.5)
27
+ i18n (1.8.10)
28
28
  concurrent-ruby (~> 1.0)
29
29
  inch (0.8.0)
30
30
  pry
@@ -33,7 +33,7 @@ GEM
33
33
  yard (~> 0.9.12)
34
34
  method_source (1.0.0)
35
35
  mini_portile2 (2.5.0)
36
- minitest (5.14.2)
36
+ minitest (5.14.4)
37
37
  nokogiri (1.11.1)
38
38
  mini_portile2 (~> 2.5.0)
39
39
  racc (~> 1.4)
@@ -52,7 +52,7 @@ GEM
52
52
  rainbow (3.0.0)
53
53
  rake (12.3.3)
54
54
  regexp_parser (2.0.1)
55
- rexml (3.2.4)
55
+ rexml (3.2.5)
56
56
  rspec (3.9.0)
57
57
  rspec-core (~> 3.9.0)
58
58
  rspec-expectations (~> 3.9.0)
@@ -92,14 +92,13 @@ GEM
92
92
  tdiff (0.3.4)
93
93
  term-ansicolor (1.7.1)
94
94
  tins (~> 1.0)
95
- thread_safe (0.3.6)
96
95
  tins (1.26.0)
97
96
  sync
98
- tzinfo (1.2.7)
99
- thread_safe (~> 0.1)
97
+ tzinfo (2.0.4)
98
+ concurrent-ruby (~> 1.0)
100
99
  unicode-display_width (1.7.0)
101
100
  yard (0.9.24)
102
- zeitwerk (2.4.0)
101
+ zeitwerk (2.4.2)
103
102
 
104
103
  PLATFORMS
105
104
  ruby
data/README.md CHANGED
@@ -210,6 +210,13 @@ And we can wrap an element with another element:
210
210
  doc.search("span").first.wrap("<span class='other'>")
211
211
  ```
212
212
 
213
+ or wrap an element's children:
214
+
215
+ ```ruby
216
+ # <div><span>Hi</span></div> => <div><span><span class="other" data-type="foo">Hi</span></span></div>
217
+ doc.search("span").first.wrap_children('span', class: 'other', data_type: 'foo')
218
+ ```
219
+
213
220
  ### Checking for elements
214
221
 
215
222
  You can see if an element contains an element matching a selector:
@@ -634,6 +641,22 @@ expect(book_1).to match_normalized_html("some string of HTML here")
634
641
  expect(book_1).to match_html_nodes("some string of HTML here")
635
642
  ```
636
643
 
644
+ ### Profiling
645
+
646
+ If you set the `PROFILE` environment variable to something before you run specs or a recipe, search query profile data will be collected and printed, e.g.
647
+
648
+ ```bash
649
+ %> PROFILE=1 rspec
650
+ ```
651
+
652
+ ### Caching
653
+
654
+ There's a low-level CSS query caching tool that saves repeated queries. In some tests, it saves 15% of query time. It is disabled by default (because we aren't super sure that it is completely safe) but can be turned on with
655
+
656
+ ```ruby
657
+ doc.config.enable_search_cache = true
658
+ ```
659
+
637
660
  ### VSCode
638
661
 
639
662
  1. Visit `vscode:extension/ms-vscode-remote.remote-containers` in a browser
data/codecov.yaml CHANGED
@@ -25,3 +25,4 @@ ignore:
25
25
  - "bin"
26
26
  - "docker"
27
27
  - "books"
28
+ - "lib/kitchen/patches/nokogiri_profiling"
data/docker/ci CHANGED
@@ -10,7 +10,6 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
10
10
  docker run $CI_ENV \
11
11
  -e ENABLE_CODECOV=1 -e CI=true \
12
12
  -v $DIR/..:/code \
13
- -v vendor/bundle \
14
13
  -w /code \
15
14
  openstax/kitchen.ci:latest \
16
15
  /bin/bash -c "bundle config path vendor/bundle; bundle install; bundle exec rspec"
@@ -29,7 +29,7 @@ module Kitchen
29
29
  # @return [BookElement]
30
30
  #
31
31
  def book
32
- BookElement.new(node: nokogiri_document.search('html').first, document: self)
32
+ BookElement.new(node: nokogiri_document.root, document: self)
33
33
  end
34
34
 
35
35
  end
@@ -13,8 +13,14 @@ module Kitchen
13
13
  def initialize(node:, document: nil)
14
14
  super(node: node,
15
15
  document: document,
16
- enumerator_class: BookElementEnumerator,
17
- short_type: :book)
16
+ enumerator_class: BookElementEnumerator)
17
+ end
18
+
19
+ # Returns the short type
20
+ # @return [Symbol]
21
+ #
22
+ def self.short_type
23
+ :book
18
24
  end
19
25
 
20
26
  # Returns the "body" element
@@ -41,5 +47,13 @@ module Kitchen
41
47
  first!('nav#toc')
42
48
  end
43
49
 
50
+ # Returns true if this class represents the element for the given node
51
+ #
52
+ # @param node [Nokogiri::XML::Node] the underlying node
53
+ # @return [Boolean]
54
+ #
55
+ def self.is_the_element_class_for?(node, **)
56
+ node.name == 'body'
57
+ end
44
58
  end
45
59
  end
@@ -13,8 +13,14 @@ module Kitchen
13
13
  def initialize(node:, document: nil)
14
14
  super(node: node,
15
15
  document: document,
16
- enumerator_class: ChapterElementEnumerator,
17
- short_type: :chapter)
16
+ enumerator_class: ChapterElementEnumerator)
17
+ end
18
+
19
+ # Returns the short type
20
+ # @return [Symbol]
21
+ #
22
+ def self.short_type
23
+ :chapter
18
24
  end
19
25
 
20
26
  # Returns the title element (the one in the immediate children, not the one in the metadata)
@@ -35,7 +41,7 @@ module Kitchen
35
41
  # @return [Element, nil]
36
42
  #
37
43
  def introduction_page
38
- pages('.introduction').first
44
+ pages('$.introduction').first
39
45
  end
40
46
 
41
47
  # Returns an enumerator for the glossaries
@@ -59,16 +65,7 @@ module Kitchen
59
65
  # @return [ElementEnumerator]
60
66
  #
61
67
  def abstracts
62
- search('[data-type="abstract"]')
63
- end
64
-
65
- # Returns true if this class represents the element for the given node
66
- #
67
- # @param node [Nokogiri::XML::Node] the underlying node
68
- # @return [Boolean]
69
- #
70
- def self.is_the_element_class_for?(node)
71
- node['data-type'] == 'chapter'
68
+ search('div[data-type="abstract"]')
72
69
  end
73
70
 
74
71
  end
@@ -11,7 +11,7 @@ module Kitchen
11
11
  #
12
12
  def self.factory
13
13
  ElementEnumeratorFactory.new(
14
- default_css_or_xpath: "div[data-type='chapter']", # TODO: element.document.selectors.chapter
14
+ default_css_or_xpath: Selector.named(:chapter),
15
15
  sub_element_class: ChapterElement,
16
16
  enumerator_class: self
17
17
  )
@@ -13,8 +13,13 @@ module Kitchen
13
13
  def initialize(node:, document: nil)
14
14
  super(node: node,
15
15
  document: document,
16
- enumerator_class: ElementEnumerator,
17
- short_type: :composite_chapter)
16
+ enumerator_class: ElementEnumerator)
17
+ end
18
+
19
+ # Returns short type
20
+ #
21
+ def self.short_type
22
+ :composite_chapter
18
23
  end
19
24
 
20
25
  # Returns the title element (the one in the immediate children, not the one in the metadata)
@@ -29,14 +34,5 @@ module Kitchen
29
34
  first!("./*[@data-type = 'document-title']")
30
35
  end
31
36
 
32
- # Returns true if this class represents the element for the given node
33
- #
34
- # @param node [Nokogiri::XML::Node] the underlying node
35
- # @return [Boolean]
36
- #
37
- def self.is_the_element_class_for?(node)
38
- node['data-type'] == 'composite-chapter'
39
- end
40
-
41
37
  end
42
38
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ # An enumerator for composite page elements
5
+ #
6
+ class CompositeChapterElementEnumerator < ElementEnumeratorBase
7
+
8
+ # Returns a factory for this enumerator
9
+ #
10
+ # @return [ElementEnumeratorFactory]
11
+ #
12
+ def self.factory
13
+ ElementEnumeratorFactory.new(
14
+ default_css_or_xpath: Selector.named(:composite_chapter),
15
+ sub_element_class: CompositeChapterElement,
16
+ enumerator_class: self
17
+ )
18
+ end
19
+
20
+ end
21
+ end
@@ -13,8 +13,14 @@ module Kitchen
13
13
  def initialize(node:, document: nil)
14
14
  super(node: node,
15
15
  document: document,
16
- enumerator_class: CompositePageElementEnumerator,
17
- short_type: :composite_page)
16
+ enumerator_class: CompositePageElementEnumerator)
17
+ end
18
+
19
+ # Returns the short type
20
+ # @return [Symbol]
21
+ #
22
+ def self.short_type
23
+ :composite_page
18
24
  end
19
25
 
20
26
  # Returns the title element (the one in the immediate children, not the one in the metadata)
@@ -26,24 +32,23 @@ module Kitchen
26
32
  # Get the title in the immediate children, not the one in the metadata. Could use
27
33
  # CSS of ":not([data-type='metadata']) > [data-type='document-title'], [data-type='document-title']"
28
34
  # but xpath is shorter
29
- first!("./*[@data-type = 'document-title']")
35
+ first!("./*[@data-type = 'document-title' or @data-type = 'title']")
30
36
  end
31
37
 
32
- # Returns true if this class represents the element for the given node
38
+ # Returns true if this page is a book index
33
39
  #
34
- # @param node [Nokogiri::XML::Node] the underlying node
35
40
  # @return [Boolean]
36
41
  #
37
- def self.is_the_element_class_for?(node)
38
- node['data-type'] == 'composite-page'
42
+ def is_index?
43
+ has_class?('os-index-container')
39
44
  end
40
45
 
41
- # Returns true if this page is a book index
46
+ # Returns true if this page is a book reference
42
47
  #
43
48
  # @return [Boolean]
44
49
  #
45
- def is_index?
46
- has_class?('os-index-container')
50
+ def is_reference?
51
+ has_class?('os-reference-container')
47
52
  end
48
53
 
49
54
  end