openstax_kitchen 12.1.0 → 15.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +42 -0
  3. data/Gemfile +1 -0
  4. data/Gemfile.lock +3 -3
  5. data/codecov.yaml +4 -0
  6. data/lib/kitchen/directions/bake_all_chapter_solutions_types.rb +30 -0
  7. data/lib/kitchen/directions/bake_all_numbered_exercise_types.rb +26 -0
  8. data/lib/kitchen/directions/bake_annotation_classes/main.rb +2 -2
  9. data/lib/kitchen/directions/bake_annotation_classes/v1.rb +3 -3
  10. data/lib/kitchen/directions/bake_appendix.rb +1 -0
  11. data/lib/kitchen/directions/bake_autotitled_exercise/main.rb +4 -0
  12. data/lib/kitchen/directions/bake_autotitled_exercise/v2.rb +33 -0
  13. data/lib/kitchen/directions/bake_chapter_glossary/v1.rb +3 -1
  14. data/lib/kitchen/directions/bake_chapter_references/v1.rb +1 -1
  15. data/lib/kitchen/directions/bake_chapter_solutions/v1.rb +1 -1
  16. data/lib/kitchen/directions/bake_chapter_summary.rb +1 -1
  17. data/lib/kitchen/directions/bake_example.rb +1 -1
  18. data/lib/kitchen/directions/bake_figure.rb +1 -15
  19. data/lib/kitchen/directions/bake_iframes/v1.rb +2 -0
  20. data/lib/kitchen/directions/bake_index/v1.xhtml.erb +5 -9
  21. data/lib/kitchen/directions/bake_injected_exercise/add_injected_exercise_id.rb +16 -0
  22. data/lib/kitchen/directions/{bake_injected_exercise_question.rb → bake_injected_exercise/bake_injected_exercise_question.rb} +0 -0
  23. data/lib/kitchen/directions/bake_learning_objectives.rb +13 -0
  24. data/lib/kitchen/directions/bake_notes/bake_autotitled_notes.rb +1 -14
  25. data/lib/kitchen/directions/bake_notes/bake_note_exercise.rb +54 -0
  26. data/lib/kitchen/directions/bake_notes/bake_note_injected_question.rb +15 -0
  27. data/lib/kitchen/directions/bake_notes/bake_numbered_notes/main.rb +0 -31
  28. data/lib/kitchen/directions/bake_notes/bake_numbered_notes/v1.rb +2 -2
  29. data/lib/kitchen/directions/bake_notes/bake_numbered_notes/v2.rb +2 -2
  30. data/lib/kitchen/directions/bake_notes/bake_numbered_notes/v3.rb +2 -2
  31. data/lib/kitchen/directions/bake_notes/bake_unclassified_notes.rb +5 -3
  32. data/lib/kitchen/directions/bake_numbered_exercise/main.rb +8 -3
  33. data/lib/kitchen/directions/bake_numbered_exercise/v1.rb +48 -7
  34. data/lib/kitchen/directions/bake_numbered_table/bake_table_body.rb +6 -0
  35. data/lib/kitchen/directions/bake_references/main.rb +6 -9
  36. data/lib/kitchen/directions/bake_references/v1.rb +9 -8
  37. data/lib/kitchen/directions/bake_references/v2.rb +9 -10
  38. data/lib/kitchen/directions/bake_references/v3.rb +32 -0
  39. data/lib/kitchen/directions/bake_unnumbered_exercise.rb +16 -0
  40. data/lib/kitchen/directions/bake_unnumbered_figure.rb +26 -0
  41. data/lib/kitchen/directions/bake_unnumbered_tables.rb +1 -0
  42. data/lib/kitchen/directions/book_answer_key_container/eob_answer_key_container.xhtml.erb +9 -0
  43. data/lib/kitchen/directions/book_answer_key_container/v1.rb +6 -2
  44. data/lib/kitchen/directions/{eoc_composite_page_container → composite_page_container}/main.rb +1 -1
  45. data/lib/kitchen/directions/composite_page_container/v1.rb +28 -0
  46. data/lib/kitchen/directions/default_strategy_for_answer_key_solutions.rb +35 -0
  47. data/lib/kitchen/directions/move_custom_section_to_eoc_container/v1.rb +1 -1
  48. data/lib/kitchen/directions/move_solutions_to_answer_key/answer_key_inner_container.rb +29 -0
  49. data/lib/kitchen/element_base.rb +2 -18
  50. data/lib/kitchen/element_enumerator_base.rb +35 -0
  51. data/lib/kitchen/figure_element.rb +12 -4
  52. data/lib/kitchen/note_element.rb +7 -1
  53. data/lib/kitchen/patches/renderable.rb +1 -1
  54. data/lib/kitchen/section_element.rb +27 -0
  55. data/lib/kitchen/section_element_enumerator.rb +20 -0
  56. data/lib/kitchen/selectors/base.rb +3 -0
  57. data/lib/kitchen/selectors/standard_1.rb +1 -0
  58. data/lib/kitchen/table_element.rb +8 -0
  59. data/lib/kitchen/templates/composite_page_template.xhtml.erb +10 -0
  60. data/lib/kitchen/version.rb +1 -1
  61. data/lib/locales/en.yml +4 -0
  62. data/lib/locales/es.yml +9 -1
  63. data/lib/locales/pl.yml +3 -0
  64. metadata +20 -14
  65. data/lib/kitchen/directions/book_answer_key_container/eob_answer_key_outer_container.xhtml.erb +0 -9
  66. data/lib/kitchen/directions/eoc_composite_page_container/v1.rb +0 -19
  67. data/lib/kitchen/directions/move_solutions_to_answer_key/main.rb +0 -18
  68. data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/calculus.rb +0 -41
  69. data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/contemporary_math.rb +0 -40
  70. data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/default.rb +0 -27
  71. data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/precalculus.rb +0 -63
  72. data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/uphysics.rb +0 -21
  73. data/lib/kitchen/directions/move_solutions_to_answer_key/v1.rb +0 -45
  74. data/lib/kitchen/templates/eoc_section_template.xhtml.erb +0 -11
