openstax_kitchen 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/devcontainer.json +37 -17
  3. data/.github/config.yml +14 -0
  4. data/.github/workflows/tests.yml +5 -15
  5. data/.gitignore +1 -1
  6. data/.inch.yml +6 -0
  7. data/.rubocop.yml +65 -0
  8. data/CHANGELOG.md +16 -0
  9. data/Gemfile +5 -3
  10. data/Gemfile.lock +54 -5
  11. data/README.md +58 -11
  12. data/Rakefile +5 -3
  13. data/bin/console +4 -3
  14. data/docker/Dockerfile +36 -0
  15. data/docker/Dockerfile.ci +10 -0
  16. data/docker/bash +5 -1
  17. data/docker/build +10 -0
  18. data/docker/ci +16 -0
  19. data/docker/run +9 -0
  20. data/docker/tag_and_push_latest +17 -0
  21. data/lefthook.yml +6 -0
  22. data/lib/kitchen/ancestor.rb +38 -1
  23. data/lib/kitchen/book_document.rb +20 -2
  24. data/lib/kitchen/book_element.rb +24 -3
  25. data/lib/kitchen/book_element_enumerator.rb +4 -0
  26. data/lib/kitchen/book_recipe.rb +15 -1
  27. data/lib/kitchen/chapter_element.rb +43 -3
  28. data/lib/kitchen/chapter_element_enumerator.rb +9 -1
  29. data/lib/kitchen/clipboard.rb +35 -4
  30. data/lib/kitchen/composite_chapter_element.rb +20 -1
  31. data/lib/kitchen/composite_page_element.rb +25 -2
  32. data/lib/kitchen/composite_page_element_enumerator.rb +8 -0
  33. data/lib/kitchen/config.rb +14 -7
  34. data/lib/kitchen/counter.rb +9 -2
  35. data/lib/kitchen/debug/print_recipe_error.rb +53 -35
  36. data/lib/kitchen/directions/.rubocop.yml +22 -0
  37. data/lib/kitchen/directions/bake_appendix.rb +4 -4
  38. data/lib/kitchen/directions/bake_chapter_glossary.rb +10 -7
  39. data/lib/kitchen/directions/bake_chapter_introductions.rb +6 -6
  40. data/lib/kitchen/directions/bake_chapter_key_equations.rb +9 -6
  41. data/lib/kitchen/directions/bake_chapter_summary.rb +16 -13
  42. data/lib/kitchen/directions/bake_chapter_title/main.rb +11 -0
  43. data/lib/kitchen/directions/bake_chapter_title/v1.rb +24 -0
  44. data/lib/kitchen/directions/bake_composite_pages.rb +2 -2
  45. data/lib/kitchen/directions/bake_example.rb +6 -4
  46. data/lib/kitchen/directions/bake_exercises/main.rb +11 -0
  47. data/lib/kitchen/directions/bake_exercises/v1.rb +166 -0
  48. data/lib/kitchen/directions/bake_figure.rb +8 -5
  49. data/lib/kitchen/directions/bake_footnotes/main.rb +2 -2
  50. data/lib/kitchen/directions/bake_footnotes/v1.rb +4 -4
  51. data/lib/kitchen/directions/bake_index/main.rb +2 -2
  52. data/lib/kitchen/directions/bake_index/v1.rb +22 -15
  53. data/lib/kitchen/directions/bake_link_placeholders.rb +24 -0
  54. data/lib/kitchen/directions/bake_math_in_paragraph.rb +5 -3
  55. data/lib/kitchen/directions/bake_notes.rb +8 -8
  56. data/lib/kitchen/directions/bake_numbered_table/main.rb +2 -2
  57. data/lib/kitchen/directions/bake_numbered_table/v1.rb +21 -16
  58. data/lib/kitchen/directions/bake_page_abstracts.rb +14 -0
  59. data/lib/kitchen/directions/bake_preface/main.rb +11 -0
  60. data/lib/kitchen/directions/bake_preface/v1.rb +18 -0
  61. data/lib/kitchen/directions/bake_stepwise.rb +7 -7
  62. data/lib/kitchen/directions/bake_suggested_reading.rb +26 -0
  63. data/lib/kitchen/directions/bake_toc.rb +41 -22
  64. data/lib/kitchen/directions/bake_unit_title/main.rb +11 -0
  65. data/lib/kitchen/directions/bake_unit_title/v1.rb +23 -0
  66. data/lib/kitchen/directions/bake_unnumbered_tables.rb +7 -5
  67. data/lib/kitchen/directions/move_title_text_into_span.rb +2 -2
  68. data/lib/kitchen/document.rb +72 -13
  69. data/lib/kitchen/element.rb +11 -0
  70. data/lib/kitchen/element_base.rb +276 -56
  71. data/lib/kitchen/element_enumerator.rb +8 -0
  72. data/lib/kitchen/element_enumerator_base.rb +210 -28
  73. data/lib/kitchen/element_enumerator_factory.rb +59 -52
  74. data/lib/kitchen/element_factory.rb +27 -12
  75. data/lib/kitchen/errors.rb +5 -0
  76. data/lib/kitchen/example_element.rb +19 -1
  77. data/lib/kitchen/example_element_enumerator.rb +9 -1
  78. data/lib/kitchen/figure_element.rb +36 -2
  79. data/lib/kitchen/figure_element_enumerator.rb +9 -1
  80. data/lib/kitchen/metadata_element.rb +28 -0
  81. data/lib/kitchen/metadata_element_enumerator.rb +21 -0
  82. data/lib/kitchen/mixins/block_error_if.rb +24 -4
  83. data/lib/kitchen/note_element.rb +37 -7
  84. data/lib/kitchen/note_element_enumerator.rb +9 -1
  85. data/lib/kitchen/oven.rb +66 -15
  86. data/lib/kitchen/page_element.rb +62 -13
  87. data/lib/kitchen/page_element_enumerator.rb +9 -1
  88. data/lib/kitchen/pantry.rb +28 -1
  89. data/lib/kitchen/patches/nokogiri.rb +19 -2
  90. data/lib/kitchen/patches/renderable.rb +9 -3
  91. data/lib/kitchen/patches/string.rb +8 -0
  92. data/lib/kitchen/recipe.rb +38 -34
  93. data/lib/kitchen/search_history.rb +43 -4
  94. data/lib/kitchen/search_query.rb +84 -0
  95. data/lib/kitchen/selectors/base.rb +26 -0
  96. data/lib/kitchen/selectors/standard_1.rb +8 -0
  97. data/lib/kitchen/table_element.rb +54 -3
  98. data/lib/kitchen/table_element_enumerator.rb +9 -1
  99. data/lib/kitchen/term_element.rb +15 -1
  100. data/lib/kitchen/term_element_enumerator.rb +9 -1
  101. data/lib/kitchen/transliterations.rb +7 -5
  102. data/lib/kitchen/type_casting_element_enumerator.rb +17 -1
  103. data/lib/kitchen/unit_element.rb +39 -0
  104. data/lib/kitchen/unit_element_enumerator.rb +20 -0
  105. data/lib/kitchen/utils.rb +10 -13
  106. data/lib/kitchen/version.rb +5 -1
  107. data/lib/locales/en.yml +6 -0
  108. data/lib/openstax_kitchen.rb +43 -42
  109. data/openstax_kitchen.gemspec +26 -20
  110. data/tutorials/00/solution1.rb +9 -0
  111. data/tutorials/00/solution2.rb +8 -0
  112. data/tutorials/01/solution1.rb +18 -0
  113. data/tutorials/01/solution2.rb +26 -0
  114. data/tutorials/02/solution1.rb +31 -0
  115. data/tutorials/03/{solution_1.rb → solution1.rb} +6 -4
  116. data/tutorials/03/solution2.rb +18 -0
  117. data/tutorials/04/{solution_1.rb → solution1.rb} +4 -2
  118. data/tutorials/04/{solution_2.rb → solution2.rb} +6 -4
  119. data/tutorials/05/solution1.rb +11 -0
  120. data/tutorials/check_it +16 -15
  121. data/tutorials/setup_my_recipes +7 -6
  122. metadata +101 -22
  123. data/Dockerfile +0 -19
  124. data/docker-compose.yml +0 -12
  125. data/docker/entrypoint +0 -9
  126. data/lib/kitchen/directions/bake_exercises.rb +0 -164
  127. data/tutorials/00/solution_1.rb +0 -7
  128. data/tutorials/00/solution_2.rb +0 -6
  129. data/tutorials/01/solution_1.rb +0 -16
  130. data/tutorials/01/solution_2.rb +0 -24
  131. data/tutorials/02/solution_1.rb +0 -29
  132. data/tutorials/03/solution_2.rb +0 -15
  133. data/tutorials/05/solution_1.rb +0 -9
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kitchen::Directions::BakeFootnotes
2
4
  class V1
