openstax_kitchen 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a4f70bbb3dd410d515f7501ed2b95635d4ca8b8369fe1b8ed5eda66e5c64c07
4
- data.tar.gz: ec5151233398b0136e0494efe4b4637876ab3e318f6606ea66fe8a750c46cbf0
3
+ metadata.gz: 47c8699f2836cea06df2e5a97aa79c350662e8193c9c1abfafd50740de61cbf6
4
+ data.tar.gz: 2384b847a91f55624ca266274fb273f98cfcaeb81962c988b04efcb0d619f2a1
5
5
  SHA512:
6
- metadata.gz: fce19e98ac530ffd809acb5ff968dbd9b786b11eaa217faec40f7e0af7ad5e2a2f70fae5aed9eb0d2b71bce7456a4d4b9e3842d2d484b17f7da529ed02af9d3a
7
- data.tar.gz: 36d66b6aa6cc8585726007f0edeff8eae49be3222dd33b367adb1b0b6554c0bfbc4f39537ad1e95fbf9bc0cf15a91049347c4940644dcf47348eb932bf42f623
6
+ metadata.gz: 6a617ef7617b5ebb0ae959615125a82945f965fcb7cbc080eff8da974fb843bd81fc72226fc62d9439f9012d95af21c80e6d85d81a1a0594c7b7546d8fd6e6f8
7
+ data.tar.gz: cad462c3c8809912d290148a5c5f64fd8518bd8043ba66d315babeed504dc083761014abd038a9fea8eb88caaa9dcc930be4f9c0b4f048e3590a0645b8bf0da9
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
- ## [1.0.0] - 2020-10-03
9
+ ## [2.0.0] - 2020-12-18
10
10
 
11
- First official version.
11
+ * Changed the main gem source file to have the same name as the gem (`openstax_kitchen`) so that you don't have to `require` a different name than you use in your `gem` call.
12
+
13
+ ## [1.0.0] - 2020-12-15
14
+
15
+ * First official version.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openstax_kitchen (1.0.0)
4
+ openstax_kitchen (2.0.0)
5
5
  activesupport
6
6
  i18n
7
7
  nokogiri
@@ -21,7 +21,7 @@ GEM
21
21
  simplecov (~> 0.18.0)
22
22
  concurrent-ruby (1.1.7)
23
23
  diff-lcs (1.3)
24
- docile (1.3.2)
24
+ docile (1.3.3)
25
25
  i18n (1.8.5)
26
26
  concurrent-ruby (~> 1.0)
27
27
  mini_portile2 (2.4.0)
data/README.md CHANGED
@@ -10,7 +10,7 @@ Kitchen lets you modify the structure and content of XML files. You create a `R
10
10
  Add this line to your application's Gemfile:
11
11
 
12
12
  ```ruby
13
- gem 'kitchen'
13
+ gem 'openstax_kitchen'
14
14
  ```
15
15
 
16
16
  And then execute:
@@ -32,7 +32,7 @@ We'll first talk about the generic way since those tools are also available in t
32
32
  Kitchen lets you modify the structure and content of XML files. You create a `Recipe` and `bake` it in the `Oven`:
33
33
 
34
34
  ```ruby
35
- require "kitchen"
35
+ require "openstax_kitchen"
36
36
 
37
37
  recipe = Kitchen::Recipe.new do |document|
38
38
  document.search("div.section").each do |element|
@@ -430,10 +430,10 @@ Want to make a one-file script to do some baking? Use the "inline" form of bund
430
430
  require "bundler/inline"
431
431
 
432
432
  gemfile do
433
- gem 'kitchen', git: 'https://github.com/openstax/kitchen.git', ref: 'some_sha_here'
433
+ gem 'openstax_kitchen', '2.0.0'
434
434
  end
435
435
 
436
- require "kitchen"
436
+ require "openstax_kitchen"
437
437
 
438
438
  recipe = Kitchen::Recipe.new do |doc|
439
439
  # ... recipe steps here
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "kitchen"
4
+ require "openstax_kitchen"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -1,3 +1,3 @@
1
1
  module Kitchen
2
- VERSION = "1.0.0"
2
+ VERSION = "2.0.0"
3
3
  end
File without changes
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "kitchen"
4
+ require "openstax_kitchen"
5
5
  require "rspec"
6
6
  require "byebug"