@@ -2,13 +2,25 @@
2
2
 
3
3
  module Kitchen::Directions::BakeNumberedExercise
4
4
  class V1
5
- def bake(exercise:, number:, suppress_solution_if: false,
6
- note_suppressed_solutions: false, cases: false)
5
+ # rubocop:disable Metrics/ParameterLists
6
+ def bake(exercise:, number:, suppress_solution_if:,
7
+ note_suppressed_solutions:, cases:, solution_stays_put:)
7
8
  problem = exercise.problem
8
9
  solution = exercise.solution
9
10
 
11
+ in_appendix = exercise.has_ancestor?(:page) && exercise.ancestor(:page).has_class?('appendix')
12
+
10
13
  # Store label information
11
- label_number = "#{exercise.ancestor(:chapter).count_in(:book)}.#{number}"
14
+ if in_appendix
15
+ label_number = number
16
+ title_label = "<span class=\"os-title-label\">#{I18n.t('exercise')}</span>"
17
+ problem_divider = ''
18
+ else
19
+ label_number = "#{exercise.ancestor(:chapter).count_in(:book)}.#{number}"
20
+ title_label = ''
21
+ problem_divider = "<span class='os-divider'>. </span>"
22
+ end
23
+
12
24
  exercise.target_label(label_text: 'exercise', custom_content: label_number, cases: cases)
13
25
 
14
26
  problem_number = "<span class='os-number'>#{number}</span>"
@@ -26,25 +38,54 @@ module Kitchen::Directions::BakeNumberedExercise
26
38
  solution.trash
27
39
  exercise.add_class('os-hasSolution-trashed') if note_suppressed_solutions
28
40
  else
29
- problem_number = "<a class='os-number' href='##{exercise.id}-solution'>#{number}</a>"
30
- bake_solution(exercise: exercise, number: number)
41
+ problem_number = \
42
+ if solution_stays_put || in_appendix
43
+ "<span class='os-number'>#{number}</span>"
44
+ else
45
+ "<a class='os-number' href='##{exercise.id}-solution'>#{number}</a>"
46
+ end
47
+ bake_solution(
48
+ exercise: exercise,
49
+ number: number,
50
+ solution_stays_put: solution_stays_put,
51
+ in_appendix: in_appendix
52
+ )
31
53
  end
32
54
  end
33
55
 
34
56
  problem.replace_children(with:
35
57
  <<~HTML
58
+ #{title_label}
36
59
  #{problem_number}
37
- <span class='os-divider'>. </span>
60
+ #{problem_divider}
38
61
  <div class="os-problem-container">#{problem.children}</div>
39
62
  HTML
40
63
  )
