openstax_kitchen 12.2.0 → 13.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/Gemfile.lock +1 -1
  4. data/lib/kitchen/directions/bake_chapter_glossary/v1.rb +1 -1
  5. data/lib/kitchen/directions/bake_chapter_references/v1.rb +1 -1
  6. data/lib/kitchen/directions/bake_chapter_solutions/v1.rb +1 -1
  7. data/lib/kitchen/directions/bake_chapter_summary.rb +1 -1
  8. data/lib/kitchen/directions/bake_iframes/v1.rb +2 -0
  9. data/lib/kitchen/directions/bake_learning_objectives.rb +13 -0
  10. data/lib/kitchen/directions/bake_references/main.rb +6 -9
  11. data/lib/kitchen/directions/bake_references/v1.rb +9 -8
  12. data/lib/kitchen/directions/bake_references/v2.rb +9 -10
  13. data/lib/kitchen/directions/bake_references/v3.rb +32 -0
  14. data/lib/kitchen/directions/{eoc_composite_page_container → composite_page_container}/main.rb +1 -1
  15. data/lib/kitchen/directions/composite_page_container/v1.rb +28 -0
  16. data/lib/kitchen/directions/move_custom_section_to_eoc_container/v1.rb +1 -1
  17. data/lib/kitchen/element_base.rb +1 -1
  18. data/lib/kitchen/element_enumerator_base.rb +18 -0
  19. data/lib/kitchen/section_element.rb +27 -0
  20. data/lib/kitchen/section_element_enumerator.rb +20 -0
  21. data/lib/kitchen/selectors/base.rb +3 -0
  22. data/lib/kitchen/selectors/standard_1.rb +1 -0
  23. data/lib/kitchen/templates/composite_page_template.xhtml.erb +10 -0
  24. data/lib/kitchen/version.rb +1 -1
  25. data/lib/locales/en.yml +3 -0
  26. data/lib/locales/es.yml +3 -0
  27. data/lib/locales/pl.yml +3 -0
  28. metadata +8 -5
  29. data/lib/kitchen/directions/eoc_composite_page_container/v1.rb +0 -19
  30. data/lib/kitchen/templates/eoc_section_template.xhtml.erb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f36305ee23acfe22fc13a9c06ee76f69243f1cd2cba33fe86c28c8c90b5eb36d
4
- data.tar.gz: fd501ef342ff2c7334455cc214139581dadf1619fde7841a29650b4fc10acd79
3
+ metadata.gz: b0f1212b9bee542b587323cef1fa5ff8dc7437d47921736f58c9c27ef6ee11b8
4
+ data.tar.gz: ca01c38368dc34a0e637f431caf7873f97d5dd52b465e1ae5411d6f0861b8e58
5
5
  SHA512:
6
- metadata.gz: e3b939d8a9851db4940213aae3350f720369eb794b8551627d2a44565af36aeda5ad701b62c2c1ec98fb7dcfabafa8bd2e4531642bf40dd777a635c0117560b6
7
- data.tar.gz: 5ec8d3e59faa619a3b23a84ce74514c96b6d360dc1b46d233cd1566b63815a5a7edaa73980f102b4c6656c603c43ea349fcc2eac99149cbafb8fa91d8f0e2fdc
6
+ metadata.gz: c877a0d30bde86ccc5d0e2191b3e0efe853916294d907c764a088e67a2011f9f3fa03fb018ff8aa9992e1fbaeebb753625b90f593d888d8e8a4473139e9e0f43
7
+ data.tar.gz: f96e5128a718bf1897c65b5b558d2586e6905767e355cf9119c56b536f128bbbf403c658187e6faefc0bb7e7fc3013218353a81d99c1fc8dfc30a9ffed8354db
data/CHANGELOG.md CHANGED
@@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+
10
+ ## [13.0.0] - 2021-10-6
11
+
12
+ * Add `BakeLearningObjectives` v3 (minor)
13
+ * Fix `BakeIframes` to skip already-baked iframes (patch)
14
+ * Add `SectionElement` and `SectionElementEnumerator` classes (minor)
15
+ * Refactor `EocCompositePageContainer` to be used by `EOB` sections as well (major)
16
+ * Refactor `bake_references` `v1, v2 and v3` to use `CompositePageContainer` (major)
17
+
9
18
  ## [12.2.0] - 2021-10-1