3
5
 
@@ -26,12 +28,10 @@ module Kitchen::Directions::BakeFootnotes
26
28
  aside_id_to_footnote_number[aside_id] = footnote_number
27
29
  end
28
30
 
29
-
30
- container.search("aside").each do |aside|
31
+ container.search('aside').each do |aside|
31
32
  footnote_number = aside_id_to_footnote_number[aside.id]
32
- aside.prepend(child: "<div class='footnote-number'>#{footnote_number}</div>")
33
+ aside.prepend(child: "<div data-type='footnote-number'>#{footnote_number}</div>")
33
34
  end
34
-
35
35
  end
36
36
 
37
37
  end
@@ -1,11 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kitchen
2
4
  module Directions
3
5
  module BakeIndex
4
-
5
6
  def self.v1(book:)
6
7
  V1.new.bake(book: book)
7
8
  end
8
-
9
9
  end
10
10
  end
11
11
  end
@@ -1,9 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kitchen::Directions::BakeIndex
4
+ # Bake directions for eob index
5
+ #
2
6
  class V1
3
7
  renderable
4
8
 
5
9
  class Term
6
- attr_reader :text, :id, :group_by, :page_title
10
+ attr_reader :text
11
+ attr_reader :id
12
+ attr_reader :group_by
13
+ attr_reader :page_title
7
14
 