41
64
  end
65
+ # rubocop:enable Metrics/ParameterLists
42
66
 
43
- def bake_solution(exercise:, number:, divider: '. ')
67
+ def bake_solution(exercise:, number:, solution_stays_put:, divider: '. ', in_appendix: false)
44
68
  solution = exercise.solution
69
+ if solution_stays_put
70
+ solution.wrap_children(class: 'os-solution-container')
71
+ solution.prepend(child:
72
+ <<~HTML
73
+ <h4 class="solution-title" data-type="title">
74
+ <span class="os-text">#{I18n.t(:solution)}</span>
75
+ </h4>
76
+ HTML
77
+ )
78
+ return
79
+ end
80
+
45
81
  solution.id = "#{exercise.id}-solution"
46
82
  exercise.add_class('os-hasSolution')
47
83
 
84
+ if in_appendix
85
+ solution.wrap_children(class: 'os-solution-container')
86
+ return
87
+ end
88
+
48
89
  solution.replace_children(with:
49
90
  <<~HTML
50
91
  <a class='os-number' href='##{exercise.id}'>#{number}</a>
@@ -62,6 +62,12 @@ module Kitchen
62
62
  elsif table.column_header?
63
63
  custom_table = CustomBody.new(table: table, klass: 'column-header')
64
64
  custom_table.modify_body(has_fake_title: false)
65
+ elsif table.text_heavy?
66
+ custom_table = CustomBody.new(table: table, klass: 'text-heavy')
67
+ custom_table.modify_body(has_fake_title: false)
68
+ elsif table.unstyled?
69
+ custom_table = CustomBody.new(table: table, klass: 'unstyled')
70
+ custom_table.modify_body(has_fake_title: false)
65
71
  end
66
72
  end
67
73
  end
@@ -6,18 +6,15 @@ module Kitchen
6
6
  #
7
7
  module BakeReferences
8
8
  def self.v1(book:, metadata_source:, numbered_title: false)
9
- V1.new.bake(
10
- book: book,
11
- metadata_source: metadata_source,
12
- numbered_title: numbered_title
13
- )
9
+ V1.new.bake(book: book, metadata_source: metadata_source, numbered_title: numbered_title)
14
10
  end
15
11
 
16
12
  def self.v2(book:, metadata_source:)
17
- V2.new.bake(
18
- book: book,
19
- metadata_source: metadata_source
20
- )
13
+ V2.new.bake(book: book, metadata_source: metadata_source)
14
+ end
15
+
16
+ def self.v3(book:, metadata_source:)
17
+ V3.new.bake(book: book, metadata_source: metadata_source)
21
18
  end
22
19
  end
23
20
  end
@@ -5,11 +5,6 @@ module Kitchen::Directions::BakeReferences
5
5
  renderable
6
6
 
7
7
  def bake(book:, metadata_source:, numbered_title:)
8
- @metadata = metadata_source.children_to_keep.copy
9
- @klass = 'reference'
10
- @uuid_prefix = '.'
11
- @title = I18n.t(:references)
12
-
13
8
  book.chapters.each do |chapter|
14
9
  chapter.search('[data-type="cite"]').each do |link|
15
10
  link.prepend(child:
@@ -44,10 +39,16 @@ module Kitchen::Directions::BakeReferences
44
39
  HTML
45
40
  )
46
41
  end
42
+
47
43
  chapter_area_references = book.chapters.search('.os-chapter-area').cut
48
- @content = chapter_area_references.paste
49
- book.body.append(child: render(file:
50
- '../../templates/eob_section_title_template.xhtml.erb'))
44
+
45
+ Kitchen::Directions::CompositePageContainer.v1(
46
+ container_key: 'reference',
47
+ uuid_key: '.reference',
48
+ metadata_source: metadata_source,
49
+ content: chapter_area_references.paste,
50
+ append_to: book.body
51
+ )
51
52
  end
52
53
  end
53
54
  end
@@ -2,14 +2,7 @@
2
2
 
3
3
  module Kitchen::Directions::BakeReferences
4
4
  class V2
5
- renderable
6
-
7
5
  def bake(book:, metadata_source:)
8
- @metadata = metadata_source.children_to_keep.copy
9
- @klass = 'references'
10
- @uuid_prefix = '.'
11
- @title = I18n.t(:references)
12
-
13
6
  book.chapters.each do |chapter|
14
7
 
15
8
  chapter.references.search('h3').trash
@@ -26,10 +19,16 @@ module Kitchen::Directions::BakeReferences
26
19
  HTML
27
20
  )