10
19
 
11
20
  * Add `context_lead_text` to translations (minor)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openstax_kitchen (12.2.0)
4
+ openstax_kitchen (13.0.0)
5
5
  activesupport
6
6
  i18n
7
7
  nokogiri
@@ -41,7 +41,7 @@ module Kitchen::Directions::BakeChapterGlossary
41
41
 
42
42
  content = @glossary.sort.map { |definition| definition.element.paste }.join
43
43
 
44
- Kitchen::Directions::EocCompositePageContainer.v1(
44
+ Kitchen::Directions::CompositePageContainer.v1(
45
45
  container_key: 'glossary',
46
46
  uuid_key: "#{uuid_prefix}glossary",
47
47
  metadata_source: metadata_source,
@@ -11,7 +11,7 @@ module Kitchen::Directions::BakeChapterReferences
11
11
 
12
12
  content = chapter.pages.references.cut.paste
13
13
 
14
- Kitchen::Directions::EocCompositePageContainer.v1(
14
+ Kitchen::Directions::CompositePageContainer.v1(
15
15
  container_key: klass,
16
16
  uuid_key: "#{uuid_prefix}#{klass}",
17
17
  metadata_source: metadata_source,
@@ -23,7 +23,7 @@ module Kitchen::Directions::BakeChapterSolutions
23
23
 
24
24
  content = solutions_clipboard.paste
25
25
 
26
- Kitchen::Directions::EocCompositePageContainer.v1(
26
+ Kitchen::Directions::CompositePageContainer.v1(
27
27
  container_key: 'solutions',
28
28
  uuid_key: "#{uuid_prefix}solutions",
29
29
  metadata_source: metadata_source,
@@ -31,7 +31,7 @@ module Kitchen
31
31
 
32
32
  return if summaries.none?
33
33
 
34
- EocCompositePageContainer.v1(
34
+ CompositePageContainer.v1(
35
35
  container_key: klass,
36
36
  uuid_key: "#{uuid_prefix}#{klass}",
37
37
  metadata_source: metadata_source,
@@ -7,6 +7,8 @@ module Kitchen::Directions::BakeIframes
7
7
  return unless iframes.any?
8
8
 
9
9
  iframes.each do |iframe|
10
+ next if iframe.has_class?('os-is-iframe')
11
+
10
12
  iframe.wrap('<div class="os-has-iframe" data-type="alternatives">')
11
13
  iframe.add_class('os-is-iframe')
12
14
  link_ref = iframe[:src]
@@ -30,6 +30,19 @@ module Kitchen
30
30
  end
31
31
  end
32
32
  end
33
+
34
+ # Wraps & moves abstract under the corresponding chapter objective in the intro page
35
+ def self.v3(chapter:)
36
+ abstracts = chapter.abstracts.map do |abstract|
37
+ abstract.wrap('<div class="learning-objective">')
38
+ abstract.parent
39
+ end
40
+
41
+ chapter.introduction_page.search('div.os-chapter-objective') \
42
+ .each_with_index do |objective, index|
43
+ objective.append(child: abstracts[index].cut.paste)
44
+ end
45
+ end
33
46
  end
34
47
  end
35
48
  end
@@ -6,18 +6,15 @@ module Kitchen
6
6
  #
7
7
  module BakeReferences
8
8
  def self.v1(book:, metadata_source:, numbered_title: false)
9
- V1.new.bake(
10
- book: book,
11
- metadata_source: metadata_source,
12
- numbered_title: numbered_title
13
- )
9
+ V1.new.bake(book: book, metadata_source: metadata_source, numbered_title: numbered_title)
14
10
  end
15
11
 
16
12
  def self.v2(book:, metadata_source:)
17
- V2.new.bake(
18
- book: book,
19
- metadata_source: metadata_source
20
- )
13
+ V2.new.bake(book: book, metadata_source: metadata_source)
14
+ end
15
+
16
+ def self.v3(book:, metadata_source:)
17
+ V3.new.bake(book: book, metadata_source: metadata_source)
21
18
  end
22
19
  end
23
20
  end
@@ -5,11 +5,6 @@ module Kitchen::Directions::BakeReferences
5
5
  renderable
6
6
 
7
7
  def bake(book:, metadata_source:, numbered_title:)
8
- @metadata = metadata_source.children_to_keep.copy
9
- @klass = 'reference'
10
- @uuid_prefix = '.'
11
- @title = I18n.t(:references)
12
-
13
8
  book.chapters.each do |chapter|
14
9
  chapter.search('[data-type="cite"]').each do |link|
15
10
  link.prepend(child:
@@ -44,10 +39,16 @@ module Kitchen::Directions::BakeReferences
44
39
  HTML
45
40
  )
46
41
  end
42
+
47
43
  chapter_area_references = book.chapters.search('.os-chapter-area').cut
48
- @content = chapter_area_references.paste
49
- book.body.append(child: render(file:
50
- '../../templates/eob_section_title_template.xhtml.erb'))
44
+
45
+ Kitchen::Directions::CompositePageContainer.v1(
46
+ container_key: 'reference',
47
+ uuid_key: '.reference',
48
+ metadata_source: metadata_source,
49
+ content: chapter_area_references.paste,
50
+ append_to: book.body
51
+ )
51
52
  end
52
53
  end
53
54
  end
@@ -2,14 +2,7 @@
2
2
 
3
3
  module Kitchen::Directions::BakeReferences
4
4
  class V2
5
- renderable
6
-
7
5
  def bake(book:, metadata_source:)
8
- @metadata = metadata_source.children_to_keep.copy
9
- @klass = 'references'
10
- @uuid_prefix = '.'
11
- @title = I18n.t(:references)
12
-
13
6
  book.chapters.each do |chapter|
14
7
 
15
8
  chapter.references.search('h3').trash
@@ -26,10 +19,16 @@ module Kitchen::Directions::BakeReferences
26
19
  HTML
27
20
  )
28
21
  end
22
+
29
23
  chapter_area_references = book.chapters.search('.os-chapter-area').cut
30
- @content = chapter_area_references.paste
31
- book.body.append(child: render(file:
32
- '../../templates/eob_section_title_template.xhtml.erb'))
24
+
25
+ Kitchen::Directions::CompositePageContainer.v1(
26
+ container_key: 'references',
27
+ uuid_key: '.references',
28
+ metadata_source: metadata_source,
29
+ content: chapter_area_references.paste,
30
+ append_to: book.body
31
+ )
33
32
  end
34
33
  end
35
34
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen::Directions::BakeReferences
4
+ class V3
5
+ def bake(book:, metadata_source:)
6
+ return unless book.references.any?
7
+
8
+ book.chapters.pages.each do |page|
9
+ page.references.each do |reference|
10
+ reference.titles.trash
11
+ reference.prepend(child:
12
+ Kitchen::Directions::EocSectionTitleLinkSnippet.v1(
13
+ page: page,
14
+ title_tag: 'h2',
15
+ wrapper: nil
16
+ )
17
+ )
18
+ end
19
+ end
20
+
21
+ chapter_area_references = book.chapters.references.cut
22
+
23
+ Kitchen::Directions::CompositePageContainer.v1(
24
+ container_key: 'references',
25
+ uuid_key: '.references',
26
+ metadata_source: metadata_source,
27
+ content: chapter_area_references.paste,
28
+ append_to: book.body
29
+ )
30
+ end
31
+ end
32
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Kitchen
4
4
  module Directions
5
- module EocCompositePageContainer
5
+ module CompositePageContainer
6
6
  # Creates a wrapper for the given content & appends it to the given element
7
7
  #
8
8
  # @param container_key [String] Appended to 'eoc.' to form the I18n key for the container title; also used as part of a class on the container.
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen::Directions::CompositePageContainer
4
+ class V1
5
+ renderable
6
+
7
+ def bake(container_key:, uuid_key:, metadata_source:, content:, append_to:)
8
+ @in_composite_chapter = append_to.is?(:composite_chapter)
9
+ @is_eoc = append_to.is?(:chapter) || @in_composite_chapter
10
+ @section = @is_eoc ? 'eoc' : 'eob'
11
+ @title = I18n.t(:"#{@section}.#{container_key}")
12
+ @uuid_key = uuid_key
13
+ @container_class_type = container_key
14
+ @metadata = metadata_source.children_to_keep.copy
15
+ @content = content
16
+ @main_title_tag = 'h1'
17
+
18
+ if @in_composite_chapter
19
+ @main_title_tag = 'h3'
20
+ elsif @is_eoc
21
+ @main_title_tag = 'h2'
22
+ end
23
+
24
+ append_to.append(child: render(file:
25
+ '../../templates/composite_page_template.xhtml.erb'))
26
+ end
27
+ end
28
+ end
@@ -30,7 +30,7 @@ module Kitchen::Directions::MoveCustomSectionToEocContainer
30
30
  section_clipboard.paste
31
31
  end
32
32
 
33
- Kitchen::Directions::EocCompositePageContainer.v1(
33
+ Kitchen::Directions::CompositePageContainer.v1(
34
34
  container_key: container_key,
35
35
  uuid_key: uuid_key,
36
36
  metadata_source: metadata_source,
@@ -754,7 +754,7 @@ module Kitchen
754
754
  def_delegators :as_enumerator, :pages, :chapters, :terms, :figures, :notes, :tables, :examples,
755
755
  :metadatas, :non_introduction_pages, :units, :titles, :exercises, :references,
756
756
  :composite_pages, :composite_chapters, :solutions, :injected_questions,
757
- :search_with
757
+ :search_with, :sections
758
758
 
759
759
  # Returns this element as an enumerator (over only one element, itself)
760
760
  #
@@ -318,6 +318,24 @@ module Kitchen
318
318
  css_or_xpath: css_or_xpath, only: only, except: except)
319
319
  end
320
320
 
321
+ # Returns an enumerator that iterates through sections within the scope of this enumerator
322
+ #
323
+ # @param css_or_xpath [String] additional selectors to further narrow the element iterated over;
324
+ # a "$" in this argument will be replaced with the default selector for the element being
325
+ # iterated over.
326
+ # @param only [Symbol, Callable] the name of a method to call on an element or a
327
+ # lambda or proc that accepts an element; elements will only be included in the
328
+ # search results if the method or callable returns true
329
+ # @param except [Symbol, Callable] the name of a method to call on an element or a
330
+ # lambda or proc that accepts an element; elements will not be included in the
331
+ # search results if the method or callable returns false
332
+ #
333
+ def sections(css_or_xpath=nil, only: nil, except: nil)
334
+ block_error_if(block_given?)
335
+ chain_to(SectionElementEnumerator,
336
+ css_or_xpath: css_or_xpath, only: only, except: except)
337
+ end
338
+
321
339
  # Returns an enumerator that iterates within the scope of this enumerator
322
340
  #
323
341
  # @param css_or_xpath [String] additional selectors to further narrow the element iterated over
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ # An element for an example
5
+ #
6
+ class SectionElement < ElementBase
7
+
8
+ # Creates a new +SectionElement+
9
+ #
10
+ # @param node [Nokogiri::XML::Node] the node this element wraps
11
+ # @param document [Document] this element's document
12
+ #
13
+ def initialize(node:, document: nil)
14
+ super(node: node,
15
+ document: document,
16
+ enumerator_class: SectionElementEnumerator)
17
+ end
18
+
19
+ # Returns the short type
20
+ # @return [Symbol]
21
+ #
22
+ def self.short_type
23
+ :section
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ # An enumerator for table elements
5
+ #
6
+ class SectionElementEnumerator < ElementEnumeratorBase
7
+ # Returns a factory for this enumerator
8
+ #
9
+ # @return [ElementEnumeratorFactory]
10
+ #
11
+ def self.factory
12
+ ElementEnumeratorFactory.new(
13
+ default_css_or_xpath: Selector.named(:section),
14
+ sub_element_class: SectionElement,
15
+ enumerator_class: self
16
+ )
17
+ end
18
+
19
+ end
20
+ end
@@ -62,6 +62,9 @@ module Kitchen
62
62
  # Selector for an injected question
63
63
  # @return [String]
64
64
  attr_accessor :injected_question
65
+ # Selector for a section
66
+ # @return [String]
67
+ attr_accessor :section
65
68
 
66
69
  # Override specific selectors
67
70
  #
@@ -29,6 +29,7 @@ module Kitchen
29
29
  self.solution = "div[data-type='solution'], " \
30
30
  "div[data-type='question-solution']"
31
31
  self.injected_question = "div[data-type='exercise-question']"
32
+ self.section = 'section'
32
33
  end
33
34
 
34
35
  end
@@ -0,0 +1,10 @@
1
+ <div class="os-<%= @section%> os-<%=@container_class_type%>-container" data-type="composite-page" data-uuid-key="<%= @uuid_key %>">
2
+ <<%= @main_title_tag %> data-type="<%= @in_composite_chapter ? 'title' : 'document-title' %>">
3
+ <span class="os-text"><%= @title %></span>
4
+ </<%= @main_title_tag %>>
5
+ <div data-type="metadata" style="display: none;">
6
+ <h1 data-type="document-title" itemprop="name"><%= @title %></h1>
7
+ <%= @metadata.paste %>
8
+ </div>
9
+ <%= @content %>
10
+ </div>
@@ -3,5 +3,5 @@
3
3
  # A library for modifying the structure of OpenStax book XML.
4
4
  #
5
5
  module Kitchen
6
- VERSION = '12.2.0'
6
+ VERSION = '13.0.0'
7
7
  end
data/lib/locales/en.yml CHANGED
@@ -40,5 +40,8 @@ en:
40
40
  folio:
41
41
  preface: Preface
42
42
  access_for_free: Access for free at openstax.org
43
+ eob:
44
+ references: References
45
+ reference: References
43
46
  index:
44
47
  main: Index
data/lib/locales/es.yml CHANGED
@@ -35,5 +35,8 @@ es:
35
35
  folio:
36
36
  preface: Prefacio
37
37
  access_for_free: Acceso gratis en openstax.org
38
+ eob:
39
+ references: Referencias
40
+ reference: Referencias
38
41
  index:
39
42
  main: Índice
data/lib/locales/pl.yml CHANGED
@@ -67,6 +67,9 @@ pl:
67
67
  key-equations: Najważniejsze wzory
68
68
  summary: Podsumowanie
69
69
  references: Bibliografia
70
+ eob:
71
+ references: Bibliografia
72
+ reference: Bibliografia
70
73
  index:
71
74
  name: Skorowidz nazwisk
72
75
  term: Skorowidz rzeczowy
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstax_kitchen
3
3
  version: !ruby/object:Gem::Version
4
- version: 12.2.0
4
+ version: 13.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Slavinsky
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-01 00:00:00.000000000 Z
11
+ date: 2021-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -320,6 +320,7 @@ files:
320
320
  - lib/kitchen/directions/bake_references/main.rb
321
321
  - lib/kitchen/directions/bake_references/v1.rb
322
322
  - lib/kitchen/directions/bake_references/v2.rb
323
+ - lib/kitchen/directions/bake_references/v3.rb
323
324
  - lib/kitchen/directions/bake_stepwise.rb
324
325
  - lib/kitchen/directions/bake_suggested_reading.rb
325
326
  - lib/kitchen/directions/bake_toc.rb
@@ -334,8 +335,8 @@ files:
334
335
  - lib/kitchen/directions/chapter_review_container/chapter_review.xhtml.erb
335
336
  - lib/kitchen/directions/chapter_review_container/main.rb
336
337
  - lib/kitchen/directions/chapter_review_container/v1.rb
337
- - lib/kitchen/directions/eoc_composite_page_container/main.rb
338
- - lib/kitchen/directions/eoc_composite_page_container/v1.rb
338
+ - lib/kitchen/directions/composite_page_container/main.rb
339
+ - lib/kitchen/directions/composite_page_container/v1.rb
339
340
  - lib/kitchen/directions/eoc_section_title_link_snippet.rb
340
341
  - lib/kitchen/directions/move_custom_section_to_eoc_container/main.rb
341
342
  - lib/kitchen/directions/move_custom_section_to_eoc_container/v1.rb
@@ -393,14 +394,16 @@ files:
393
394
  - lib/kitchen/references_element_enumerator.rb
394
395
  - lib/kitchen/search_history.rb
395
396
  - lib/kitchen/search_query.rb
397
+ - lib/kitchen/section_element.rb
398
+ - lib/kitchen/section_element_enumerator.rb
396
399
  - lib/kitchen/selector.rb
397
400
  - lib/kitchen/selectors/base.rb
398
401
  - lib/kitchen/selectors/standard_1.rb
399
402
  - lib/kitchen/solution_element_enumerator.rb
400
403
  - lib/kitchen/table_element.rb
401
404
  - lib/kitchen/table_element_enumerator.rb
405
+ - lib/kitchen/templates/composite_page_template.xhtml.erb
402
406
  - lib/kitchen/templates/eob_section_title_template.xhtml.erb
403
- - lib/kitchen/templates/eoc_section_template.xhtml.erb
404
407
  - lib/kitchen/templates/eoc_section_template_old.xhtml.erb
405
408
  - lib/kitchen/term_element.rb
406
409
  - lib/kitchen/term_element_enumerator.rb
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Kitchen::Directions::EocCompositePageContainer
4
- class V1
5
- renderable
6
-
7
- def bake(container_key:, uuid_key:, metadata_source:, content:, append_to:)
8
- @title = I18n.t(:"eoc.#{container_key}")
9
- @uuid_key = uuid_key
10
- @container_class_type = container_key
11
- @metadata = metadata_source.children_to_keep.copy
12
- @content = content
13
- @in_composite_chapter = append_to.is?(:composite_chapter)
14
-
15
- append_to.append(child: render(file:
16
- '../../templates/eoc_section_template.xhtml.erb'))
17
- end
18
- end
19
- end
@@ -1,11 +0,0 @@
1
- <% main_title_tag = @in_composite_chapter ? 'h3' : 'h2' %>
2
- <div class="os-eoc os-<%=@container_class_type%>-container" data-type="composite-page" data-uuid-key="<%= @uuid_key %>">
3
- <<%= main_title_tag %> data-type="<%= @in_composite_chapter ? 'title' : 'document-title' %>">
4
- <span class="os-text"><%= @title %></span>
5
- </<%= main_title_tag %>>
6
- <div data-type="metadata" style="display: none;">
7
- <h1 data-type="document-title" itemprop="name"><%= @title %></h1>
8
- <%= @metadata.paste %>
9
- </div>
10
- <%= @content %>
11
- </div>