openstax_kitchen 6.0.0 → 9.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/changelog.yml +0 -3
  3. data/CHANGELOG.md +38 -4
  4. data/Gemfile.lock +2 -2
  5. data/docker/rubocop +6 -4
  6. data/lib/kitchen/chapter_element.rb +0 -8
  7. data/lib/kitchen/composite_page_element.rb +20 -3
  8. data/lib/kitchen/directions/.rubocop.yml +3 -0
  9. data/lib/kitchen/directions/bake_chapter_glossary/v1.rb +30 -16
  10. data/lib/kitchen/directions/bake_chapter_key_concepts/v1.rb +9 -13
  11. data/lib/kitchen/directions/bake_chapter_key_equations.rb +10 -17
  12. data/lib/kitchen/directions/bake_chapter_references/main.rb +1 -2
  13. data/lib/kitchen/directions/bake_chapter_references/v1.rb +33 -21
  14. data/lib/kitchen/directions/bake_chapter_solutions/v1.rb +8 -12
  15. data/lib/kitchen/directions/bake_chapter_summary.rb +10 -32
  16. data/lib/kitchen/directions/bake_eoc_section_content/remove_section_title.rb +11 -0
  17. data/lib/kitchen/directions/bake_example.rb +7 -1
  18. data/lib/kitchen/directions/bake_further_research.rb +13 -39
  19. data/lib/kitchen/directions/bake_inline_lists.rb +22 -0
  20. data/lib/kitchen/directions/bake_references/main.rb +7 -0
  21. data/lib/kitchen/directions/bake_references/v2.rb +35 -0
  22. data/lib/kitchen/directions/bake_toc.rb +3 -1
  23. data/lib/kitchen/directions/eoc_composite_page_container/main.rb +27 -0
  24. data/lib/kitchen/directions/eoc_composite_page_container/v1.rb +19 -0
  25. data/lib/kitchen/directions/move_custom_section_to_eoc_container/main.rb +37 -0
  26. data/lib/kitchen/directions/move_custom_section_to_eoc_container/v1.rb +27 -0
  27. data/lib/kitchen/directions/move_exercises_to_eoc/v1.rb +10 -27
  28. data/lib/kitchen/directions/move_exercises_to_eoc/v2.rb +11 -18
  29. data/lib/kitchen/directions/move_exercises_to_eoc/v3.rb +14 -38
  30. data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/calculus.rb +5 -5
  31. data/lib/kitchen/directions/move_solutions_to_answer_key/strategies/default.rb +3 -3
  32. data/lib/kitchen/element_base.rb +2 -2
  33. data/lib/kitchen/example_element.rb +1 -1
  34. data/lib/kitchen/i18n_string.rb +16 -0
  35. data/lib/kitchen/patches/array.rb +15 -0
  36. data/lib/kitchen/templates/eoc_section_template.xhtml.erb +11 -0
  37. data/lib/kitchen/templates/eoc_section_template_old.xhtml.erb +11 -0
  38. data/lib/kitchen/version.rb +1 -1
  39. data/lib/locales/en.yml +7 -5
  40. data/lib/locales/es.yml +7 -5
  41. data/lib/locales/pl.yml +6 -3
  42. data/lib/openstax_kitchen.rb +1 -0
  43. metadata +13 -3
  44. 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: 544eb8b780fd248111e4dc9738c32b7edfefc101fbf6abd82f25c01bada69708
4
- data.tar.gz: c3f1e2658259f5d9a04dde8aa188793c3c82e8ef6a4f6c1354e2b50d5ed7982d
3
+ metadata.gz: fca2eb47435f5ff74342d7de2afc02e2c55eed224f1ae669b440d52a1c50b1b0
4
+ data.tar.gz: f22d42bc7618868d1890e149d9e0bf5134945b8fccce5c7742827e6c53589d81
5
5
  SHA512:
6
- metadata.gz: 1829a8193fd8d53e2eaa4d91bd00417eb439b1dce3e690b865ff7741d3aad8637282a680f7840842180bfd811cbd79d7275b1c75502fdbcb72d39ed81572b905
7
- data.tar.gz: 6cf08743860774a7f7b6fa73d26d4adbc56d7e2849e2178fc020456f113774942d23f7f14f2a5f02393c43cbfa0312b787bbb8a1adbdca4943fd76cb697ff9c0
6
+ metadata.gz: a457781d0bcb61533c5b96ca0b2ffcde74a69743a54c09f4b901b7e769056d1d616afa736df40067e7472a479c8526505d72fe5d7e9ecf3eca6789581d92c380
7
+ data.tar.gz: 9f517fbc86ae32e0fd2bbc108774a9f4b94a63df01675530c7f26d7f9bf9522654f4ddb5d7e1c9d141b1a67a0ccc6a98ac2f8c0cf94719ccf04b67cfbf69f240
@@ -2,9 +2,6 @@ name: CHANGELOG.md
2
2
 
