openstax_kitchen 8.0.1 → 10.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +42 -0
  3. data/Gemfile.lock +1 -1
  4. data/lib/kitchen/chapter_element.rb +0 -8
  5. data/lib/kitchen/composite_page_element.rb +2 -4
  6. data/lib/kitchen/directions/.rubocop.yml +3 -0
  7. data/lib/kitchen/directions/bake_chapter_glossary/main.rb +3 -2
  8. data/lib/kitchen/directions/bake_chapter_glossary/v1.rb +18 -13
  9. data/lib/kitchen/directions/bake_chapter_key_concepts/v1.rb +13 -26
  10. data/lib/kitchen/directions/bake_chapter_key_equations.rb +10 -17
  11. data/lib/kitchen/directions/bake_chapter_references/v1.rb +10 -12
  12. data/lib/kitchen/directions/bake_chapter_solutions/main.rb +7 -2
  13. data/lib/kitchen/directions/bake_chapter_solutions/v1.rb +19 -21
  14. data/lib/kitchen/directions/bake_chapter_summary.rb +9 -32
  15. data/lib/kitchen/directions/bake_eoc_section_content/remove_section_title.rb +11 -0
  16. data/lib/kitchen/directions/bake_example.rb +4 -8
  17. data/lib/kitchen/directions/bake_first_elements.rb +9 -0
  18. data/lib/kitchen/directions/bake_further_research.rb +12 -39
  19. data/lib/kitchen/directions/bake_handbook/main.rb +11 -0
  20. data/lib/kitchen/directions/bake_handbook/v1.rb +74 -0
  21. data/lib/kitchen/directions/bake_inline_lists.rb +1 -1
  22. data/lib/kitchen/directions/bake_lists_with_para.rb +17 -0
  23. data/lib/kitchen/directions/bake_notes/bake_autotitled_notes.rb +1 -0
  24. data/lib/kitchen/directions/bake_notes/bake_note_iframes.rb +27 -0
  25. data/lib/kitchen/directions/bake_numbered_exercise/v1.rb +19 -0
  26. data/lib/kitchen/directions/bake_numbered_table/bake_table_body.rb +1 -1
  27. data/lib/kitchen/directions/bake_numbered_table/v1.rb +1 -1
  28. data/lib/kitchen/directions/bake_toc.rb +9 -0
  29. data/lib/kitchen/directions/bake_unit_page_title/main.rb +11 -0
  30. data/lib/kitchen/directions/bake_unit_page_title/v1.rb +21 -0
  31. data/lib/kitchen/directions/eoc_composite_page_container/main.rb +27 -0
  32. data/lib/kitchen/directions/eoc_composite_page_container/v1.rb +19 -0
  33. data/lib/kitchen/directions/move_custom_section_to_eoc_container/main.rb +40 -0
  34. data/lib/kitchen/directions/move_custom_section_to_eoc_container/v1.rb +43 -0
  35. data/lib/kitchen/directions/move_exercises_to_eoc/v1.rb +10 -27
  36. data/lib/kitchen/directions/move_exercises_to_eoc/v2.rb +13 -38
  37. data/lib/kitchen/directions/move_exercises_to_eoc/v3.rb +14 -38
  38. data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/contemporary_math.rb +40 -0
  39. data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/precalculus.rb +4 -4
  40. data/lib/kitchen/directions/move_solutions_to_answer_key/v1.rb +7 -1
  41. data/lib/kitchen/example_element.rb +9 -3
  42. data/lib/kitchen/exercise_element.rb +8 -0
  43. data/lib/kitchen/figure_element.rb +11 -0
  44. data/lib/kitchen/metadata_element.rb +2 -2
  45. data/lib/kitchen/note_element.rb +8 -1
  46. data/lib/kitchen/page_element.rb +7 -7
  47. data/lib/kitchen/templates/eoc_section_template.xhtml.erb +11 -0
  48. data/lib/kitchen/templates/eoc_section_template_old.xhtml.erb +11 -0
  49. data/lib/kitchen/version.rb +1 -1
  50. data/lib/locales/en.yml +10 -5
  51. data/lib/locales/es.yml +6 -4
  52. data/lib/locales/pl.yml +5 -3
  53. metadata +16 -5
  54. data/lib/kitchen/directions/bake_theorem/main.rb +0 -11
  55. data/lib/kitchen/directions/bake_theorem/v1.rb +0 -28
  56. data/lib/kitchen/templates/eoc_section_title_template.xhtml.erb +0 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50c444687ca21462df4d8110fd8789f10ba40a439b5d037b3eba8d255b5e16fa