28
21
  end
22
+
29
23
  chapter_area_references = book.chapters.search('.os-chapter-area').cut
30
- @content = chapter_area_references.paste
31
- book.body.append(child: render(file:
32
- '../../templates/eob_section_title_template.xhtml.erb'))
24
+
25
+ Kitchen::Directions::CompositePageContainer.v1(
26
+ container_key: 'references',
27
+ uuid_key: '.references',
28
+ metadata_source: metadata_source,
29
+ content: chapter_area_references.paste,
30
+ append_to: book.body
31
+ )
33
32
  end
34
33
  end
35
34
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen::Directions::BakeReferences
4
+ class V3
5
+ def bake(book:, metadata_source:)
6
+ return unless book.references.any?
7
+
8
+ book.chapters.pages.each do |page|
9
+ page.references.each do |reference|
10
+ reference.titles.trash
11
+ reference.prepend(child:
12
+ Kitchen::Directions::EocSectionTitleLinkSnippet.v1(
13
+ page: page,
14
+ title_tag: 'h2',
15
+ wrapper: nil
16
+ )
17
+ )
18
+ end
19
+ end
20
+
21
+ chapter_area_references = book.chapters.references.cut
22
+
23
+ Kitchen::Directions::CompositePageContainer.v1(
24
+ container_key: 'references',
25
+ uuid_key: '.references',
26
+ metadata_source: metadata_source,
27
+ content: chapter_area_references.paste,
28
+ append_to: book.body
29
+ )
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ module Directions
5
+ module BakeUnnumberedExercise
6
+ def self.v1(exercise:)
7
+ exercise.problem.wrap_children(class: 'os-problem-container')
8
+ return unless exercise.solution
9
+
10
+ exercise.solutions.each do |solution|
11
+ solution.wrap_children(class: 'os-solution-container')
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ module Directions
5
+ module BakeUnnumberedFigure
6
+ def self.v1(book:)
7
+ book.figures(only: :unnumbered?).each do |figure|
8
+ next unless figure.caption || figure.title
9
+
10
+ figure.wrap(%(<div class="os-figure#{' has-splash' if figure.has_class?('splash')}">))
11
+ title = figure.title&.cut
12
+ caption = figure.caption&.cut
13
+ figure.append(sibling:
14
+ <<~HTML
15
+ <div class="os-caption-container">
16
+ #{"<span class=\"os-title\" data-type=\"title\" id=\"#{title.id}\">#{title.children}</span>" if title}
17
+ #{'<span class="os-divider"> </span>' if title && caption}
18
+ #{"<span class=\"os-caption\">#{caption.children}</span>" if caption}
19
+ </div>
20
+ HTML
21
+ )
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -9,6 +9,7 @@ module Kitchen
9
9
  table.remove_attribute('summary')
10
10
  table.parent.add_class('os-unstyled-container') if table.unstyled?
11
11
  table.parent.add_class('os-column-header-container') if table.column_header?
12
+ table.parent.add_class('os-top-titled-container') if table.top_titled?
12
13
  end
13
14
  end
14
15
  end
@@ -0,0 +1,9 @@
1
+ <div class="os-eob os-<%= @solutions_or_solution %>-container" data-type="<%= @composite_element %>" data-uuid-key=".<%= @uuid_key %>">
2
+ <<%= @main_title_tag %> data-type="document-title">
3
+ <span class="os-text"><%= @title %></span>
4
+ </<%= @main_title_tag %>>
5
+ <div data-type="metadata" style="display: none;">
6
+ <h1 data-type="document-title" itemprop="name"><%= @title %></h1>
7
+ <%= @metadata.paste %>
8
+ </div>
9
+ </div>
@@ -4,10 +4,14 @@ module Kitchen::Directions::BookAnswerKeyContainer
4
4
  class V1
5
5
  renderable
6
6
 
7
- def bake(book:, solutions_plural: true)
7
+ def bake(book:, solutions_plural:)
8
+ @composite_element = 'composite-chapter'
8
9
  @metadata = book.metadata.children_to_keep.copy
9
10
  @solutions_or_solution = solutions_plural ? 'solutions' : 'solution'