3
3
  on:
4
4
  pull_request:
5
- push:
6
- branches:
7
- - main
8
5
 
9
6
  jobs:
10
7
  exists:
data/CHANGELOG.md CHANGED
@@ -6,6 +6,39 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [9.0.0] - 2021-07-12
10
+
11
+ * Refactor `BakeChapterKeyConcepts`, `BakeChapterReferences`, `BakeChapterSolutions`, and `MoveExercisesToEoc` versions 1-3 to use new general eoc directions (major?)
12
+ * Fixed `BakeExample.v1` to also search inside `.body` for titles (minor)
13
+ * Add documentation to `MoveCustomSectionToEocContainer` & `EocCompositePageContainer` (minor)
14
+ * Add a `MoveCustomSectionToEocContainer` to allow for custom sections (minor)
15
+ * Add a `EocCompositePageContainer` direction to handle creation of eoc page wrapper (minor)
16
+ * Refactor `BakeChapterKeyEquations`, `BakeChapterGlossary`, `BakeChapterSummary`, `BakeFurtherResearch` (major)
17
+ * Fix metadata title in composite pages (major)
18
+
19
+ ## [8.0.1] - 2021-06-29
20
+
21
+ * Added tags to classnames to optimize searches in `calculus strategy` for `move_solutions_to_answer_key` (minor)
22
+
23
+ ## [8.0.0] - 2021-06-29
24
+
25
+ * Sort terms in `BakeChapterGlossary` in language specific way (major)
26
+ * Spanish translation change (minor)
27
+ * Fixed the implementation of `Element#wrap_children` to reuse existing document elements (major).
28
+
29
+ ## [7.0.0] - 2021-06-21
30
+
31
+ * Changed selector expected by `default strategy` in `move_solutions_to_answer_key` to optimize search (major)
32
+ * Fix Rubocop GitHub Action's regular expression used to select files to lint (patch)
33
+ * Add optional numbering to multiple solutions inside examples (minor)
34
+ * Added monkey patch for array to be able to add a prefix: `%w[multiple-choice true-false].prefix('section.')` (minor)
35
+ * Add more specific book part selector (`os-eob`) for References in `is_citation_reference?`, `is_section_reference?` methods in `Element Base` to fix toc selector for References which are moved to EoC (major)
36
+
37
+ ## [6.1.0] - 2021-06-21
38
+
39
+ * Create a `BakeReferences` V2 for unnumbered section references (minor)
40
+ * Don't check for CHANGELOG when merge a PR to main (patch)
41
+ * Added `BakeInlineLists` (minor)
9
42
 
10
43
  ## [6.0.0] - 2021-06-15
11
44
 
@@ -33,10 +66,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
33
66
  * Adds `BakeNumberedNotes` V3 (minor)
34
67
  * Added line that puts the classname `has-footnote` in the footnote ref's parent element (major)
35
68
  * Added a condition into `BakeChapterSummary` so it doesn't bake the title if it already includes the respective number in it
36
- * Create v3 of MoveExercisesToEOC which differs from v1 by the presence of a section title
37
- and from v2 the lack of additional "os-section-area" and os-#{@klass} wrapper (minor)
38
- * Add a condition in BakeNumberedExercise to make it possible to suppress even solutions in the Answer Key (minor)
39
- * Fix BakeFurtherResearch baking with main bake script error by breaking the loop if further research sections are not present (minor)
69
+ * Create v3 of `MoveExercisesToEOC` which differs from v1 by the presence of a section title
70
+ and from v2 the lack of additional `os-section-area` and `os-#{@klass} wrapper` (minor)
71
+ * Add a condition in `BakeNumberedExercise` to make it possible to suppress even solutions in the Answer Key (minor)
72
+ * Fix `BakeFurtherResearch` baking with main bake script error by breaking the loop if further research sections are not present (minor)
73
+ * Rework v1 of `BakeChapterReferences` to bake references also from introduction pages (major)
40
74
  * Fix for `BakeIndex` for words that start with a number to be grouped as symbols and for first letters with accent marks to be grouped with regular letters in alphabetic order (major)
41
75
 
42
76
  ## [5.0.0] - 2021-06-02
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openstax_kitchen (6.0.0)
4
+ openstax_kitchen (9.0.0)
5
5
  activesupport
6
6
  i18n
7
7
  nokogiri
@@ -11,7 +11,7 @@ PATH
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- activesupport (6.1.3.2)
14
+ activesupport (6.1.4)
15
15
  concurrent-ruby (~> 1.0, >= 1.0.2)
16
16
  i18n (>= 1.6, < 2)
17
17
  minitest (>= 5.1)
data/docker/rubocop CHANGED
@@ -4,13 +4,15 @@
4
4
 
