openstax_kitchen 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +7 -0
  2. data/.devcontainer/devcontainer.json +19 -0
  3. data/.github/workflows/tests.yml +36 -0
  4. data/.gitignore +20 -0
  5. data/.rspec +3 -0
  6. data/.solargraph.yml +15 -0
  7. data/CHANGELOG.md +11 -0
  8. data/CODE_OF_CONDUCT.md +74 -0
  9. data/Dockerfile +19 -0
  10. data/Gemfile +9 -0
  11. data/Gemfile.lock +74 -0
  12. data/LICENSE.txt +21 -0
  13. data/README.md +674 -0
  14. data/Rakefile +6 -0
  15. data/bin/console +14 -0
  16. data/bin/normalize +79 -0
  17. data/bin/setup +8 -0
  18. data/books/chemistry2e/bake.rb +133 -0
  19. data/codecov.yaml +27 -0
  20. data/docker-compose.yml +12 -0
  21. data/docker/bash +1 -0
  22. data/docker/entrypoint +9 -0
  23. data/lib/kitchen.rb +57 -0
  24. data/lib/kitchen/ancestor.rb +30 -0
  25. data/lib/kitchen/book_document.rb +18 -0
  26. data/lib/kitchen/book_element.rb +24 -0
  27. data/lib/kitchen/book_element_enumerator.rb +5 -0
  28. data/lib/kitchen/book_recipe.rb +25 -0
  29. data/lib/kitchen/chapter_element.rb +35 -0
  30. data/lib/kitchen/chapter_element_enumerator.rb +13 -0
  31. data/lib/kitchen/clipboard.rb +37 -0
  32. data/lib/kitchen/composite_chapter_element.rb +23 -0
  33. data/lib/kitchen/composite_page_element.rb +27 -0
  34. data/lib/kitchen/composite_page_element_enumerator.rb +13 -0
  35. data/lib/kitchen/config.rb +20 -0
  36. data/lib/kitchen/counter.rb +34 -0
  37. data/lib/kitchen/debug/print_recipe_error.rb +80 -0
  38. data/lib/kitchen/directions/bake_appendix.rb +26 -0
  39. data/lib/kitchen/directions/bake_chapter_glossary.rb +34 -0
  40. data/lib/kitchen/directions/bake_chapter_introductions.rb +58 -0
  41. data/lib/kitchen/directions/bake_chapter_key_equations.rb +30 -0
  42. data/lib/kitchen/directions/bake_chapter_summary.rb +52 -0
  43. data/lib/kitchen/directions/bake_composite_pages.rb +13 -0
  44. data/lib/kitchen/directions/bake_example.rb +31 -0
  45. data/lib/kitchen/directions/bake_exercises.rb +164 -0
  46. data/lib/kitchen/directions/bake_figure.rb +25 -0
  47. data/lib/kitchen/directions/bake_footnotes/main.rb +11 -0
  48. data/lib/kitchen/directions/bake_footnotes/v1.rb +38 -0
  49. data/lib/kitchen/directions/bake_index/main.rb +11 -0
  50. data/lib/kitchen/directions/bake_index/v1.rb +138 -0
  51. data/lib/kitchen/directions/bake_index/v1.xhtml.erb +28 -0
  52. data/lib/kitchen/directions/bake_math_in_paragraph.rb +13 -0
  53. data/lib/kitchen/directions/bake_notes.rb +58 -0
  54. data/lib/kitchen/directions/bake_numbered_table/main.rb +11 -0
  55. data/lib/kitchen/directions/bake_numbered_table/v1.rb +47 -0
  56. data/lib/kitchen/directions/bake_stepwise.rb +27 -0
  57. data/lib/kitchen/directions/bake_toc.rb +103 -0
  58. data/lib/kitchen/directions/bake_unnumbered_tables.rb +14 -0
  59. data/lib/kitchen/directions/move_title_text_into_span.rb +15 -0
  60. data/lib/kitchen/document.rb +142 -0
  61. data/lib/kitchen/element.rb +15 -0
  62. data/lib/kitchen/element_base.rb +444 -0
  63. data/lib/kitchen/element_enumerator.rb +12 -0
  64. data/lib/kitchen/element_enumerator_base.rb +101 -0
  65. data/lib/kitchen/element_enumerator_factory.rb +111 -0
  66. data/lib/kitchen/element_factory.rb +32 -0
  67. data/lib/kitchen/errors.rb +4 -0
  68. data/lib/kitchen/example_element.rb +20 -0
  69. data/lib/kitchen/example_element_enumerator.rb +13 -0
  70. data/lib/kitchen/figure_element.rb +20 -0
  71. data/lib/kitchen/figure_element_enumerator.rb +13 -0
  72. data/lib/kitchen/mixins/block_error_if.rb +19 -0
  73. data/lib/kitchen/note_element.rb +43 -0
  74. data/lib/kitchen/note_element_enumerator.rb +13 -0
  75. data/lib/kitchen/oven.rb +61 -0
  76. data/lib/kitchen/page_element.rb +51 -0
  77. data/lib/kitchen/page_element_enumerator.rb +13 -0
  78. data/lib/kitchen/pantry.rb +35 -0
  79. data/lib/kitchen/patches/nokogiri.rb +31 -0
  80. data/lib/kitchen/patches/renderable.rb +31 -0
  81. data/lib/kitchen/patches/string.rb +5 -0
  82. data/lib/kitchen/recipe.rb +78 -0
  83. data/lib/kitchen/search_history.rb +33 -0
  84. data/lib/kitchen/selectors/base.rb +8 -0
  85. data/lib/kitchen/selectors/standard_1.rb +12 -0
  86. data/lib/kitchen/table_element.rb +36 -0
  87. data/lib/kitchen/table_element_enumerator.rb +13 -0
  88. data/lib/kitchen/term_element.rb +16 -0
  89. data/lib/kitchen/term_element_enumerator.rb +13 -0
  90. data/lib/kitchen/transliterations.rb +19 -0
  91. data/lib/kitchen/type_casting_element_enumerator.rb +23 -0
  92. data/lib/kitchen/utils.rb +19 -0
  93. data/lib/kitchen/version.rb +3 -0
  94. data/lib/locales/en.yml +21 -0
  95. data/lib/notes.md +9 -0
  96. data/openstax_kitchen.gemspec +39 -0
  97. data/tutorials/00/expected_baked.html +3 -0
  98. data/tutorials/00/raw.html +3 -0
  99. data/tutorials/00/solution_1.rb +7 -0
  100. data/tutorials/00/solution_2.rb +6 -0
  101. data/tutorials/01/expected_baked.html +66 -0
  102. data/tutorials/01/raw.html +62 -0
  103. data/tutorials/01/solution_1.rb +16 -0
  104. data/tutorials/01/solution_2.rb +24 -0
  105. data/tutorials/02/expected_baked.html +207 -0
  106. data/tutorials/02/raw.html +201 -0
  107. data/tutorials/02/solution_1.rb +29 -0
  108. data/tutorials/03/expected_baked.html +33 -0
  109. data/tutorials/03/raw.html +31 -0
  110. data/tutorials/03/solution_1.rb +16 -0
  111. data/tutorials/03/solution_2.rb +15 -0
  112. data/tutorials/04/expected_baked.html +36 -0
  113. data/tutorials/04/raw.html +36 -0
  114. data/tutorials/04/solution_1.rb +20 -0
  115. data/tutorials/04/solution_2.rb +25 -0
  116. data/tutorials/05/expected_baked.html +11 -0
  117. data/tutorials/05/raw.html +11 -0
  118. data/tutorials/05/solution_1.rb +9 -0
  119. data/tutorials/check_it +64 -0
  120. data/tutorials/setup_my_recipes +30 -0
  121. metadata +278 -0