4
- data.tar.gz: 353afbf616ae3f9794ee13594cf9baa244fbc1077e55c78c193aac1a89cefffd
3
+ metadata.gz: 3a071ba6e289c222a7333f401c7d6bd25d6dba9527253b6c6ae123169d9b6425
4
+ data.tar.gz: 2debc535f61a289f6668019f1eeb5cd639efaf8d49172d668f8b602e02e91b07
5
5
  SHA512:
6
- metadata.gz: 0b52d4418f83bdacfac36d7d6c904500cd4bb965795f91e718c6588e0f27c72eb5b73d9b05db9f2bafa60711717c93888a0d09ced10c6986e7ec0a83d7283a31
7
- data.tar.gz: 34ebd35add4868907853f3a3e4cc839f521352d3eadc763350487e5a7f372f947e6e837d0fea7ad198810d968c1e1bfc7a591f515b65218253c084db21b85a45
6
+ metadata.gz: 6bfeae3a664c95c17249ab32a8bba863091fb1e23f501273fd57d9752688c29ba9877b5a6404393dc88ae993f16af3f89fa768e3984cf81233908ab238b0350a
7
+ data.tar.gz: '086fa06f8f7eb33f3908c15ba0172a02a1738c943ba87b25245f63626cda51e5163edbece95cdce2ce1907d5815aefd179db7fb7e3a4fe2a7165c623c5120ede'
data/CHANGELOG.md CHANGED
@@ -6,6 +6,48 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [10.0.0] - 2021-07-30
10
+
11
+ * Add support for baking multipart questions to `BakeNumberedExercise` (minor)
12
+ * Add `has_para` option to `BakeChapterGlossary` for books from Adaptarr (minor)
13
+ * Create `BakeListsWithPara` to remove paragraphs from lists in books created by Adaptarr (minor)
14
+ * Create `Strategy::ContemporaryMath` (minor)
15
+ * Stop `BakeTableBody` from blowing up when table doesn't have an ID (patch)
16
+ * Refactor `MoveExercisesToEOC::V2` & `BakeChapterKeyConcepts` to use `MoveCustomSectionToEocContainer` (minor)
17
+ * Add wrapper support for `MoveCustomSectionToEocContainer` (minor)
18
+ * Create `BakeHandbook` direction (minor)
19
+ * Add `ExampleElement#titles_to_rename` & refactor `BakeExample` (patch)
20
+ * Create `BakeUnitPageTitle` (minor)
21
+ * Fix `BakeExample` to skip baked exercises (patch)
22
+ * Add `FigureElement#figure_to_bake?` (minor)
23
+ * Remove `itemprop` attribute from `BakeChapterSummary` and `BakeFurtherResearch` (major)
24
+ * Fix `NoteElement#title` to exclude nested element titles (patch)
25
+ * Remove `BakeTheorem` (minor)
26
+ * Allow `BakeChapterSolutions` to bake solutions from multiple sections (minor)
27
+ * Add `.os-problem-container` to `BakeFirstElement` selectors (minor)
28
+ * Tweak `BakeExample` to not touch unbaked titles in captions (minor/patch)
29
+ * Tweak `BakeNumberedTables.v1` to cut extra white space (minor)
30
+
31
+ ## [9.2.0] - 2021-07-19
32
+
33
+ * Update `BakeFirstElements` to also add the `.has-first-inline-list` class (minor)
34
+
35
+ ## [9.1.0] - 2021-07-16
36
+
37
+ * Add `BakeNoteIFrames` direction (minor)
38
+ * Selector optimization in precalculus `Strategy` & elsewhere (patch)
39
+ * Tweaks inline list seperators to only target labeled items (major?)
40
+ * Add definition of handbook page selector needed for BakeToc, create a link class for this page (minor)
41
+
42
+ ## [9.0.0] - 2021-07-12
43
+
44
+ * Refactor `BakeChapterKeyConcepts`, `BakeChapterReferences`, `BakeChapterSolutions`, and `MoveExercisesToEoc` versions 1-3 to use new general eoc directions (major)
45
+ * Fixed `BakeExample.v1` to also search inside `.body` for titles (minor)
46
+ * Add documentation to `MoveCustomSectionToEocContainer` & `EocCompositePageContainer` (minor)
47
+ * Add a `MoveCustomSectionToEocContainer` to allow for custom sections (minor)
48
+ * Add a `EocCompositePageContainer` direction to handle creation of eoc page wrapper (minor)
49
+ * Refactor `BakeChapterKeyEquations`, `BakeChapterGlossary`, `BakeChapterSummary`, `BakeFurtherResearch` (major)
50
+ * Fix metadata title in composite pages (major)
9
51
 