8
15
  def initialize(text:, id:, group_by:, page_title:)
9
16
  @text = text.strip
@@ -38,7 +45,7 @@ module Kitchen::Directions::BakeIndex
38
45
  end
39
46
 
40
47
  def <=>(other)
41
- self.sortable <=> other.sortable
48
+ sortable <=> other.sortable
42
49
  end
43
50
 
44
51
  protected
@@ -64,7 +71,8 @@ module Kitchen::Directions::BakeIndex
64
71
  def <=>(other)
65
72
  return -1 if force_first
66
73
  return 1 if other.force_first
67
- self.name <=> other.name
74
+
75
+ name <=> other.name
68
76
  end
69
77
 
70
78
  protected
@@ -107,8 +115,7 @@ module Kitchen::Directions::BakeIndex
107
115
  end
108
116
 
109
117
  def bake(book:)
110
- @metadata_elements = book.metadata.search(%w(.authors .publishers .print-style
111
- .permissions [data-type='subject'])).copy
118
+ @metadata_elements = book.metadata.children_to_keep.copy
112
119
  @index = Index.new
113
120
 
114
121
  book.pages.terms.each do |term_element|
@@ -117,21 +124,21 @@ module Kitchen::Directions::BakeIndex
117
124
  term_element.id = "auto_#{page.id}_term#{term_element.count_in(:book)}"
118
125
 
119
126
  group_by = term_element.text.strip[0]
120
- if !group_by.match? (/\w/)
121
- group_by = I18n.t(:eob_index_symbols_group)
122
- end
127
+ group_by = I18n.t(:eob_index_symbols_group) unless group_by.match?(/\w/)
123
128
  term_element['group-by'] = group_by
124
129
 
125
130
  # Add it to our index object
126
- @index.add_term(Term.new(
127
- text: term_element.text,
128
- id: term_element.id,
129
- group_by: group_by,
130
- page_title: page.title.text.gsub(/\n/,'')
131
- ))
131
+ @index.add_term(
132
+ Term.new(
133
+ text: term_element.text,
134
+ id: term_element.id,
135
+ group_by: group_by,
136
+ page_title: page.title.text.gsub(/\n/, '')
137
+ )
138
+ )
132
139
  end
133
140
 
134
- book.first("body").append(child: render(file: 'v1.xhtml.erb'))
141
+ book.first('body').append(child: render(file: 'v1.xhtml.erb'))
135
142
  end
136
143
 
137
144
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ module Directions
5
+ # Bake directions for link placeholders
6
+ #
7
+ module BakeLinkPlaceholders
8
+ def self.v1(book:)
9
+ book.search('a').each do |anchor|
10
+ next unless anchor.text == '[link]'
11
+
12
+ id = anchor[:href][1..-1]
13
+ replacement = book.document.pantry(name: :link_text).get(id)
14
+ if replacement.present?
15
+ anchor.replace_children(with: replacement)
16
+ else
17
+ # TODO: log a warning!
18
+ puts "warning! could not find a replacement for '[link]' on an element with ID '#{id}'"
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,13 +1,15 @@
1
+ # frozen-string-literal: true
2
+
1
3
  module Kitchen