10
- book.body.append(child: render(file: 'eob_answer_key_outer_container.xhtml.erb'))
11
+ @title = I18n.t(:answer_key_title)
12
+ @main_title_tag = 'h1'
13
+ @uuid_key = @solutions_or_solution
14
+ book.body.append(child: render(file: 'eob_answer_key_container.xhtml.erb'))
11
15
  book.body.first("div.os-eob.os-#{@solutions_or_solution}-container")
12
16
  end
13
17
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Kitchen
4
4
  module Directions
5
- module EocCompositePageContainer
5
+ module CompositePageContainer
6
6
  # Creates a wrapper for the given content & appends it to the given element
7
7
  #
8
8
  # @param container_key [String] Appended to 'eoc.' to form the I18n key for the container title; also used as part of a class on the container.
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen::Directions::CompositePageContainer
4
+ class V1
5
+ renderable
6
+
7
+ def bake(container_key:, uuid_key:, metadata_source:, content:, append_to:)
8
+ @in_composite_chapter = append_to.is?(:composite_chapter)
9
+ @is_eoc = append_to.is?(:chapter) || @in_composite_chapter
10
+ @section = @is_eoc ? 'eoc' : 'eob'
11
+ @title = I18n.t(:"#{@section}.#{container_key}")
12
+ @uuid_key = uuid_key
13
+ @container_class_type = container_key
14
+ @metadata = metadata_source.children_to_keep.copy
15
+ @content = content
16
+ @main_title_tag = 'h1'
17
+
18
+ if @in_composite_chapter
19
+ @main_title_tag = 'h3'
20
+ elsif @is_eoc
21
+ @main_title_tag = 'h2'
22
+ end
23
+
24
+ append_to.append(child: render(file:
25
+ '../../templates/composite_page_template.xhtml.erb'))
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen::Directions::DefaultStrategyForAnswerKeySolutions
4
+ def self.v1(strategy_options:, chapter:, append_to:)
5
+ V1.new(
6
+ strategy_options
7
+ ).bake(
8
+ chapter: chapter,
9
+ append_to: append_to
10
+ )
11
+ end
12
+
13
+ class V1
14
+ def bake(chapter:, append_to:)
15
+ bake_section(chapter: chapter, append_to: append_to)
16
+ end
17
+
18
+ protected
19
+
20
+ def bake_section(chapter:, append_to:)
21
+ @selectors.each do |selector|
22
+ chapter.search("#{selector} div[data-type='solution']").each do |solution|
23
+ append_to.append(child: solution.cut.to_s) unless @condition.present? && !@condition
24
+ end
25
+ end
26
+ end
27
+
28
+ # This method helps to obtain more strategy-specific params through
29
+ # "strategy_options: {blah1: 1, blah2: 2}"
30
+ def initialize(strategy_options)
31
+ @selectors = strategy_options[:selectors] || (raise 'missing selectors for strategy')
32
+ @condition = strategy_options[:condition]
33
+ end
34
+ end
35
+ end
@@ -30,7 +30,7 @@ module Kitchen::Directions::MoveCustomSectionToEocContainer
30
30
  section_clipboard.paste
31
31
  end
32
32
 