5
5
  DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
6
6
 
7
- from="${1:-main}"
8
- to="${2:-HEAD}"
7
+ commit_range="${1:-main}"
8
+ if [ ! -z "$2" ]; then
9
+ commit_range="$commit_range..$2"
10
+ fi
9
11
 
10
- echo "Checking from $from to $to"
12
+ echo "Checking $commit_range"
11
13
 
12
14
  # https://dev.to/scienta/get-changed-files-in-github-actions-1p36
13
- changed_ruby_files=$(git diff --name-only --diff-filter=ACMRT $from $to | grep -E "(lib\/|spec\/)*.rb$" | xargs)
15
+ changed_ruby_files=$(git diff --name-only --diff-filter=ACMRT $commit_range | grep -E "(lib\/|spec\/).*\.rb$" | xargs)
14
16
 
15
17
  if [[ -z "${changed_ruby_files// }" ]]; then
16
18
  echo "No files to lint with Rubocop"
@@ -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]
@@ -43,12 +43,29 @@ module Kitchen
43
43
  has_class?('os-index-container')
44
44
  end
45
45
 
46
- # Returns true if this page is a book reference
46
+ # In books we can find two types of EOB References.
47
+ #
48
+ # One of them has form similar to footnotes. There are citation links in the text that provides
49
+ # to the reference note at the end of the book.
50
+ #
51
+ # Second one is a section with references on the Introduction page that is moved to the EOB.
52
+ #
53
+ # Difference in classes is important.
54
+
55
+ # Returns true if this page is a book citation reference
56
+ #
57
+ # @return [Boolean]
58
+ #
59
+ def is_citation_reference?
60
+ has_class?('os-eob os-reference-container')
61
+ end
62
+
63
+ # Returns true if this page is a book section reference
47
64
  #
48
65
  # @return [Boolean]
49
66
  #
50
- def is_reference?
51
- has_class?('os-reference-container')
67
+ def is_section_reference?
68
+ has_class?('os-eob os-references-container')
52
69
  end
53
70
 
54
71
  end
@@ -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
 
@@ -2,29 +2,43 @@
2
2
 
3
3
  module Kitchen::Directions::BakeChapterGlossary
4
4
  class V1
5
- renderable
5
+ class Definition
6
+ attr_reader :element
7
+
8
+ def initialize(element)
9
+ term = Kitchen::I18nString.new(element.first('dt').text.downcase)
10
+ description = Kitchen::I18nString.new(element.first('dd').text.downcase)
11
+ @sortable = [term, description]
12
+ @element = element
13
+ end
14
+
15
+ def <=>(other)
16
+ sortable <=> other.sortable
17
+ end
18
+
19
+ protected
20
+
21
+ attr_reader :sortable
22
+ end
6
23
 
7
24
  def bake(chapter:, metadata_source:, append_to: nil, uuid_prefix: '')
8
- @metadata = metadata_source.children_to_keep.copy
9
- @klass = 'glossary'
10
- @title = I18n.t(:eoc_key_terms_title)
11
- @uuid_prefix = uuid_prefix
12
-
13
- definitions = chapter.glossaries.search('dl').cut
14
- return if definitions.none?
15
- definitions.sort_by! do |definition|
16
- [definition.first('dt').text.downcase, definition.first('dd').text.downcase]
25
+ @glossary = []
26
+
27
+ chapter.glossaries.search('dl').each do |definition_element|
28
+ @glossary.push(Definition.new(definition_element.cut))
17
29
  end
18
30
 
19
31
  chapter.glossaries.trash
20
32
 
21
- @content = definitions.paste
22
-
23
- append_to_element = append_to || chapter
24
- @in_composite_chapter = append_to_element.is?(:composite_chapter)
33
+ content = @glossary.sort.map { |definition| definition.element.paste }.join
25
34
 
26
- append_to_element.append(child: render(file:
27
- '../../templates/eoc_section_title_template.xhtml.erb'))
35
+ Kitchen::Directions::EocCompositePageContainer.v1(
36
+ container_key: 'glossary',
37
+ uuid_key: "#{uuid_prefix}glossary",
38
+ metadata_source: metadata_source,
39
+ content: content,
40
+ append_to: append_to || chapter
41
+ )
28
42
  end
29
43
  end
30
44
  end
@@ -2,34 +2,30 @@
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
6
  key_concepts_clipboard = Kitchen::Clipboard.new
13
7
  chapter.non_introduction_pages.each do |page|
14
8
  key_concepts = page.key_concepts
15
9
  next if key_concepts.none?
16
10
 
17
- key_concepts.search('h3').trash
18
11
  title = Kitchen::Directions::EocSectionTitleLinkSnippet.v1(page: page)
19
12
  key_concepts.each do |key_concept|