2
4
  module Directions
5
+ # Wraps any math contained in a <p> tag
6
+ # with a <span> with class 'os-math-in-para'
3
7
  module BakeMathInParagraph
4
-
5
8
  def self.v1(book:)
6
- book.search("p m|math").each do |math|
9
+ book.search('p m|math', '//p//math | //p//m').each do |math|
7
10
  math.wrap("<span class='os-math-in-para'>")
8
11
  end
9
12
  end
10
-
11
13
  end
12
14
  end
13
15
  end
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kitchen
2
4
  module Directions
3
5
  module BakeNotes
4
-
5
6
  def self.v1(book:)
6
7
  book.notes.each do |note|
7
8
  title = note.title&.cut
@@ -22,23 +23,23 @@ module Kitchen
22
23
  HTML
23
24
  )
24
25
 
25
- title.name = "h4"
26
- title.add_class("os-subtitle")
26
+ title.name = 'h4'
27
+ title.add_class('os-subtitle')
27
28
  title.replace_children(with:
28
29
  <<~HTML
29
30
  <span class="os-subtitle-label">#{title.children}</span>
30
31
  HTML
31
32
  )
32
- note.first!(".os-note-body").prepend(child: title.raw)
33
+ note.first!('.os-note-body').prepend(child: title.raw)
33
34
  else
34
- title.name = "h3"
35
- title.add_class("os-title")
35
+ title.name = 'h3'
36
+ title.add_class('os-title')
36
37
  title.replace_children(with:
37
38
  <<~HTML
38
39
  <span data-type="" id="#{title.id}" class="os-title-label">#{title.children}</span>
39
40
  HTML
40
41
  )
41
- title.remove_attribute("id")
42
+ title.remove_attribute('id')
42
43
  note.prepend(child: title.raw)
43
44
  end
44
45
  else
@@ -52,7 +53,6 @@ module Kitchen
52
53
  end
53
54
  end
54
55
  end
55
-
56
56
  end
57
57
  end
58
58
  end
@@ -1,11 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kitchen
2
4
  module Directions
3
5
  module BakeNumberedTable
4
-
5
6
  def self.v1(table:, number:)
6
7
  V1.new.bake(table: table, number: number)
7
8
  end
8
-
9
9
  end
10
10
  end
11
11
  end
@@ -1,13 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kitchen::Directions::BakeNumberedTable
2
4
  class V1
3
5
 
4
6
  def bake(table:, number:)
5
- table.wrap(%Q(<div class="os-table">))
7
+ table.wrap(%(<div class="os-table">))
6
8
 
7
9
  table_label = "#{I18n.t(:table_label)} #{number}"
8
10
  table.document.pantry(name: :link_text).store table_label, label: table.id
9
11
 
10
12
  if table.top_titled?