10
52
  ## [8.0.1] - 2021-06-29
11
53
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openstax_kitchen (8.0.1)
4
+ openstax_kitchen (10.0.0)
5
5
  activesupport
6
6
  i18n
7
7
  nokogiri
@@ -52,14 +52,6 @@ module Kitchen
52
52
  search("div[data-type='glossary']")
53
53
  end
54
54
 
55
- # Returns an enumerator for the key equations
56
- #
57
- # @return [ElementEnumerator]
58
- #
59
- def key_equations
60
- search('section.key-equations')
61
- end
62
-
63
55
  # Returns an enumerator for the abstracts
64
56
  #
65
57
  # @return [ElementEnumerator]
@@ -29,10 +29,8 @@ module Kitchen
29
29
  # @return [Element]
30
30
  #
31
31
  def title
32
- # Get the title in the immediate children, not the one in the metadata. Could use
33
- # CSS of ":not([data-type='metadata']) > [data-type='document-title'], [data-type='document-title']"
34
- # but xpath is shorter
35
- first!("./*[@data-type = 'document-title' or @data-type = 'title']")
32
+ first!('h3[data-type="title"], h2[data-type="document-title"],' \
33
+ 'h1[data-type="document-title"]')
36
34
  end
37
35
 
38
36
  # Returns true if this page is a book index
@@ -15,6 +15,9 @@ Metrics/CyclomaticComplexity:
15
15
  Metrics/PerceivedComplexity:
16
16
  Enabled: false
17
17
 
18
+ Metrics/ParameterLists:
19
+ Max: 5
20
+
18
21
  Style/ClassAndModuleChildren:
19
22
  Enabled: false
20
23
 
@@ -5,12 +5,13 @@ module Kitchen
5
5
  # Bake directons for eoc glossary
6
6
  #
7
7
  module BakeChapterGlossary
8
- def self.v1(chapter:, metadata_source:, append_to: nil, uuid_prefix: nil)
8
+ def self.v1(chapter:, metadata_source:, append_to: nil, uuid_prefix: nil, has_para: false)
9
9
  V1.new.bake(
10
10
  chapter: chapter,
11
11
  metadata_source: metadata_source,
12
12
  append_to: append_to,
13
- uuid_prefix: uuid_prefix
13
+ uuid_prefix: uuid_prefix,
14
+ has_para: has_para
14
15
  )
15
16
  end
16
17
  end
@@ -2,8 +2,6 @@
2
2
 
3
3
  module Kitchen::Directions::BakeChapterGlossary
4
4
  class V1
5
- renderable
6
-
7
5
  class Definition
8
6
  attr_reader :element
9
7
 
@@ -23,26 +21,33 @@ module Kitchen::Directions::BakeChapterGlossary
23
21
  attr_reader :sortable
24
22
  end
25
23
 
