openstax_kitchen 1.0.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.devcontainer/devcontainer.json +37 -17
- data/.github/config.yml +14 -0
- data/.github/workflows/tests.yml +5 -15
- data/.gitignore +2 -2
- data/.inch.yml +6 -0
- data/.rubocop.yml +65 -0
- data/CHANGELOG.md +85 -2
- data/Gemfile +5 -3
- data/Gemfile.lock +66 -18
- data/README.md +69 -15
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/docker/Dockerfile +36 -0
- data/docker/Dockerfile.ci +10 -0
- data/docker/bash +5 -1
- data/docker/build +10 -0
- data/docker/ci +15 -0
- data/docker/run +9 -0
- data/docker/tag_and_push_latest +17 -0
- data/lefthook.yml +6 -0
- data/lib/kitchen/ancestor.rb +38 -1
- data/lib/kitchen/book_document.rb +20 -2
- data/lib/kitchen/book_element.rb +40 -5
- data/lib/kitchen/book_element_enumerator.rb +4 -0
- data/lib/kitchen/book_recipe.rb +15 -1
- data/lib/kitchen/chapter_element.rb +43 -6
- data/lib/kitchen/chapter_element_enumerator.rb +9 -1
- data/lib/kitchen/clipboard.rb +35 -4
- data/lib/kitchen/composite_chapter_element.rb +21 -6
- data/lib/kitchen/composite_page_element.rb +35 -7
- data/lib/kitchen/composite_page_element_enumerator.rb +9 -1
- data/lib/kitchen/config.rb +20 -6
- data/lib/kitchen/counter.rb +9 -2
- data/lib/kitchen/debug/print_recipe_error.rb +53 -35
- data/lib/kitchen/directions/.rubocop.yml +22 -0
- data/lib/kitchen/directions/bake_appendix.rb +4 -4
- data/lib/kitchen/directions/bake_chapter_glossary/main.rb +18 -0
- data/lib/kitchen/directions/bake_chapter_glossary/v1.rb +30 -0
- data/lib/kitchen/directions/bake_chapter_introductions.rb +7 -7
- data/lib/kitchen/directions/bake_chapter_key_concepts/main.rb +16 -0
- data/lib/kitchen/directions/bake_chapter_key_concepts/v1.rb +35 -0
- data/lib/kitchen/directions/bake_chapter_key_equations.rb +30 -20
- data/lib/kitchen/directions/bake_chapter_section_exercises/main.rb +11 -0
- data/lib/kitchen/directions/bake_chapter_section_exercises/v1.rb +28 -0
- data/lib/kitchen/directions/bake_chapter_summary.rb +45 -36
- data/lib/kitchen/directions/bake_chapter_title/main.rb +11 -0
- data/lib/kitchen/directions/bake_chapter_title/v1.rb +24 -0
- data/lib/kitchen/directions/bake_checkpoint.rb +44 -0
- data/lib/kitchen/directions/bake_composite_chapters.rb +14 -0
- data/lib/kitchen/directions/bake_composite_pages.rb +2 -2
- data/lib/kitchen/directions/bake_equations.rb +37 -0
- data/lib/kitchen/directions/bake_example.rb +39 -11
- data/lib/kitchen/directions/bake_figure.rb +8 -5
- data/lib/kitchen/directions/bake_first_elements.rb +16 -0
- data/lib/kitchen/directions/bake_footnotes/main.rb +2 -2
- data/lib/kitchen/directions/bake_footnotes/v1.rb +6 -5
- data/lib/kitchen/directions/bake_free_response/free_response.xhtml.erb +10 -0
- data/lib/kitchen/directions/bake_free_response/main.rb +11 -0
- data/lib/kitchen/directions/bake_free_response/v1.rb +29 -0
- data/lib/kitchen/directions/bake_further_research.rb +59 -0
- data/lib/kitchen/directions/bake_index/main.rb +2 -2
- data/lib/kitchen/directions/bake_index/v1.rb +46 -18
- data/lib/kitchen/directions/bake_link_placeholders.rb +24 -0
- data/lib/kitchen/directions/bake_math_in_paragraph.rb +5 -3
- data/lib/kitchen/directions/bake_non_introduction_pages.rb +26 -0
- data/lib/kitchen/directions/bake_notes/bake_autotitled_notes.rb +29 -0
- data/lib/kitchen/directions/bake_notes/bake_note_subtitle.rb +22 -0
- data/lib/kitchen/directions/bake_notes/bake_numbered_notes.rb +51 -0
- data/lib/kitchen/directions/bake_notes/bake_unclassified_notes.rb +30 -0
- data/lib/kitchen/directions/bake_numbered_exercise/main.rb +15 -0
- data/lib/kitchen/directions/bake_numbered_exercise/v1.rb +47 -0
- data/lib/kitchen/directions/bake_numbered_table/main.rb +4 -4
- data/lib/kitchen/directions/bake_numbered_table/v1.rb +37 -18
- data/lib/kitchen/directions/bake_page_abstracts.rb +30 -0
- data/lib/kitchen/directions/bake_preface/main.rb +11 -0
- data/lib/kitchen/directions/bake_preface/v1.rb +18 -0
- data/lib/kitchen/directions/bake_references/main.rb +16 -0
- data/lib/kitchen/directions/bake_references/v1.rb +48 -0
- data/lib/kitchen/directions/bake_stepwise.rb +8 -12
- data/lib/kitchen/directions/bake_suggested_reading.rb +31 -0
- data/lib/kitchen/directions/bake_theorem/main.rb +11 -0
- data/lib/kitchen/directions/bake_theorem/v1.rb +28 -0
- data/lib/kitchen/directions/bake_toc.rb +49 -22
- data/lib/kitchen/directions/bake_unit_title/main.rb +11 -0
- data/lib/kitchen/directions/bake_unit_title/v1.rb +23 -0
- data/lib/kitchen/directions/bake_unnumbered_tables.rb +7 -5
- data/lib/kitchen/directions/book_answer_key_container/eob_solutions_container.xhtml.erb +9 -0
- data/lib/kitchen/directions/book_answer_key_container/main.rb +11 -0
- data/lib/kitchen/directions/book_answer_key_container/v1.rb +13 -0
- data/lib/kitchen/directions/chapter_review_container/chapter_review.xhtml.erb +9 -0
- data/lib/kitchen/directions/chapter_review_container/main.rb +11 -0
- data/lib/kitchen/directions/chapter_review_container/v1.rb +13 -0
- data/lib/kitchen/directions/eoc_section_title_link_snippet.rb +20 -0
- data/lib/kitchen/directions/move_exercises_to_eoc/main.rb +27 -0
- data/lib/kitchen/directions/move_exercises_to_eoc/v1.rb +36 -0
- data/lib/kitchen/directions/move_exercises_to_eoc/v2.rb +49 -0
- data/lib/kitchen/directions/move_solutions_to_answer_key/main.rb +14 -0
- data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/american_government.rb +19 -0
- data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/calculus.rb +41 -0
- data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/uphysics.rb +63 -0
- data/lib/kitchen/directions/move_solutions_to_answer_key/v1.rb +34 -0
- data/lib/kitchen/directions/move_title_text_into_span.rb +2 -2
- data/lib/kitchen/document.rb +83 -13
- data/lib/kitchen/element.rb +20 -3
- data/lib/kitchen/element_base.rb +373 -63
- data/lib/kitchen/element_enumerator.rb +8 -0
- data/lib/kitchen/element_enumerator_base.rb +297 -28
- data/lib/kitchen/element_enumerator_factory.rb +64 -53
- data/lib/kitchen/element_factory.rb +27 -12
- data/lib/kitchen/errors.rb +5 -0
- data/lib/kitchen/example_element.rb +21 -6
- data/lib/kitchen/example_element_enumerator.rb +9 -1
- data/lib/kitchen/exercise_element.rb +42 -0
- data/lib/kitchen/exercise_element_enumerator.rb +21 -0
- data/lib/kitchen/figure_element.rb +36 -5
- data/lib/kitchen/figure_element_enumerator.rb +9 -1
- data/lib/kitchen/metadata_element.rb +34 -0
- data/lib/kitchen/metadata_element_enumerator.rb +21 -0
- data/lib/kitchen/mixins/block_error_if.rb +24 -4
- data/lib/kitchen/note_element.rb +48 -20
- data/lib/kitchen/note_element_enumerator.rb +9 -1
- data/lib/kitchen/oven.rb +66 -15
- data/lib/kitchen/page_element.rb +84 -14
- data/lib/kitchen/page_element_enumerator.rb +9 -1
- data/lib/kitchen/pantry.rb +28 -1
- data/lib/kitchen/patches/nokogiri.rb +19 -2
- data/lib/kitchen/patches/renderable.rb +9 -3
- data/lib/kitchen/patches/string.rb +8 -0
- data/lib/kitchen/recipe.rb +69 -32
- data/lib/kitchen/reference_element.rb +27 -0
- data/lib/kitchen/references_element_enumerator.rb +20 -0
- data/lib/kitchen/search_history.rb +43 -4
- data/lib/kitchen/search_query.rb +106 -0
- data/lib/kitchen/selector.rb +24 -0
- data/lib/kitchen/selectors/base.rb +65 -0
- data/lib/kitchen/selectors/standard_1.rb +21 -0
- data/lib/kitchen/table_element.rb +55 -7
- data/lib/kitchen/table_element_enumerator.rb +9 -1
- data/lib/kitchen/templates/eob_section_title_template.xhtml.erb +10 -0
- data/lib/kitchen/templates/eoc_section_title_template.xhtml.erb +10 -0
- data/lib/kitchen/term_element.rb +15 -4
- data/lib/kitchen/term_element_enumerator.rb +9 -1
- data/lib/kitchen/transliterations.rb +7 -5
- data/lib/kitchen/type_casting_element_enumerator.rb +17 -1
- data/lib/kitchen/unit_element.rb +45 -0
- data/lib/kitchen/unit_element_enumerator.rb +20 -0
- data/lib/kitchen/utils.rb +10 -13
- data/lib/kitchen/version.rb +5 -1
- data/lib/locales/en.yml +18 -7
- data/lib/locales/pl.yml +24 -0
- data/lib/openstax_kitchen.rb +59 -0
- data/openstax_kitchen.gemspec +26 -20
- data/tutorials/00/solution1.rb +9 -0
- data/tutorials/00/solution2.rb +8 -0
- data/tutorials/01/solution1.rb +18 -0
- data/tutorials/01/solution2.rb +26 -0
- data/tutorials/02/solution1.rb +31 -0
- data/tutorials/03/{solution_1.rb → solution1.rb} +6 -4
- data/tutorials/03/solution2.rb +18 -0
- data/tutorials/04/{solution_1.rb → solution1.rb} +4 -2
- data/tutorials/04/{solution_2.rb → solution2.rb} +6 -4
- data/tutorials/05/solution1.rb +11 -0
- data/tutorials/check_it +16 -15
- data/tutorials/setup_my_recipes +7 -6
- metadata +148 -27
- data/Dockerfile +0 -19
- data/bin/normalize +0 -79
- data/books/chemistry2e/bake.rb +0 -133
- data/docker-compose.yml +0 -12
- data/docker/entrypoint +0 -9
- data/lib/kitchen.rb +0 -57
- data/lib/kitchen/directions/bake_chapter_glossary.rb +0 -34
- data/lib/kitchen/directions/bake_exercises.rb +0 -164
- data/lib/kitchen/directions/bake_notes.rb +0 -58
- data/tutorials/00/solution_1.rb +0 -7
- data/tutorials/00/solution_2.rb +0 -6
- data/tutorials/01/solution_1.rb +0 -16
- data/tutorials/01/solution_2.rb +0 -24
- data/tutorials/02/solution_1.rb +0 -29
- data/tutorials/03/solution_2.rb +0 -15
- data/tutorials/05/solution_1.rb +0 -9
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kitchen
|
4
|
+
module Directions
|
5
|
+
module BakeCheckpoint
|
6
|
+
def self.v1(checkpoint:, number:)
|
7
|
+
checkpoint.wrap_children(class: 'os-note-body')
|
8
|
+
|
9
|
+
checkpoint.prepend(child:
|
10
|
+
<<~HTML
|
11
|
+
<div class="os-title">
|
12
|
+
<span class="os-title-label">#{I18n.t(:checkpoint)} </span>
|
13
|
+
<span class="os-number">#{number}</span>
|
14
|
+
<span class="os-divider"> </span>
|
15
|
+
</div>
|
16
|
+
HTML
|
17
|
+
)
|
18
|
+
|
19
|
+
exercise = checkpoint.exercises.first!
|
20
|
+
exercise.search("[data-type='commentary']").trash
|
21
|
+
|
22
|
+
problem = exercise.problem
|
23
|
+
problem.wrap_children(class: 'os-problem-container')
|
24
|
+
|
25
|
+
solution = exercise.solution
|
26
|
+
exercise.add_class('unnumbered') unless solution.present?
|
27
|
+
return unless solution.present?
|
28
|
+
|
29
|
+
solution.id = "#{exercise.id}-solution"
|
30
|
+
exercise.add_class('os-hasSolution')
|
31
|
+
|
32
|
+
solution.replace_children(with:
|
33
|
+
<<~HTML
|
34
|
+
<span class="os-divider"> </span>
|
35
|
+
<a class="os-number" href="##{exercise.id}">#{number}</a>
|
36
|
+
<div class="os-solution-container">#{solution.children}</div>
|
37
|
+
HTML
|
38
|
+
)
|
39
|
+
|
40
|
+
exercise.add_class('unnumbered')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kitchen
|
4
|
+
module Directions
|
5
|
+
module BakeCompositeChapters
|
6
|
+
def self.v1(book:)
|
7
|
+
book.search("[data-type='composite-chapter']").each do |chapter|
|
8
|
+
chapter.first("[data-type='document-title']").id =
|
9
|
+
"composite-chapter-#{chapter.count_in(:book)}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Kitchen
|
2
4
|
module Directions
|
3
5
|
module BakeCompositePages
|
4
|
-
|
5
6
|
def self.v1(book:)
|
6
7
|
book.search("[data-type='composite-page']").each do |page|
|
7
8
|
page.id = "composite-page-#{page.count_in(:book)}"
|
8
9
|
end
|
9
10
|
end
|
10
|
-
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kitchen
|
4
|
+
module Directions
|
5
|
+
module BakeEquations
|
6
|
+
def self.v1(book:, number_decorator: :none)
|
7
|
+
book.chapters.search('[data-type="equation"]:not(.unnumbered)').each do |eq|
|
8
|
+
chapter = eq.ancestor(:chapter)
|
9
|
+
number = "#{chapter.count_in(:book)}.#{eq.count_in(:chapter)}"
|
10
|
+
|
11
|
+
# Store label information
|
12
|
+
equation_label = "#{I18n.t(:equation)} #{number}"
|
13
|
+
book.pantry(name: :link_text).store equation_label, label: eq.id
|
14
|
+
|
15
|
+
decorated_number =
|
16
|
+
case number_decorator
|
17
|
+
when :none
|
18
|
+
number
|
19
|
+
when :parentheses
|
20
|
+
"(#{number})"
|
21
|
+
else
|
22
|
+
raise "Unsupported number_decorator '#{number_decorator}'"
|
23
|
+
end
|
24
|
+
|
25
|
+
# Bake the equation
|
26
|
+
eq.append(child:
|
27
|
+
<<~HTML
|
28
|
+
<div class="os-equation-number">
|
29
|
+
<span class="os-number">#{decorated_number}</span>
|
30
|
+
</div>
|
31
|
+
HTML
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,15 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Kitchen
|
2
4
|
module Directions
|
3
5
|
module BakeExample
|
4
|
-
|
5
6
|
def self.v1(example:, number:, title_tag:)
|
6
|
-
example.
|
7
|
-
<<~HTML
|
8
|
-
<div class="body">
|
9
|
-
#{example.children}
|
10
|
-
</div>
|
11
|
-
HTML
|
12
|
-
)
|
7
|
+
example.wrap_children(class: 'body')
|
13
8
|
|
14
9
|
example.prepend(child:
|
15
10
|
<<~HTML
|
@@ -21,11 +16,44 @@ module Kitchen
|
|
21
16
|
HTML
|
22
17
|
)
|
23
18
|
|
24
|
-
example.document
|
19
|
+
example.document
|
20
|
+
.pantry(name: :link_text)
|
21
|
+
.store("#{I18n.t(:example_label)} #{number}", label: example.id)
|
25
22
|
|
26
|
-
example.titles.each
|
27
|
-
|
23
|
+
example.titles.each do |title|
|
24
|
+
next if title.parent.has_class?('os-caption-container')
|
28
25
|
|
26
|
+
title.name = 'h4'
|
27
|
+
end
|
28
|
+
|
29
|
+
example.exercises.each do |exercise|
|
30
|
+
if (problem = exercise.problem)
|
31
|
+
problem.titles.each { |title| title.name = 'h4' }
|
32
|
+
problem.wrap_children(class: 'os-problem-container')
|
33
|
+
end
|
34
|
+
|
35
|
+
if (solution = exercise.solution)
|
36
|
+
solution.replace_children(with:
|
37
|
+
<<~HTML
|
38
|
+
<h4 data-type="solution-title">
|
39
|
+
<span class="os-title-label">#{I18n.t(:solution)} </span>
|
40
|
+
</h4>
|
41
|
+
<div class="os-solution-container">#{solution.children}</div>
|
42
|
+
HTML
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
exercise.add_class('unnumbered')
|
47
|
+
|
48
|
+
commentary = exercise.first('[data-type="commentary"]')
|
49
|
+
next unless commentary.present?
|
50
|
+
|
51
|
+
commentary_title = commentary.titles.first
|
52
|
+
commentary_title.name = 'h4'
|
53
|
+
commentary_title['data-type'] = 'commentary-title'
|
54
|
+
commentary_title.wrap_children('span', class: 'os-title-label')
|
55
|
+
end
|
56
|
+
end
|
29
57
|
end
|
30
58
|
end
|
31
59
|
end
|
@@ -1,21 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Kitchen
|
2
4
|
module Directions
|
3
5
|
module BakeFigure
|
4
|
-
|
5
6
|
def self.v1(figure:, number:)
|
6
|
-
figure.wrap(%
|
7
|
+
figure.wrap(%(<div class="os-figure#{' has-splash' if figure.has_class?('splash')}">))
|
7
8
|
|
8
|
-
figure.
|
9
|
+
figure.pantry(name: :link_text).store "#{I18n.t(:figure)} #{number}", label: figure.id
|
10
|
+
title = figure.title&.cut
|
9
11
|
|
10
12
|
caption = figure.caption&.cut
|
11
13
|
figure.append(sibling:
|
12
14
|
<<~HTML
|
13
15
|
<div class="os-caption-container">
|
14
|
-
<span class="os-title-label"
|
16
|
+
<span class="os-title-label">#{I18n.t(:figure)} </span>
|
15
17
|
<span class="os-number">#{number}</span>
|
16
18
|
<span class="os-divider"> </span>
|
19
|
+
#{"<span class=\"os-title\" data-type=\"title\" id=\"#{title.id}\">#{title.children}</span>" if title}
|
17
20
|
<span class="os-divider"> </span>
|
18
|
-
#{
|
21
|
+
#{"<span class=\"os-caption\">#{caption.children}</span>" if caption}
|
19
22
|
</div>
|
20
23
|
HTML
|
21
24
|
)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kitchen
|
4
|
+
module Directions
|
5
|
+
module BakeFirstElements
|
6
|
+
def self.v1(within:, selectors:)
|
7
|
+
selectors.each do |selector|
|
8
|
+
within.search("#{selector}:first-child").each do |problem|
|
9
|
+
problem.add_class('first-element')
|
10
|
+
problem.parent.add_class('has-first-element')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Kitchen::Directions::BakeFootnotes
|
2
4
|
class V1
|
3
5
|
|
@@ -6,7 +8,8 @@ module Kitchen::Directions::BakeFootnotes
|
|
6
8
|
# appendices, etc) or within chapters. Tackle each case separately
|
7
9
|
|
8
10
|
book.body.element_children.only(Kitchen::PageElement,
|
9
|
-
Kitchen::CompositePageElement
|
11
|
+
Kitchen::CompositePageElement,
|
12
|
+
Kitchen::CompositeChapterElement).each do |page|
|
10
13
|
bake_footnotes_within(page)
|
11
14
|
end
|
12
15
|
|
@@ -26,12 +29,10 @@ module Kitchen::Directions::BakeFootnotes
|
|
26
29
|
aside_id_to_footnote_number[aside_id] = footnote_number
|
27
30
|
end
|
28
31
|
|
29
|
-
|
30
|
-
container.search("aside").each do |aside|
|
32
|
+
container.search('aside').each do |aside|
|
31
33
|
footnote_number = aside_id_to_footnote_number[aside.id]
|
32
|
-
aside.prepend(child: "<div
|
34
|
+
aside.prepend(child: "<div data-type='footnote-number'>#{footnote_number}</div>")
|
33
35
|
end
|
34
|
-
|
35
36
|
end
|
36
37
|
|
37
38
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<div class="os-eoc os-free-response-container" data-type="composite-page" data-uuid-key=".free-response">
|
2
|
+
<<%= @title_tag %> data-type="document-title">
|
3
|
+
<span class="os-text"><%= I18n.t(:eoc_free_response) %></span>
|
4
|
+
</<%= @title_tag %>>
|
5
|
+
<div data-type="metadata" style="display: none;">
|
6
|
+
<h1 data-type="document-title" itemprop="name"><%= I18n.t(:eoc_free_response) %></h1>
|
7
|
+
<%= @metadata_elements.paste %>
|
8
|
+
</div>
|
9
|
+
<%= @free_response_clipboard.paste %>
|
10
|
+
</div>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kitchen
|
4
|
+
module Directions
|
5
|
+
module BakeFreeResponse
|
6
|
+
def self.v1(chapter:, metadata_source:, append_to: nil)
|
7
|
+
V1.new.bake(chapter: chapter, metadata_source: metadata_source, append_to: append_to)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kitchen::Directions::BakeFreeResponse
|
4
|
+
class V1
|
5
|
+
renderable
|
6
|
+
|
7
|
+
def bake(chapter:, metadata_source:, append_to:)
|
8
|
+
@metadata_elements = metadata_source.children_to_keep.copy
|
9
|
+
|
10
|
+
@free_response_clipboard = Kitchen::Clipboard.new
|
11
|
+
chapter.non_introduction_pages.each do |page|
|
12
|
+
free_response_questions = page.free_response
|
13
|
+
next if free_response_questions.none?
|
14
|
+
|
15
|
+
free_response_questions.search('h3').trash
|
16
|
+
title = Kitchen::Directions::EocSectionTitleLinkSnippet.v1(page: page)
|
17
|
+
free_response_questions.each do |free_response_question|
|
18
|
+
free_response_question.prepend(child: title)
|
19
|
+
free_response_question.cut(to: @free_response_clipboard)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
append_to_element = append_to || chapter
|
24
|
+
@title_tag = append_to ? 'h3' : 'h2'
|
25
|
+
|
26
|
+
append_to_element.append(child: render(file: 'free_response.xhtml.erb'))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kitchen
|
4
|
+
module Directions
|
5
|
+
# Bake directions for further research
|
6
|
+
#
|
7
|
+
module BakeFurtherResearch
|
8
|
+
def self.v1(chapter:, metadata_source:, uuid_prefix: '.')
|
9
|
+
V1.new.bake(
|
10
|
+
chapter: chapter,
|
11
|
+
metadata_source: metadata_source,
|
12
|
+
uuid_prefix: uuid_prefix)
|
13
|
+
end
|
14
|
+
|
15
|
+
class V1
|
16
|
+
renderable
|
17
|
+
def bake(chapter:, metadata_source:, uuid_prefix: '.')
|
18
|
+
@metadata = metadata_source.children_to_keep.copy
|
19
|
+
@klass = 'further-research'
|
20
|
+
@title = I18n.t(:eoc_further_research_title)
|
21
|
+
@uuid_prefix = uuid_prefix
|
22
|
+
|
23
|
+
further_researches = Clipboard.new
|
24
|
+
|
25
|
+
chapter.non_introduction_pages.each do |page|
|
26
|
+
further_research = page.first('.further-research')
|
27
|
+
further_research.first("[data-type='title']")&.trash # get rid of old title if exists
|
28
|
+
further_research_title = page.title.copy
|
29
|
+
further_research_title.name = 'h3'
|
30
|
+
further_research_title.replace_children(with: <<~HTML
|
31
|
+
<span class="os-number">#{chapter.count_in(:book)}.#{page.count_in(:chapter)}</span>
|
32
|
+
<span class="os-divider"> </span>
|
33
|
+
<span class="os-text" data-type="" itemprop="">#{further_research_title.children}</span>
|
34
|
+
HTML
|
35
|
+
)
|
36
|
+
|
37
|
+
further_research.prepend(child:
|
38
|
+
<<~HTML
|
39
|
+
<a href="##{page.title.id}">
|
40
|
+
#{further_research_title.paste}
|
41
|
+
</a>
|
42
|
+
HTML
|
43
|
+
)
|
44
|
+
further_research.cut(to: further_researches)
|
45
|
+
end
|
46
|
+
|
47
|
+
return if further_researches.none?
|
48
|
+
|
49
|
+
@content = further_researches.paste
|
50
|
+
|
51
|
+
@in_composite_chapter = false
|
52
|
+
|
53
|
+
chapter.append(child: render(file:
|
54
|
+
'../templates/eoc_section_title_template.xhtml.erb'))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
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
|
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
|
@@ -37,8 +44,12 @@ module Kitchen::Directions::BakeIndex
|
|
37
44
|
@term_text = @term_text.uncapitalize
|
38
45
|
end
|
39
46
|
|
47
|
+
def capitalize_term_text!
|
48
|
+
@term_text = @term_text.capitalize
|
49
|
+
end
|
50
|
+
|
40
51
|
def <=>(other)
|
41
|
-
|
52
|
+
sortable <=> other.sortable
|
42
53
|
end
|
43
54
|
|
44
55
|
protected
|
@@ -64,7 +75,8 @@ module Kitchen::Directions::BakeIndex
|
|
64
75
|
def <=>(other)
|
65
76
|
return -1 if force_first
|
66
77
|
return 1 if other.force_first
|
67
|
-
|
78
|
+
|
79
|
+
name <=> other.name
|
68
80
|
end
|
69
81
|
|
70
82
|
protected
|
@@ -76,6 +88,11 @@ module Kitchen::Directions::BakeIndex
|
|
76
88
|
different_caps_item = @items_by_term_text[term.text.uncapitalize]
|
77
89
|
different_caps_item&.uncapitalize_term_text!
|
78
90
|
|
91
|
+
unless different_caps_item
|
92
|
+
different_caps_item = @items_by_term_text[term.text.capitalize]
|
93
|
+
different_caps_item&.capitalize_term_text!
|
94
|
+
end
|
95
|
+
|
79
96
|
(different_caps_item || IndexItem.new(term_text: term.text)).tap do |item|
|
80
97
|
@items.add(item)
|
81
98
|
end
|
@@ -107,31 +124,42 @@ module Kitchen::Directions::BakeIndex
|
|
107
124
|
end
|
108
125
|
|
109
126
|
def bake(book:)
|
110
|
-
@metadata_elements = book.metadata.
|
111
|
-
.permissions [data-type='subject'])).copy
|
127
|
+
@metadata_elements = book.metadata.children_to_keep.copy
|
112
128
|
@index = Index.new
|
113
129
|
|
114
130
|
book.pages.terms.each do |term_element|
|
115
|
-
# Markup the term
|
116
131
|
page = term_element.ancestor(:page)
|
117
132
|
term_element.id = "auto_#{page.id}_term#{term_element.count_in(:book)}"
|
133
|
+
page_title = page.title.text
|
134
|
+
add_term_to_index(term_element, page_title)
|
135
|
+
end
|
118
136
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
137
|
+
book.chapters.composite_pages.terms.each do |term_element|
|
138
|
+
page = term_element.ancestor(:composite_page)
|
139
|
+
chapter = term_element.ancestor(:chapter)
|
140
|
+
term_element.id = "auto_composite_page_term#{term_element.count_in(:book)}"
|
141
|
+
chapter_number = chapter.count_in(:book)
|
142
|
+
page_title = "#{chapter_number} #{page.title.text.strip}".strip
|
143
|
+
add_term_to_index(term_element, page_title)
|
144
|
+
end
|
145
|
+
|
146
|
+
book.first('body').append(child: render(file: 'v1.xhtml.erb'))
|
147
|
+
end
|
124
148
|
|
125
|
-
|
126
|
-
|
149
|
+
def add_term_to_index(term_element, page_title)
|
150
|
+
group_by = term_element.text.strip[0]
|
151
|
+
group_by = I18n.t(:eob_index_symbols_group) unless group_by.match?(/\w/)
|
152
|
+
term_element['group-by'] = group_by
|
153
|
+
|
154
|
+
# Add it to our index object
|
155
|
+
@index.add_term(
|
156
|
+
Term.new(
|
127
157
|
text: term_element.text,
|
128
158
|
id: term_element.id,
|
129
159
|
group_by: group_by,
|
130
|
-
page_title:
|
131
|
-
)
|
132
|
-
|
133
|
-
|
134
|
-
book.first("body").append(child: render(file: 'v1.xhtml.erb'))
|
160
|
+
page_title: page_title.gsub(/\n/, '')
|
161
|
+
)
|
162
|
+
)
|
135
163
|
end
|
136
164
|
|
137
165
|
end
|