13
+ table.parent.add_class('os-top-titled-container')
11
14
  table.prepend(sibling:
12
15
  <<~HTML
13
16
  <div class="os-table-title">#{table.title}</div>
@@ -16,9 +19,11 @@ module Kitchen::Directions::BakeNumberedTable
16
19
  table.title_row.trash
17
20
  end
18
21
 
19
- # TODO extra spaces added here to match legacy implementation, but probably not meaningful?
20
- new_summary = table_label + " "
21
- new_caption = ""
22
+ table.parent.add_class('os-column-header-container') if table.column_header?
23
+
24
+ # TODO: extra spaces added here to match legacy implementation, but probably not meaningful?
25
+ new_summary = "#{table_label} "
26
+ new_caption = ''
22
27
 
23
28
  if (caption = table.caption&.cut)
24
29
  new_summary += caption.text
@@ -29,18 +34,18 @@ module Kitchen::Directions::BakeNumberedTable
29
34
 
30
35
  table[:summary] = new_summary
31
36
 
32
- if !table.unnumbered?
33
- table.append(sibling:
34
- <<~HTML
35
- <div class="os-caption-container">
36
- <span class="os-title-label">#{I18n.t(:table_label)} </span>
37
- <span class="os-number">#{number}</span>
38
- <span class="os-divider"> </span>
39
- <span class="os-divider"> </span>#{new_caption}
40
- </div>
41
- HTML
42
- )
43
- end
37
+ return if table.unnumbered?
38
+
39
+ table.append(sibling:
40
+ <<~HTML
41
+ <div class="os-caption-container">
42
+ <span class="os-title-label">#{I18n.t(:table_label)} </span>
43
+ <span class="os-number">#{number}</span>
44
+ <span class="os-divider"> </span>
45
+ <span class="os-divider"> </span>#{new_caption}
46
+ </div>
47
+ HTML
48
+ )
44
49
  end
45
50
 
46
51
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ module Directions
5
+ # Adds learning objectives header to abstracts
6
+ module BakePageAbstracts
7
+ def self.v1(chapter:)
8
+ chapter.abstracts.each do |abstract|
9
+ abstract.prepend(child: "<h3 data-type='title'>#{I18n.t(:learning_objectives)}</h3>")
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ module Directions
5
+ module BakePreface
6
+ def self.v1(book:)
7
+ V1.new.bake(book: book)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen::Directions::BakePreface
4
+ class V1
5
+ def bake(book:)
6
+ book.pages('$.preface').each do |page|
7
+ page.titles.each do |title|
8
+ title.replace_children(with:
9
+ <<~HTML
10
+ <span data-type="" itemprop="" class="os-text">#{title.text}</span>
11
+ HTML
12
+ )
13
+ title.name = 'h1'
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,13 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kitchen
2
4
  module Directions
3
5
  module BakeStepwise
4
-
5
6
  def self.v1(book:)
6
- book.search("ol.stepwise").each do |ol|
7
- ol.remove_class("stepwise")
8
- ol.add_class("os-stepwise")
7
+ book.search('ol.stepwise').each do |ol|
8
+ ol.remove_class('stepwise')
9
+ ol.add_class('os-stepwise')
9
10
 
10
- ol.search("li").each_with_index do |li, ii|
11
+ ol.search('li').each_with_index do |li, ii|
11
12
  li.replace_children(with:
12
13
  <<~HTML
13
14
  <span class="os-stepwise-content">#{li.children}</span>
@@ -15,13 +16,12 @@ module Kitchen
15
16
  )
16
17
  li.prepend(child:
17
18
  <<~HTML
18
- <span class="os-stepwise-token">#{I18n.t(:stepwise_step_label)} #{ii+1}. </span>
19
+ <span class="os-stepwise-token">#{I18n.t(:stepwise_step_label)} #{ii + 1}. </span>
19
20
  HTML
20
21
  )
21
22
  end
22
23
  end
23
24
  end
24
-
25
25
  end
26
26
  end
27
27
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ module Directions
5
+ # Bake directions for EOC suggested reading
6
+ #
7
+ module BakeSuggestedReading
8
+ def self.v1(book:)
9
+ book.chapters.each do |chapter|
10
+ suggested_reading = chapter.search('section.suggested-reading').cut
11
+
12
+ chapter.append(child:
13
+ <<~HTML
14
+ <div class="os-eoc os-suggested-reading-container" data-type="composite-page" data-uuid-key=".suggested-reading">
15
+ <h2 data-type="document-title">
16
+ <span class="os-text">#{I18n.t(:eoc_suggested_reading)}</span>
17
+ </h2>
18
+ #{suggested_reading.paste}
19
+ </div>
20
+ HTML
21
+ )
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,10 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kitchen
2
4
  module Directions
3
5
  module BakeToc
4
-
5
6
  def self.v1(book:)
6
7
  li_tags = book.body.element_children.map do |element|
7
8
  case element
9
+ when UnitElement
10
+ li_for_unit(element)
8
11
  when ChapterElement
9
12
  li_for_chapter(element)
10
13
  when PageElement, CompositePageElement
@@ -14,25 +17,41 @@ module Kitchen
14
17
  end
15
18
  end.compact.join("\n")
16
19
 
17
- book.first!("nav").replace_children(with: <<~HTML
18
- <h1 class="os-toc-title">Contents</h1>
19
- <ol>
20
- #{li_tags}
21
- </ol>
22
- HTML
20
+ book.first!('nav').replace_children(with: <<~HTML
21
+ <h1 class="os-toc-title">#{I18n.t(:toc_title)}</h1>
22
+ <ol>
23
+ #{li_tags}
24
+ </ol>
25
+ HTML
23
26
  )
24
27
  end
25
28
 
29
+ def self.li_for_unit(unit)
30
+ chapters = unit.element_children.only(ChapterElement)
31
+ <<~HTML
32
+ <li cnx-archive-uri="" cnx-archive-shortid="" class="os-toc-unit">
33
+ <a href="#">
34
+ <span class="os-number"><span class="os-part-text">#{I18n.t(:unit)} </span> #{unit.count_in(:book)}</span>
35
+ <span class="os-divider"> </span>
36
+ <span data-type itemprop class="os-text"> #{unit.title.children} </span>
37
+ </a>
38
+ <ol class="os-unit">
39
+ #{chapters.map { |chapter| li_for_chapter(chapter) }.join("\n")}
40
+ </ol>
41
+ </li>
42
+ HTML
43
+ end
44
+
26
45
  def self.li_for_composite_chapter(chapter)
27
46
  pages = chapter.element_children.only(CompositePageElement)
28
47
 
29
48
  <<~HTML
30
49
  <li class="os-toc-composite-chapter" cnx-archive-shortid="" cnx-archive-uri="">
31
50
  <a href="##{chapter.title.id}">
32
- #{chapter.title.children.to_s}
51
+ #{chapter.title.children}
33
52
  </a>
34
53
  <ol class="os-chapter">
35
- #{pages.map{|page| li_for_page(page)}.join("\n")}
54
+ #{pages.map { |page| li_for_page(page) }.join("\n")}
36
55
  </ol>
37
56
  </li>
38
57
  HTML
@@ -44,12 +63,12 @@ module Kitchen
44
63
  <<~HTML
45
64
  <li class="os-toc-chapter" cnx-archive-shortid="" cnx-archive-uri="">
46
65
  <a href="##{chapter.title.id}">
47
- <span class="os-number"><span class="os-part-text">Chapter </span>#{chapter.count_in(:book)}</span>
66
+ <span class="os-number"><span class="os-part-text">#{I18n.t(:chapter)} </span>#{chapter.count_in(:book)}</span>
48
67
  <span class="os-divider"> </span>
49
- <span class="os-text" data-type="" itemprop="">#{chapter.title.first!(".os-text").text}</span>
68
+ <span class="os-text" data-type="" itemprop="">#{chapter.title.first!('.os-text').text}</span>
50
69
  </a>
51
70
  <ol class="os-chapter">
52
- #{pages.map{|page| li_for_page(page)}.join("\n")}
71
+ #{pages.map { |page| li_for_page(page) }.join("\n")}
53
72
  </ol>
54
73
  </li>
55
74
  HTML
@@ -57,21 +76,22 @@ module Kitchen
57
76
 
58
77
  def self.li_for_page(page)
59
78
  li_class =
60
- if page.is_a?(PageElement)
79
+ case page
80
+ when PageElement
61
81
  if page.has_ancestor?(:chapter)
62
- "os-toc-chapter-page"
82
+ 'os-toc-chapter-page'
63
83
  elsif page.is_appendix?
64
- "os-toc-appendix"
84
+ 'os-toc-appendix'
65
85
  elsif page.is_preface?
66
- "os-toc-preface"
86
+ 'os-toc-preface'
67
87
  else
68
88
  raise "do not know what TOC class to use for page with classes #{page.classes}"
69
89
  end
70
- elsif page.is_a?(CompositePageElement)
90
+ when CompositePageElement
71
91
  if page.is_index?
72
- "os-toc-index"
92
+ 'os-toc-index'
73
93
  elsif page.has_ancestor?(:composite_chapter) || page.has_ancestor?(:chapter)
74
- "os-toc-chapter-composite-page"
94
+ 'os-toc-chapter-composite-page'
75
95
  else
76
96
  raise "do not know what TOC class to use for page with classes #{page.classes}"
77
97
  end
@@ -82,8 +102,8 @@ module Kitchen
82
102
  title = page.title.copy
83
103
 
84
104
  # The part text gets inserted as a child to the number span
85
- part_text = title.first(".os-part-text")
86
- number = title.first(".os-number")
105
+ part_text = title.first('.os-part-text')
106
+ number = title.first('.os-number')
87
107
  if part_text && number
88
108
  part_text = part_text.cut
89
109
  number.prepend(child: part_text.paste)
@@ -97,7 +117,6 @@ module Kitchen
97
117
  </li>
98
118
  HTML
99
119
  end
100
-
101
120
  end
102
121
  end
103
122
  end