26
- def bake(chapter:, metadata_source:, append_to: nil, uuid_prefix: '')
27
- @metadata = metadata_source.children_to_keep.copy
28
- @klass = 'glossary'
29
- @title = I18n.t(:eoc_key_terms_title)
30
- @uuid_prefix = uuid_prefix
24
+ def bake(chapter:, metadata_source:, append_to: nil, uuid_prefix: '', has_para: false)
31
25
  @glossary = []
32
26
 
27
+ # Use for books created by Adaptarr, where dd contains paragraphs
28
+ # More info: https://github.com/openstax/kitchen/issues/284
29
+ if has_para
30
+ chapter.glossaries.search('dd').each do |description|
31
+ description_content = description.first('p').text
32
+ description.replace_children with: description_content
33
+ end
34
+ end
35
+
33
36
  chapter.glossaries.search('dl').each do |definition_element|
34
37
  @glossary.push(Definition.new(definition_element.cut))
35
38
  end
36
39
 
37
40
  chapter.glossaries.trash
38
41
 
39
- @content = @glossary.sort.map { |definition| definition.element.paste }.join
40
-
41
- append_to_element = append_to || chapter
42
- @in_composite_chapter = append_to_element.is?(:composite_chapter)
42
+ content = @glossary.sort.map { |definition| definition.element.paste }.join
43
43
 
44
- append_to_element.append(child: render(file:
45
- '../../templates/eoc_section_title_template.xhtml.erb'))
44
+ Kitchen::Directions::EocCompositePageContainer.v1(
45
+ container_key: 'glossary',
46
+ uuid_key: "#{uuid_prefix}glossary",
47
+ metadata_source: metadata_source,
48
+ content: content,
49
+ append_to: append_to || chapter
50
+ )
46
51
  end
47
52
  end
48
53
  end
@@ -2,34 +2,21 @@
2
2
 
3
3
  module Kitchen::Directions::BakeChapterKeyConcepts
4
4
  class V1
5
- renderable
6
5
  def bake(chapter:, metadata_source:, append_to:, uuid_prefix:)
7
- @metadata = metadata_source.children_to_keep.copy
8
- @klass = 'key-concepts'
9
- @title = I18n.t(:eoc_key_concepts)
10
- @uuid_prefix = uuid_prefix
11
-
12
- key_concepts_clipboard = Kitchen::Clipboard.new
13
- chapter.non_introduction_pages.each do |page|
14
- key_concepts = page.key_concepts
15
- next if key_concepts.none?
16
-
17
- key_concepts.search('h3').trash
18
- title = Kitchen::Directions::EocSectionTitleLinkSnippet.v1(page: page)
19
- key_concepts.each do |key_concept|
20
- key_concept.prepend(child: title)
21
- key_concept.wrap("<div class='os-section-area'>")
22
- page.search('div.os-section-area').first.cut(to: key_concepts_clipboard)
23
- end
6
+ Kitchen::Directions::MoveCustomSectionToEocContainer.v1(
7
+ chapter: chapter,
8
+ metadata_source: metadata_source,
9
+ container_key: 'key-concepts',
10
+ uuid_key: "#{uuid_prefix}key-concepts",
11
+ section_selector: 'section.key-concepts',
12
+ append_to: append_to || chapter,
13
+ include_intro_page: false,
14
+ wrap_section: true, wrap_content: true
15
+ ) do |section|
16
+ Kitchen::Directions::RemoveSectionTitle.v1(section: section)
17
+ title = Kitchen::Directions::EocSectionTitleLinkSnippet.v1(page: section.ancestor(:page))
18
+ section.prepend(child: title)
24
19
  end
25
-
26
- @content = "<div class=\"os-key-concepts\"> #{key_concepts_clipboard.paste} </div>"
27
-
28
- append_to_element = append_to || chapter
29
- @in_composite_chapter = append_to_element.is?(:composite_chapter)
30
-
31
- append_to_element.append(child: render(file:
32
- '../../templates/eoc_section_title_template.xhtml.erb'))
33
20
  end