7
7
  require "rainbow"
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: 1.0.0
4
+ version: 2.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: 2020-12-15 00:00:00.000000000 Z
11
+ date: 2020-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -143,14 +143,11 @@ files:
143
143
  - README.md
144
144
  - Rakefile
145
145
  - bin/console
146
- - bin/normalize
147
146
  - bin/setup
148
- - books/chemistry2e/bake.rb
149
147
  - codecov.yaml
150
148
  - docker-compose.yml
151
149
  - docker/bash
152
150
  - docker/entrypoint
153
- - lib/kitchen.rb
154
151
  - lib/kitchen/ancestor.rb
155
152
  - lib/kitchen/book_document.rb
156
153
  - lib/kitchen/book_element.rb
@@ -223,6 +220,7 @@ files:
223
220
  - lib/kitchen/version.rb
224
221
  - lib/locales/en.yml
225
222
  - lib/notes.md
223
+ - lib/openstax_kitchen.rb
226
224
  - openstax_kitchen.gemspec
227
225
  - tutorials/00/expected_baked.html
228
226
  - tutorials/00/raw.html
@@ -1,79 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/inline"
4
-
5
- gemfile do
6
- gem 'nokogiri'
7
- gem 'byebug'
8
- end
9
-
10
- require 'nokogiri'
11
- require 'byebug'
12
-
13
- # In HTML attribute order doesn't matter, but to make sure our diffs are useful resort all
14
- # attributes.
15
- def sort_attributes(document)
16
- document.traverse do |child|
17
- next if child.text? || child.document?
18
- attributes = child.attributes
19
- attributes.each do |key, value|
20
- child.remove_attribute(key)
21
- end
22
- sorted_keys = attributes.keys.sort
23
- sorted_keys.each do |key|
24
- value = attributes[key].to_s
25
- child[key] = value
26
- end
27
- end
28
- end
29
-
30
- # Legacy baked docs have a few issues that I think are unintentional; clean those
31
- def clean_legacy_baked(document)
32
- document.traverse do |child|
33
- next if child.text? || child.document?
34
-
35
- # Legacy bakings of unnumbered tables include a bogus number, delete it
36
- if child.name == "table" && (child[:class] || "").include?("unnumbered")
37
- child.remove_attribute("summary")
38
- end
39
-
40
- # Sometimes there is `class=' '`, get rid of these
41
- child.attributes.each do |key, value|
42
- child.remove_attribute(key) if key == "class" && value.to_s.strip == ""
43
- end
44
- end
45
- end
46
-
47
- def mask_copied_id_numbers(document)
48
- document.traverse do |child|
49
- if child[:id]
50
- child[:id] = child[:id].gsub(/_copy_(\d+)$/,"_copy_XXX")
51
- end
52
- end
53
- end
54
-
55
- def process(input_file:, output_file:)
56
- read_and_write(input_file: input_file, output_file: output_file) do |doc|
57
- clean_legacy_baked(doc)
58
- sort_attributes(doc)
59
- mask_copied_id_numbers(doc)
60
- end
61
- end
62
-
63
- def read_and_write(input_file:, output_file:)
64
- doc = Nokogiri::XML(File.open(input_file)){|config| config.noblanks}
65
-
66
- yield(doc) if block_given?
67
-
68
- File.open(output_file, "w") do |f|
69
- f.write doc.to_xhtml(indent:2)
70
- end
71
- end
72
-
73
- ARGV.each do |input_file|
74
- output_file = input_file.gsub(/(\.\w+)\z/,'.normalized\1')
75
-
76
- process(input_file: input_file, output_file: output_file)
77
-
78
- puts "Normalized '#{input_file}' to '#{output_file}'"
79
- end
@@ -1,133 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/inline"
4
-
5
- gemfile do
6
- gem 'kitchen', path: '/Users/jps/dev/openstax/kitchen'
7
- gem 'byebug'
8
- end
9
-
10
- require "kitchen"
11
- require 'byebug'
12
-
13
- include Kitchen::Directions
14
-
15
- recipe = Kitchen::BookRecipe.new(book_short_name: :chemistry) do |doc|
16
- book = doc.book
17
-
18
- # Some stuff just goes away
19
- book.search("cnx-pi").trash
20
-
21
- # Update the preface title
22
- book.pages("$.preface").search("div[data-type='document-title']").each do |title| # TODO add title method
23
- title.replace_children(with:
24
- <<~HTML
25
- <span data-type="" itemprop="" class="os-text">#{title.text}</span>
26
- HTML
27
- )
28
- title.name = "h1"
29
- end
30
-
31
- book.chapters.each do |chapter|
32
- BakeChapterGlossary.v1(chapter: chapter, metadata_source: book.metadata)
33
- BakeChapterKeyEquations.v1(chapter: chapter, metadata_source: book.metadata)
34
- BakeChapterSummary.v1(chapter: chapter, metadata_source: book.metadata)
35
- end
36
-
37
- BakeExercises.v1(book: book)
38
- BakeChapterIntroductions.v1(book: book)
39
-
40
- book.chapters.each do |chapter|
41
- # Fix up chapter titles - TODO put this in BakeChapter
42
- heading = chapter.at("h1[2]")
43
- heading[:id] = "chapTitle#{chapter.count_in(:book)}"
44
- heading.replace_children(with:
45
- <<~HTML
46
- <span class="os-part-text">Chapter </span>
47
- <span class="os-number">#{chapter.count_in(:book)}</span>
48
- <span class="os-divider"> </span>
49
- <span data-type="" itemprop="" class="os-text">#{heading.text}</span>
50
- HTML
51
- )
52
-
53
- chapter.tables("$:not(.unnumbered)").each do |table|
54
- BakeNumberedTable.v1(table: table, number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}")
55
- end
56
-
57
- chapter.examples.each do |example|
58
- BakeExample.v1(example: example,
59
- number: "#{chapter.count_in(:book)}.#{example.count_in(:chapter)}",
60
- title_tag: "h3")
61
- end
62
-
63
- chapter.pages("$:not(.introduction)").each do |page|
64
- page.search("div[data-type='description']").each(&:trash)
65
- page.add_class("chapter-content-module")
66
-
67
- title = page.search("div[data-type='document-title']").first
68
- title.name = "h2"
69
- title.replace_children(with:
70
- <<~HTML
71
- <span class="os-number">#{chapter.count_in(:book)}.#{page.count_in(:chapter)}</span>
72
- <span class="os-divider"> </span>
73
- <span data-type="" itemprop="" class="os-text">#{title.text}</span>
74
- HTML
75
- )
76
- end
77
-
78
- chapter.figures.each do |figure|
79
- BakeFigure.v1(figure: figure, number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}")
80
- end
81
- end
82
-
83
- book.pages("$.appendix").each do |page|
84
- appendix_letter = [*('A'..'Z')][page.count_in(:book)-1]
85
-
86
- page.figures.each do |figure|
87
- BakeFigure.v1(figure: figure, number: "#{appendix_letter}#{figure.count_in(:page)}")
88
- end
89
-
90
- page.tables("$:not(.unnumbered)").each do |table|
91
- BakeNumberedTable.v1(table: table, number: "#{appendix_letter}#{table.count_in(:page)}")
92
- end
93
-
94
- page.examples.each do |example|
95
- BakeExample.v1(example: example,
96
- number: "#{appendix_letter}#{example.count_in(:page)}",
97
- title_tag: "div")
98
- end
99
-
100
- BakeAppendix.v1(page: page, number: appendix_letter)
101
- end
102
-
103
- BakeNotes.v1(book: book)
104
- BakeStepwise.v1(book: book)
105
- BakeUnnumberedTables.v1(book: book)
106
- BakeMathInParagraph.v1(book: book)
107
- BakeIndex.v1(book: book)
108
- BakeCompositePages.v1(book: book)
109
- BakeFootnotes.v1(book: book)
110
-
111
- BakeToc.v1(book: book)
112
-
113
- # competing docs from elements - BakeLinkPlaceholders
114
- book.search("a").each do |anchor|
115
- next unless anchor.text == "[link]"
116
- id = anchor[:href][1..-1]
117
- replacement = doc.pantry(name: :link_text).get(id)
118
- if replacement.present?
119
- anchor.replace_children(with: replacement)
120
- else
121
- # TODO log a warning!
122
- puts "warning! could not find a replacement for '[link]' on an element with ID '#{id}'"
123
- end
124
- end
125
-
126
- end
127
-
128
- puts Kitchen::Oven.bake(
129
- # input_file: "collection.assembled.xhtml",
130
- input_file: "entire.collection.assembled.xhtml",
131
- recipes: recipe,
132
- output_file: "collection.kitchen.xhtml"
133
- )