33
- Kitchen::Directions::EocCompositePageContainer.v1(
33
+ Kitchen::Directions::CompositePageContainer.v1(
34
34
  container_key: container_key,
35
35
  uuid_key: uuid_key,
36
36
  metadata_source: metadata_source,
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen::Directions::AnswerKeyInnerContainer
4
+ def self.v1(chapter:, metadata_source:, append_to:, solutions_plural: true)
5
+ V1.new.bake(
6
+ chapter: chapter,
7
+ metadata_source: metadata_source,
8
+ append_to: append_to,
9
+ solutions_plural: solutions_plural
10
+ )
11
+ end
12
+
13
+ class V1
14
+ renderable
15
+
16
+ def bake(chapter:, metadata_source:, append_to:, solutions_plural:)
17
+ @solutions_or_solution = solutions_plural ? 'solutions' : 'solution'
18
+ @uuid_key = "#{@solutions_or_solution}#{chapter.count_in(:book)}"
19
+ @metadata = metadata_source.children_to_keep.copy
20
+ @composite_element = 'composite-page'
21
+ @title = "#{I18n.t(:chapter)} #{chapter.count_in(:book)}"
22
+ @main_title_tag = 'h2'
23
+
24
+ append_to.append(
25
+ child: render(file: '../book_answer_key_container/eob_answer_key_container.xhtml.erb')
26
+ ).first("div[data-uuid-key='.#{@uuid_key}']")
27
+ end
28
+ end
29
+ end
@@ -427,23 +427,6 @@ module Kitchen
427
427
  )
428
428
  end
429
429
 
430
- # Searches for elements handled by a list of enumerator classes. All element that
431
- # matches one of those enumerator classes are iterated over.
432
- #
433
- # @param enumerator_classes [Array<ElementEnumeratorBase>]
434
- # @return [TypeCastingElementEnumerator]
435
- #
436
- def search_with(*enumerator_classes)
437
- block_error_if(block_given?)
438
- raise 'must supply at least one enumerator class' if enumerator_classes.empty?
439
-
440
- factory = enumerator_classes[0].factory
441
- enumerator_classes[1..-1].each do |enumerator_class|
442
- factory = factory.or_with(enumerator_class.factory)
443
- end
444
- factory.build_within(self)
445
- end
446
-
447
430
  # Removes the element from its parent and places it on the specified clipboard
448
431
  #
449
432
  # @param to [Symbol, String, Clipboard, nil] the name of the clipboard (or a Clipboard
@@ -770,7 +753,8 @@ module Kitchen
770
753
  # Returns a pages enumerator
771
754
  def_delegators :as_enumerator, :pages, :chapters, :terms, :figures, :notes, :tables, :examples,
772
755
  :metadatas, :non_introduction_pages, :units, :titles, :exercises, :references,
773
- :composite_pages, :composite_chapters, :solutions, :injected_questions
756
+ :composite_pages, :composite_chapters, :solutions, :injected_questions,
757
+ :search_with, :sections
774
758
 
775
759
  # Returns this element as an enumerator (over only one element, itself)
776
760
  #
@@ -318,6 +318,24 @@ module Kitchen
318
318
  css_or_xpath: css_or_xpath, only: only, except: except)
319
319
  end
320
320
 
321
+ # Returns an enumerator that iterates through sections within the scope of this enumerator
322
+ #
323
+ # @param css_or_xpath [String] additional selectors to further narrow the element iterated over;
324
+ # a "$" in this argument will be replaced with the default selector for the element being
325
+ # iterated over.
326
+ # @param only [Symbol, Callable] the name of a method to call on an element or a
327
+ # lambda or proc that accepts an element; elements will only be included in the
328
+ # search results if the method or callable returns true
329
+ # @param except [Symbol, Callable] the name of a method to call on an element or a
330
+ # lambda or proc that accepts an element; elements will not be included in the
331
+ # search results if the method or callable returns false
332
+ #
333
+ def sections(css_or_xpath=nil, only: nil, except: nil)
334
+ block_error_if(block_given?)
335
+ chain_to(SectionElementEnumerator,
336
+ css_or_xpath: css_or_xpath, only: only, except: except)
337
+ end
338
+
321
339
  # Returns an enumerator that iterates within the scope of this enumerator
322
340
  #
323
341
  # @param css_or_xpath [String] additional selectors to further narrow the element iterated over
@@ -327,6 +345,23 @@ module Kitchen
327
345
  chain_to(ElementEnumerator, css_or_xpath: css_or_xpath, only: only, except: except)
328
346
  end
329
347
 
348
+ # Searches for elements handled by a list of enumerator classes. All element that
349
+ # matches one of those enumerator classes are iterated over.
350
+ #
351
+ # @param enumerator_classes [Array<ElementEnumeratorBase>]
352
+ # @return [TypeCastingElementEnumerator]
353
+ #
354
+ def search_with(*enumerator_classes)
355
+ block_error_if(block_given?)
356
+ raise 'must supply at least one enumerator class' if enumerator_classes.empty?
357
+
358
+ factory = enumerator_classes[0].factory
359
+ enumerator_classes[1..-1].each do |enumerator_class|
360
+ factory = factory.or_with(enumerator_class.factory)
361
+ end
362
+ factory.build_within(self)
363
+ end
364
+
330
365
  # Returns an enumerator that iterates through elements within the scope of this enumerator
331
366
  #
332
367
  # @param enumerator_class [ElementEnumeratorBase] the enumerator to use for the iteration
@@ -47,16 +47,24 @@ module Kitchen
47
47
  parent.name == 'figure'