34
21
  end
35
22
  end
@@ -15,24 +15,17 @@ module Kitchen
15
15
  end
16
16
 
17
17
  class V1
18
- renderable
19
18
  def bake(chapter:, metadata_source:, append_to:, uuid_prefix:)
20
- @metadata = metadata_source.children_to_keep.copy
21
- @klass = 'key-equations'
22
- @title = I18n.t(:eoc_key_equations)
23
- @uuid_prefix = uuid_prefix
24
-
25
- chapter.key_equations.search('h3').trash
26
-
27
- return if chapter.key_equations.none?
28
-
29
- @content = chapter.key_equations.cut.paste
30
-
31
- append_to_element = append_to || chapter
32
- @in_composite_chapter = append_to_element.is?(:composite_chapter)
33
-
34
- append_to_element.append(child: render(file:
35
- '../templates/eoc_section_title_template.xhtml.erb'))
19
+ MoveCustomSectionToEocContainer.v1(
20
+ chapter: chapter,
21
+ metadata_source: metadata_source,
22
+ container_key: 'key-equations',
23
+ uuid_key: "#{uuid_prefix}key-equations",
24
+ section_selector: 'section.key-equations',
25
+ append_to: append_to
26
+ ) do |section|
27
+ RemoveSectionTitle.v1(section: section)
28
+ end
36
29
  end
37
30
  end
38
31
  end
@@ -2,25 +2,22 @@
2
2
 
3
3
  module Kitchen::Directions::BakeChapterReferences
4
4
  class V1
5
- renderable
6
-
7
5
  def bake(chapter:, metadata_source:, uuid_prefix: '.', klass: 'references')
8
- @metadata = metadata_source.children_to_keep.copy
9
- @klass = klass
10
- @title = I18n.t(:references)
11
- @uuid_prefix = uuid_prefix
12
-
13
- chapter.references.search('h3').trash
14
-
15
6
  bake_page_references(page: chapter.introduction_page)
16
7
 
17
8
  chapter.non_introduction_pages.each do |page|
18
9
  bake_page_references(page: page)
19
10
  end
20
11
 
21
- @content = chapter.pages.references.cut.paste
22
- chapter.append(child: render(file:
23
- '../../templates/eoc_section_title_template.xhtml.erb'))
12
+ content = chapter.pages.references.cut.paste
13
+
14
+ Kitchen::Directions::EocCompositePageContainer.v1(
15
+ container_key: klass,
16
+ uuid_key: "#{uuid_prefix}#{klass}",
17
+ metadata_source: metadata_source,
18
+ content: content,
19
+ append_to: chapter
20
+ )
24
21
  end
25
22
 
26
23
  def bake_page_references(page:)
@@ -42,6 +39,7 @@ module Kitchen::Directions::BakeChapterReferences
42
39
  end
43
40
 
44
41
  references.each do |reference|
42
+ Kitchen::Directions::RemoveSectionTitle.v1(section: reference)
45
43
  reference.prepend(child: title)
46
44
  end
47
45
  end
@@ -3,8 +3,13 @@
3
3
  module Kitchen
4
4
  module Directions
5
5
  module BakeChapterSolutions
6
- def self.v1(chapter:, metadata_source:, uuid_prefix: '')
7
- V1.new.bake(chapter: chapter, metadata_source: metadata_source, uuid_prefix: uuid_prefix)
6
+ def self.v1(chapter:, metadata_source:, uuid_prefix: '', classes: %w[free-response])
7
+ V1.new.bake(
8
+ chapter: chapter,
9
+ metadata_source: metadata_source,
10
+ uuid_prefix: uuid_prefix,
11
+ classes: classes
12
+ )
8
13
  end
9
14
  end
10
15
  end
@@ -2,36 +2,34 @@
2
2
 
3
3
  module Kitchen::Directions::BakeChapterSolutions
4
4
  class V1
