openstax_kitchen 2.0.0 → 4.1.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 -1
- data/Gemfile +5 -3
- data/Gemfile.lock +65 -17
- data/README.md +65 -11
- 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_references/main.rb +16 -0
- data/lib/kitchen/directions/bake_chapter_references/v1.rb +35 -0
- 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 +59 -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 +44 -42
- 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 +149 -24
- data/Dockerfile +0 -19
- data/docker-compose.yml +0 -12
- data/docker/entrypoint +0 -9
- 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
@@ -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
|
@@ -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.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(
|
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
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kitchen
|
4
|
+
module Directions
|
5
|
+
module BakeNonIntroductionPages
|
6
|
+
def self.v1(chapter:)
|
7
|
+
chapter.non_introduction_pages.each do |page|
|
8
|
+
number = "#{chapter.count_in(:book)}.#{page.count_in(:chapter)}"
|
9
|
+
|
10
|
+
page.search("div[data-type='description']").each(&:trash)
|
11
|
+
page.add_class('chapter-content-module')
|
12
|
+
|
13
|
+
title = page.title
|
14
|
+
title.name = 'h2'
|
15
|
+
title.replace_children(with:
|
16
|
+
<<~HTML
|
17
|
+
<span class="os-number">#{number}</span>
|
18
|
+
<span class="os-divider"> </span>
|
19
|
+
<span data-type="" itemprop="" class="os-text">#{title.text}</span>
|
20
|
+
HTML
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kitchen
|
4
|
+
module Directions
|
5
|
+
module BakeAutotitledNotes
|
6
|
+
def self.v1(book:, classes:)
|
7
|
+
book.notes.each do |note|
|
8
|
+
next unless (note.classes & classes).any?
|
9
|
+
|
10
|
+
bake_note(note: note)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.bake_note(note:)
|
15
|
+
note.wrap_children(class: 'os-note-body')
|
16
|
+
|
17
|
+
BakeNoteSubtitle.v1(note: note)
|
18
|
+
|
19
|
+
note.prepend(child:
|
20
|
+
<<~HTML
|
21
|
+
<h3 class="os-title" data-type="title">
|
22
|
+
<span class="os-title-label">#{note.autogenerated_title}</span>
|
23
|
+
</h3>
|
24
|
+
HTML
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kitchen
|
4
|
+
module Directions
|
5
|
+
module BakeNoteSubtitle
|
6
|
+
def self.v1(note:)
|
7
|
+
title = note.title&.cut
|
8
|
+
|
9
|
+
return unless title
|
10
|
+
|
11
|
+
# Store label information
|
12
|
+
note_label = title.children
|
13
|
+
note.pantry(name: :link_text).store note_label, label: note.id
|
14
|
+
|
15
|
+
title.name = 'h4'
|
16
|
+
title.add_class('os-subtitle')
|
17
|
+
title.wrap_children('span', class: 'os-subtitle-label')
|
18
|
+
note.first!('.os-note-body').prepend(child: title.to_s)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kitchen
|
4
|
+
module Directions
|
5
|
+
module BakeNumberedNotes
|
6
|
+
def self.v1(book:, classes:)
|
7
|
+
classes.each do |klass|
|
8
|
+
book.chapters.notes("$.#{klass}").each do |note|
|
9
|
+
bake_note(note: note)
|
10
|
+
note.exercises.each do |exercise|
|
11
|
+
bake_note_exercise(note: note, exercise: exercise)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.bake_note(note:)
|
18
|
+
note.wrap_children(class: 'os-note-body')
|
19
|
+
|
20
|
+
chapter_count = note.ancestor(:chapter).count_in(:book)
|
21
|
+
note_count = note.count_in(:chapter)
|
22
|
+
note.prepend(child:
|
23
|
+
<<~HTML
|
24
|
+
<h3 class="os-title">
|
25
|
+
<span class="os-title-label">#{note.autogenerated_title}</span>
|
26
|
+
<span class="os-number">#{chapter_count}.#{note_count}</span>
|
27
|
+
<span class="os-divider"> </span>
|
28
|
+
</h3>
|
29
|
+
HTML
|
30
|
+
)
|
31
|
+
|
32
|
+
return unless note['use-subtitle']
|
33
|
+
|
34
|
+
BakeNoteSubtitle.v1(note: note)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.bake_note_exercise(note:, exercise:)
|
38
|
+
exercise.add_class('unnumbered')
|
39
|
+
# bake problem
|
40
|
+
exercise.problem.wrap_children('div', class: 'os-problem-container')
|
41
|
+
exercise.problem.first('strong')&.trash
|
42
|
+
exercise.search('[data-type="commentary"]').each(&:trash)
|
43
|
+
return unless exercise.solution
|
44
|
+
|
45
|
+
# bake solution in place
|
46
|
+
BakeNumberedExercise.bake_solution_v1(
|
47
|
+
exercise: exercise, number: note.first('.os-number').text, divider: ' ')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kitchen
|
4
|
+
module Directions
|
5
|
+
module BakeUnclassifiedNotes
|
6
|
+
def self.v1(book:)
|
7
|
+
book.notes.each do |note|
|
8
|
+
next unless note.classes.empty?
|
9
|
+
|
10
|
+
bake_note(note: note)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.bake_note(note:)
|
15
|
+
note.wrap_children(class: 'os-note-body')
|
16
|
+
|
17
|
+
title = note.title&.cut
|
18
|
+
return unless title
|
19
|
+
|
20
|
+
note.prepend(child:
|
21
|
+
<<~HTML
|
22
|
+
<h3 class="os-title" data-type="title">
|
23
|
+
<span class="os-title-label" data-type="" id="#{title[:id]}">#{title.children}</span>
|
24
|
+
</h3>
|
25
|
+
HTML
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kitchen
|
4
|
+
module Directions
|
5
|
+
module BakeNumberedExercise
|
6
|
+
def self.v1(exercise:, number:, suppress_solution: false)
|
7
|
+
V1.new.bake(exercise: exercise, number: number, suppress_solution: suppress_solution)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.bake_solution_v1(exercise:, number:, divider: '. ')
|
11
|
+
V1.new.bake_solution(exercise: exercise, number: number, divider: divider)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kitchen::Directions::BakeNumberedExercise
|
4
|
+
class V1
|
5
|
+
def bake(exercise:, number:, suppress_solution: false)
|
6
|
+
problem = exercise.problem
|
7
|
+
solution = exercise.solution
|
8
|
+
|
9
|
+
exercise.pantry(name: :link_text).store(
|
10
|
+
"#{I18n.t(:exercise_label)} #{exercise.ancestor(:chapter).count_in(:book)}.#{number}",
|
11
|
+
label: exercise.id
|
12
|
+
)
|
13
|
+
problem_number = "<span class='os-number'>#{number}</span>"
|
14
|
+
|
15
|
+
if solution.present?
|
16
|
+
if suppress_solution
|
17
|
+
solution.trash
|
18
|
+
else
|
19
|
+
problem_number = "<a class='os-number' href='##{exercise.id}-solution'>#{number}</a>"
|
20
|
+
bake_solution(exercise: exercise, number: number)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
problem.replace_children(with:
|
25
|
+
<<~HTML
|
26
|
+
#{problem_number}
|
27
|
+
<span class='os-divider'>. </span>
|
28
|
+
<div class="os-problem-container">#{problem.children}</div>
|
29
|
+
HTML
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
def bake_solution(exercise:, number:, divider: '. ')
|
34
|
+
solution = exercise.solution
|
35
|
+
solution.id = "#{exercise.id}-solution"
|
36
|
+
exercise.add_class('os-hasSolution')
|
37
|
+
|
38
|
+
solution.replace_children(with:
|
39
|
+
<<~HTML
|
40
|
+
<a class='os-number' href='##{exercise.id}'>#{number}</a>
|
41
|
+
<span class='os-divider'>#{divider}</span>
|
42
|
+
<div class="os-solution-container">#{solution.children}</div>
|
43
|
+
HTML
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
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
|
-
V1.new.bake(table: table, number: number)
|
6
|
+
def self.v1(table:, number:, always_caption: false)
|
7
|
+
V1.new.bake(table: table, number: number, always_caption: always_caption)
|
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
|
-
def bake(table:, number:)
|
5
|
-
table.wrap(%
|
6
|
+
def bake(table:, number:, always_caption: false)
|
7
|
+
table.wrap(%(<div class="os-table">))
|
6
8
|
|
7
9
|
table_label = "#{I18n.t(:table_label)} #{number}"
|
8
|
-
table.
|
10
|
+
table.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,31 +19,47 @@ module Kitchen::Directions::BakeNumberedTable
|
|
16
19
|
table.title_row.trash
|
17
20
|
end
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
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 = ''
|
27
|
+
caption_title = ''
|
28
|
+
|
29
|
+
if (title = table.first("span[data-type='title']")&.cut)
|
30
|
+
new_summary += title.text
|
31
|
+
caption_title = <<~HTML
|
32
|
+
\n<span class="os-title" data-type="title">#{title.children}</span>
|
33
|
+
HTML
|
34
|
+
end
|
35
|
+
|
36
|
+
new_summary += ' '
|
22
37
|
|
23
38
|
if (caption = table.caption&.cut)
|
24
39
|
new_summary += caption.text
|
25
40
|
new_caption = <<~HTML
|
26
41
|
\n<span class="os-caption">#{caption.children}</span>
|
27
42
|
HTML
|
43
|
+
elsif always_caption
|
44
|
+
new_caption = <<~HTML
|
45
|
+
\n<span class="os-caption"></span>
|
46
|
+
HTML
|
28
47
|
end
|
29
48
|
|
30
49
|
table[:summary] = new_summary
|
31
50
|
|
32
|
-
if
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
</
|
41
|
-
|
42
|
-
|
43
|
-
|
51
|
+
return if table.unnumbered?
|
52
|
+
|
53
|
+
table.append(sibling:
|
54
|
+
<<~HTML
|
55
|
+
<div class="os-caption-container">
|
56
|
+
<span class="os-title-label">#{I18n.t(:table_label)} </span>
|
57
|
+
<span class="os-number">#{number}</span>
|
58
|
+
<span class="os-divider"> </span>#{caption_title}
|
59
|
+
<span class="os-divider"> </span>#{new_caption}
|
60
|
+
</div>
|
61
|
+
HTML
|
62
|
+
)
|
44
63
|
end
|
45
64
|
|
46
65
|
end
|