@@ -0,0 +1,11 @@
1
+ <!--
2
+ 1. Copy the "div#original" element and add the copy right after the original one.
3
+ 2. Get rid of the "badness" div
4
+ -->
5
+
6
+ <html>
7
+ <body>
8
+ <div id="original">Someone make a copy of me</div>
9
+ <div id="original_copy_1">Someone make a copy of me</div>
10
+ </body>
11
+ </html>
@@ -0,0 +1,11 @@
1
+ <!--
2
+ 1. Copy the "div#original" element and add the copy right after the original one.
3
+ 2. Get rid of the "badness" div
4
+ -->
5
+
6
+ <html>
7
+ <body>
8
+ <div id="original">Someone make a copy of me</div>
9
+ <div id="badness">This one has got to go</div>
10
+ </body>
11
+ </html>
@@ -0,0 +1,9 @@
1
+ @solution_1 = Kitchen::Recipe.new do |doc|
2
+ original = doc.search("#original").first
3
+ original.append(sibling: <<~HTML
4
+ \n#{original.copy.paste}
5
+ HTML
6
+ )
7
+
8
+ doc.search("#badness").trash
9
+ end
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "kitchen"
5
+ require "rspec"
6
+ require "byebug"
7
+ require "rainbow"
8
+
9
+ def parse_doc(filename)
10
+ Nokogiri::XML(File.open(filename)){|config| config.noblanks}
11
+ end
12
+
13
+ def parse_doc_and_prep_for_diff(filename)
14
+ doc = parse_doc(filename)
15
+ string = doc.to_xhtml
16
+ # Get rid of whitespace at the start of lines (remove impact of indentation)
17
+ string.gsub(/^\s*/,"")
18
+ end
19
+
20
+ if ARGV.empty?
21
+ puts "Usage: check_it tutorial-folder-number [recipe-name]\n" \
22
+ " e.g. check_it 02"
23
+ exit(0)
24
+ end
25
+
26
+ tutorial_number = ARGV[0]
27
+
28
+ Dir[File.expand_path(__dir__ + "/#{tutorial_number}/*.rb")].each{|f| require f}
29
+
30
+ recipe_name = (ARGV[1] || "my_recipe")
31
+ recipe_variable_name = "@#{recipe_name}".to_sym
32
+
33
+ if !instance_variables.include?(recipe_variable_name)
34
+ puts Rainbow("There is no recipe named '#{recipe_variable_name}' defined in the " \
35
+ "tutorials/#{tutorial_number} directory").red
36
+ exit(1)
37
+ end
38
+
39
+ recipe = instance_variable_get(recipe_variable_name)
40
+
41
+ Kitchen::Oven.bake(
42
+ input_file: File.expand_path("#{tutorial_number}/raw.html", __dir__),
43
+ recipes: recipe,
44
+ output_file: File.expand_path("#{tutorial_number}/actual_baked.html", __dir__)
45
+ )
46
+
47
+ actual = parse_doc_and_prep_for_diff("#{tutorial_number}/actual_baked.html")
48
+ expected = parse_doc_and_prep_for_diff("#{tutorial_number}/expected_baked.html")
49
+
50
+ differ = RSpec::Support::Differ.new(color: true)
51
+ diff = differ.diff(expected, actual)
52
+
53
+ # Get rid of some coloring junk at the start
54
+ diff.sub!(/\e\[0m\n\e\[0m/, "")
55
+
56
+ if diff.blank?
57
+ puts Rainbow("The actual output matches the expected output! Way to go!").green
58
+ else
59
+ puts Rainbow("The actual output does not match the expected output.").yellow
60
+ puts Rainbow("-").red + " = actual output"
61
+ puts Rainbow("+").green + " = expected output"
62
+ puts "\n"
63
+ puts diff
64
+ end
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "byebug"
5
+ require "rainbow"
6
+
7
+ Dir.chdir(__dir__)
8
+ tutorial_numbers = Dir.glob("*").select{|f| File.directory?(f) && f.match?(/\d\d/)}
9
+
10
+ tutorial_numbers.each do |tutorial_number|
11
+ file_name = File.expand_path("#{tutorial_number}/my_recipe.rb", __dir__)
12
+ if File.exist?(file_name)
13
+ puts "Skipped making recipe skeleton; my_recipe.rb exists in tutorials folder '#{tutorial_number}'"
14
+ next
15
+ else
16
+ File.open(file_name, "w") do |f|
17
+ f.write <<~CONTENTS
18
+ # This file is IGNORED by Git
19
+
20
+ @my_recipe = Kitchen::Recipe.new do |doc|
21
+
22
+ # Write you recipe here
23
+
24
+ end
25
+ CONTENTS
26
+ end
27
+
28
+ puts "Generated recipe skeleton (my_recipe.rb) in tutorials folder '#{tutorial_number}'"
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,278 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openstax_kitchen
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - JP Slavinsky
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-12-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rainbow
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: i18n
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: nokogiri-diff
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rainbow
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: OpenStax content baking library
126
+ email:
127
+ - jpslav@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".devcontainer/devcontainer.json"
133
+ - ".github/workflows/tests.yml"
134
+ - ".gitignore"
135
+ - ".rspec"
136
+ - ".solargraph.yml"
137
+ - CHANGELOG.md
138
+ - CODE_OF_CONDUCT.md
139
+ - Dockerfile
140
+ - Gemfile
141
+ - Gemfile.lock
142
+ - LICENSE.txt
143
+ - README.md
144
+ - Rakefile
145
+ - bin/console
146
+ - bin/normalize
147
+ - bin/setup
148
+ - books/chemistry2e/bake.rb
149
+ - codecov.yaml
150
+ - docker-compose.yml
151
+ - docker/bash
152
+ - docker/entrypoint
153
+ - lib/kitchen.rb
154
+ - lib/kitchen/ancestor.rb
155
+ - lib/kitchen/book_document.rb
156
+ - lib/kitchen/book_element.rb
157
+ - lib/kitchen/book_element_enumerator.rb
158
+ - lib/kitchen/book_recipe.rb
159
+ - lib/kitchen/chapter_element.rb
160
+ - lib/kitchen/chapter_element_enumerator.rb
161
+ - lib/kitchen/clipboard.rb
162
+ - lib/kitchen/composite_chapter_element.rb
163
+ - lib/kitchen/composite_page_element.rb
164
+ - lib/kitchen/composite_page_element_enumerator.rb
165
+ - lib/kitchen/config.rb
166
+ - lib/kitchen/counter.rb
167
+ - lib/kitchen/debug/print_recipe_error.rb
168
+ - lib/kitchen/directions/bake_appendix.rb
169
+ - lib/kitchen/directions/bake_chapter_glossary.rb
170
+ - lib/kitchen/directions/bake_chapter_introductions.rb
171
+ - lib/kitchen/directions/bake_chapter_key_equations.rb
172
+ - lib/kitchen/directions/bake_chapter_summary.rb
173
+ - lib/kitchen/directions/bake_composite_pages.rb
174
+ - lib/kitchen/directions/bake_example.rb
175
+ - lib/kitchen/directions/bake_exercises.rb
176
+ - lib/kitchen/directions/bake_figure.rb
177
+ - lib/kitchen/directions/bake_footnotes/main.rb
178
+ - lib/kitchen/directions/bake_footnotes/v1.rb
179
+ - lib/kitchen/directions/bake_index/main.rb
180
+ - lib/kitchen/directions/bake_index/v1.rb
181
+ - lib/kitchen/directions/bake_index/v1.xhtml.erb
182
+ - lib/kitchen/directions/bake_math_in_paragraph.rb
183
+ - lib/kitchen/directions/bake_notes.rb
184
+ - lib/kitchen/directions/bake_numbered_table/main.rb
185
+ - lib/kitchen/directions/bake_numbered_table/v1.rb
186
+ - lib/kitchen/directions/bake_stepwise.rb
187
+ - lib/kitchen/directions/bake_toc.rb
188
+ - lib/kitchen/directions/bake_unnumbered_tables.rb
189
+ - lib/kitchen/directions/move_title_text_into_span.rb
190
+ - lib/kitchen/document.rb
191
+ - lib/kitchen/element.rb
192
+ - lib/kitchen/element_base.rb
193
+ - lib/kitchen/element_enumerator.rb
194
+ - lib/kitchen/element_enumerator_base.rb
195
+ - lib/kitchen/element_enumerator_factory.rb
196
+ - lib/kitchen/element_factory.rb
197
+ - lib/kitchen/errors.rb
198
+ - lib/kitchen/example_element.rb
199
+ - lib/kitchen/example_element_enumerator.rb
200
+ - lib/kitchen/figure_element.rb
201
+ - lib/kitchen/figure_element_enumerator.rb
202
+ - lib/kitchen/mixins/block_error_if.rb
203
+ - lib/kitchen/note_element.rb
204
+ - lib/kitchen/note_element_enumerator.rb
205
+ - lib/kitchen/oven.rb
206
+ - lib/kitchen/page_element.rb
207
+ - lib/kitchen/page_element_enumerator.rb
208
+ - lib/kitchen/pantry.rb
209
+ - lib/kitchen/patches/nokogiri.rb
210
+ - lib/kitchen/patches/renderable.rb
211
+ - lib/kitchen/patches/string.rb
212
+ - lib/kitchen/recipe.rb
213
+ - lib/kitchen/search_history.rb
214
+ - lib/kitchen/selectors/base.rb
215
+ - lib/kitchen/selectors/standard_1.rb
216
+ - lib/kitchen/table_element.rb
217
+ - lib/kitchen/table_element_enumerator.rb
218
+ - lib/kitchen/term_element.rb
219
+ - lib/kitchen/term_element_enumerator.rb
220
+ - lib/kitchen/transliterations.rb
221
+ - lib/kitchen/type_casting_element_enumerator.rb
222
+ - lib/kitchen/utils.rb
223
+ - lib/kitchen/version.rb
224
+ - lib/locales/en.yml
225
+ - lib/notes.md
226
+ - openstax_kitchen.gemspec
227
+ - tutorials/00/expected_baked.html
228
+ - tutorials/00/raw.html
229
+ - tutorials/00/solution_1.rb
230
+ - tutorials/00/solution_2.rb
231
+ - tutorials/01/expected_baked.html
232
+ - tutorials/01/raw.html
233
+ - tutorials/01/solution_1.rb
234
+ - tutorials/01/solution_2.rb
235
+ - tutorials/02/expected_baked.html
236
+ - tutorials/02/raw.html
237
+ - tutorials/02/solution_1.rb
238
+ - tutorials/03/expected_baked.html
239
+ - tutorials/03/raw.html
240
+ - tutorials/03/solution_1.rb
241
+ - tutorials/03/solution_2.rb
242
+ - tutorials/04/expected_baked.html
243
+ - tutorials/04/raw.html
244
+ - tutorials/04/solution_1.rb
245
+ - tutorials/04/solution_2.rb
246
+ - tutorials/05/expected_baked.html
247
+ - tutorials/05/raw.html
248
+ - tutorials/05/solution_1.rb
249
+ - tutorials/check_it
250
+ - tutorials/setup_my_recipes
251
+ homepage: https://github.com/openstax/kitchen
252
+ licenses:
253
+ - MIT
254
+ metadata:
255
+ allowed_push_host: https://rubygems.org
256
+ homepage_uri: https://github.com/openstax/kitchen
257
+ source_code_uri: https://github.com/openstax/kitchen
258
+ changelog_uri: https://github.com/openstax/kitchen/CHANGELOG.md
259
+ post_install_message:
260
+ rdoc_options: []
261
+ require_paths:
262
+ - lib
263
+ required_ruby_version: !ruby/object:Gem::Requirement
264
+ requirements:
265
+ - - ">="
266
+ - !ruby/object:Gem::Version
267
+ version: 2.3.0
268
+ required_rubygems_version: !ruby/object:Gem::Requirement
269
+ requirements:
270
+ - - ">="
271
+ - !ruby/object:Gem::Version
272
+ version: '0'
273
+ requirements: []
274
+ rubygems_version: 3.0.3
275
+ signing_key:
276
+ specification_version: 4
277
+ summary: OpenStax content baking library
278
+ test_files: []