5
- renderable
6
-
7
- def bake(chapter:, metadata_source:, uuid_prefix: '')
8
- @metadata = metadata_source.children_to_keep.copy
9
- @klass = 'solutions'
10
- @title = I18n.t(:eoc_solutions_title)
11
- @uuid_prefix = uuid_prefix
12
-
5
+ def bake(chapter:, metadata_source:, uuid_prefix: '', classes: %w[free-response])
13
6
  solutions_clipboard = Kitchen::Clipboard.new
14
7
 
15
- chapter.search('section.free-response').each do |free_response_question|
16
- exercises = free_response_question.exercises
17
- # must run AFTER .free-response notes are baked
8
+ classes.each do |klass|
9
+ chapter.search("section.#{klass}").each do |question|
10
+ exercises = question.exercises
11
+ # must run AFTER the other sections are baked
18
12
 
19
- next if exercises.none?
13
+ next if exercises.none?
20
14
 
21
- exercises.each do |exercise|
22
- solution = exercise.solution
23
- next unless solution.present?
15
+ exercises.each do |exercise|
16
+ solution = exercise.solution
17
+ next unless solution.present?
24
18
 
25
- solution.cut(to: solutions_clipboard)
19
+ solution.cut(to: solutions_clipboard)
20
+ end
26
21
  end
27
22
  end
28
23
 
29
- @content = solutions_clipboard.paste
30
-
31
- @in_composite_chapter = false
24
+ content = solutions_clipboard.paste
32
25
 
33
- chapter.append(child: render(file:
34
- '../../templates/eoc_section_title_template.xhtml.erb'))
26
+ Kitchen::Directions::EocCompositePageContainer.v1(
27
+ container_key: 'solutions',
28
+ uuid_key: "#{uuid_prefix}solutions",
29
+ metadata_source: metadata_source,
30
+ content: content,
31
+ append_to: chapter
32
+ )
35
33
  end
36
34
  end
37
35
  end
@@ -15,52 +15,29 @@ module Kitchen
15
15
  end
16
16
 
17
17
  class V1
18
- renderable
19
18
  def bake(chapter:, metadata_source:, uuid_prefix: '.', klass: 'summary')
20
- @metadata = metadata_source.children_to_keep.copy
21
- @klass = klass
22
- @title = I18n.t(:eoc_summary_title)
23
- @uuid_prefix = uuid_prefix
24
-
25
19
  summaries = Clipboard.new
26
20
 
27
- # TODO: include specific page types somehow without writing it out
28
21
  chapter.non_introduction_pages.each do |page|
29
22
  summary = page.summary
30
23
 
31
24
  next if summary.nil?
32
25
 
33
26
  summary.first("[data-type='title']")&.trash # get rid of old title if exists
34
- summary_title = page.title.copy
35
- summary_title.name = 'h3'
36
-
37
- unless summary_title.children.search('span.os-number').present?
38
- summary_title.replace_children(with:
39
- <<~HTML
40
- <span class="os-number">#{chapter.count_in(:book)}.#{page.count_in(:chapter)}</span>
41
- <span class="os-divider"> </span>
42
- <span class="os-text" data-type="" itemprop="">#{summary_title.children}</span>
43
- HTML
44
- )
45
- end
46
-
47
- summary.prepend(child:
48
- <<~HTML
49
- <a href="##{page.title.id}">
50
- #{summary_title.paste}
51
- </a>
52
- HTML
53
- )
27
+ title = EocSectionTitleLinkSnippet.v1(page: page)
28
+ summary.prepend(child: title)
54
29
  summary.cut(to: summaries)
55
30
  end
56
31
 
57
32
  return if summaries.none?
58
33
 
59
- @content = summaries.paste
60
- @in_composite_chapter = false
61
-
62
- chapter.append(child: render(file:
63
- '../templates/eoc_section_title_template.xhtml.erb'))
34
+ EocCompositePageContainer.v1(
35
+ container_key: klass,
36
+ uuid_key: "#{uuid_prefix}#{klass}",
37
+ metadata_source: metadata_source,
38
+ content: summaries.paste,
39
+ append_to: chapter
40
+ )
64
41
  end
65
42
  end
66
43
  end