13
+ Kitchen::Directions::RemoveSectionTitle.v1(section: key_concept)
20
14
  key_concept.prepend(child: title)
21
15
  key_concept.wrap("<div class='os-section-area'>")
22
16
  page.search('div.os-section-area').first.cut(to: key_concepts_clipboard)
23
17
  end
24
18
  end
25
19
 
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)
20
+ content = "<div class=\"os-key-concepts\"> #{key_concepts_clipboard.paste} </div>"
30
21
 
31
- append_to_element.append(child: render(file:
32
- '../../templates/eoc_section_title_template.xhtml.erb'))
22
+ Kitchen::Directions::EocCompositePageContainer.v1(
23
+ container_key: 'key-concepts',
24
+ uuid_key: "#{uuid_prefix}key-concepts",
25
+ metadata_source: metadata_source,
26
+ content: content,
27
+ append_to: append_to || chapter
28
+ )
33
29
  end
34
30
  end
35
31
  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
@@ -8,8 +8,7 @@ module Kitchen
8
8
  chapter: chapter,
9
9
  metadata_source: metadata_source,
10
10
  uuid_prefix: uuid_prefix,
11
- klass: klass
12
- )
11
+ klass: klass)
13
12
  end
14
13
  end
15
14
  end
@@ -2,34 +2,46 @@
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
6
+ bake_page_references(page: chapter.introduction_page)
14
7
 
15
8
  chapter.non_introduction_pages.each do |page|
16
- references = page.references
17
- next if references.none?
18
-
19
- references.search('h3').trash
20
- title = Kitchen::Directions::EocSectionTitleLinkSnippet.v1(page: page)
21
-
22
- references.each do |reference|
23
- reference.prepend(child: title)
24
- end
9
+ bake_page_references(page: page)
25
10
  end
26
11
 
27
- @content = chapter.pages.references.cut.paste
12
+ content = chapter.pages.references.cut.paste
28
13
 
29
- @in_composite_chapter = false
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
+ )
21
+ end
30
22
 
31
- chapter.append(child: render(file:
32
- '../../templates/eoc_section_title_template.xhtml.erb'))
23
+ def bake_page_references(page:)
24
+ return if page.nil?
25
+
26
+ references = page.references
27
+ return if references.none?
28
+
29
+ title = if page.is_introduction?
30
+ <<~HTML
31
+ <a href="##{page.title.id}">
32
+ <h3 data-type="document-title" id="#{page.title.copied_id}">
33
+ <span class="os-text" data-type="" itemprop="">#{page.title_text}</span>
34
+ </h3>
35
+ </a>
36
+ HTML
37
+ else
38
+ Kitchen::Directions::EocSectionTitleLinkSnippet.v1(page: page)
39
+ end
40
+
41
+ references.each do |reference|
42
+ Kitchen::Directions::RemoveSectionTitle.v1(section: reference)
43
+ reference.prepend(child: title)
44
+ end
33
45
  end
34
46
  end
35
47
  end
@@ -2,14 +2,7 @@
2
2
 
3
3
  module Kitchen::Directions::BakeChapterSolutions
4
4
  class V1
5
- renderable
6
-
7
5
  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
-
13
6
  solutions_clipboard = Kitchen::Clipboard.new
14
7
 
15
8
  chapter.search('section.free-response').each do |free_response_question|
@@ -26,12 +19,15 @@ module Kitchen::Directions::BakeChapterSolutions
26
19
  end
27
20
  end
28
21
 
29
- @content = solutions_clipboard.paste
30
-
31
- @in_composite_chapter = false
22
+ content = solutions_clipboard.paste
32
23
 
33
- chapter.append(child: render(file:
34
- '../../templates/eoc_section_title_template.xhtml.erb'))
24
+ Kitchen::Directions::EocCompositePageContainer.v1(
25
+ container_key: 'solutions',
26
+ uuid_key: "#{uuid_prefix}solutions",
27
+ metadata_source: metadata_source,
28
+ content: content,
29
+ append_to: chapter
30
+ )
35
31
  end
36
32
  end
37
33
  end
@@ -15,52 +15,30 @@ 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)
29
+ summary.first('h3')[:itemprop] = 'name'
54
30
  summary.cut(to: summaries)
55
31
  end
56
32
 
57
33
  return if summaries.none?
58
34
 
59
- @content = summaries.paste
60
- @in_composite_chapter = false
61
-
62
- chapter.append(child: render(file:
63
- '../templates/eoc_section_title_template.xhtml.erb'))
35
+ EocCompositePageContainer.v1(
36
+ container_key: klass,
37
+ uuid_key: "#{uuid_prefix}#{klass}",
38
+ metadata_source: metadata_source,
39
+ content: summaries.paste,
40
+ append_to: chapter
41
+ )
64
42
  end
65
43
  end
66
44
  end