48
48
  end
49
49
 
50
+ # Returns true if the figure is unnumbered
51
+ #
52
+ # @return [Boolean]
53
+ #
54
+
55
+ def unnumbered?
56
+ has_class?('unnumbered')
57
+ end
58
+
50
59
  # Returns true unless the figure is a subfigure or has the 'unnumbered' class,
51
60
  # unless the figure has both the 'unnumbered' and the 'splash' classes.
52
61
  #
53
62
  # @return [Boolean]
54
- #
55
- def figure_to_bake?
56
- return false if subfigure? || (has_class?('unnumbered') && !has_class?('splash') && !caption)
63
+
64
+ def figure_to_number?
65
+ return false if subfigure? || unnumbered?
57
66
 
58
67
  true
59
68
  end
60
-
61
69
  end
62
70
  end
@@ -33,7 +33,9 @@ module Kitchen
33
33
  # 1. it is the note body's first child
34
34
  # 2. it is the first child's first child and the first child is a paragraph
35
35
  first_child = first_note_body_child
36
- first_grandchild = first_child&.element_children&.[](0) if first_child.name == 'p'
36
+ return unless first_child
37
+
38
+ first_grandchild = get_first_grandchild_for_title(first_child)
37
39
 
38
40
  if first_child.data_type == 'title'
39
41
  first_child
@@ -47,6 +49,10 @@ module Kitchen
47
49
  note_body ? note_body.element_children[0] : element_children[0]
48
50
  end
49
51
 
52
+ def get_first_grandchild_for_title(first_child)
53
+ first_child&.element_children&.[](0) if first_child.name == 'p'
54
+ end
55
+
50
56
  # Returns true if the note's title is autogenerated
51
57
  #
52
58
  # @return [Boolean]
@@ -29,7 +29,7 @@ class Object
29
29
  def render(file:)
30
30
  file = File.absolute_path(file, renderable_base_dir)
31
31
  template = File.open(file, 'rb', &:read)
32
- ERB.new(template).result(binding)
32
+ ERB.new(template, trim_mode: '-').result(binding)
33
33
  end
34
34
  end
35
35
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ # An element for an example
5
+ #
6
+ class SectionElement < ElementBase
7
+
8
+ # Creates a new +SectionElement+
9
+ #
10
+ # @param node [Nokogiri::XML::Node] the node this element wraps
11
+ # @param document [Document] this element's document
12
+ #
13
+ def initialize(node:, document: nil)
14
+ super(node: node,
15
+ document: document,
16
+ enumerator_class: SectionElementEnumerator)
17
+ end
18
+
19
+ # Returns the short type
20
+ # @return [Symbol]
21
+ #
22
+ def self.short_type
23
+ :section
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ # An enumerator for table elements
5
+ #
6
+ class SectionElementEnumerator < ElementEnumeratorBase
7
+ # Returns a factory for this enumerator
8
+ #
9
+ # @return [ElementEnumeratorFactory]
10
+ #
11
+ def self.factory
12
+ ElementEnumeratorFactory.new(
13
+ default_css_or_xpath: Selector.named(:section),
14
+ sub_element_class: SectionElement,
15
+ enumerator_class: self
16
+ )
17
+ end
18
+
19
+ end
20
+ end
@@ -62,6 +62,9 @@ module Kitchen
62
62
  # Selector for an injected question
63
63
  # @return [String]
64
64
  attr_accessor :injected_question
65
+ # Selector for a section
66
+ # @return [String]
67
+ attr_accessor :section
65
68
 
66
69
  # Override specific selectors
67
70
  #
@@ -29,6 +29,7 @@ module Kitchen
29
29
  self.solution = "div[data-type='solution'], " \
30
30
  "div[data-type='question-solution']"
31
31
  self.injected_question = "div[data-type='exercise-question']"
32
+ self.section = 'section'
32
33
  end
33
34
 
34
35
  end
@@ -97,6 +97,14 @@ module Kitchen
97
97
  has_class?('column-header')
98
98
  end
99
99
 
100
+ # Returns true if the table is text heavy
101
+ #
102
+ # @return [Boolean]
103
+ #
104
+ def text_heavy?
105
+ has_class?('text-heavy')
106
+ end
107
+
100
108
  # Returns an element for the table caption, if present
101
109
  #
102
110
  # @return [Element, nil]