openstax_kitchen 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.devcontainer/devcontainer.json +37 -17
- data/.github/config.yml +14 -0
- data/.github/workflows/tests.yml +5 -15
- data/.gitignore +1 -1
- data/.inch.yml +6 -0
- data/.rubocop.yml +65 -0
- data/CHANGELOG.md +16 -0
- data/Gemfile +5 -3
- data/Gemfile.lock +54 -5
- data/README.md +58 -11
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/docker/Dockerfile +36 -0
- data/docker/Dockerfile.ci +10 -0
- data/docker/bash +5 -1
- data/docker/build +10 -0
- data/docker/ci +16 -0
- data/docker/run +9 -0
- data/docker/tag_and_push_latest +17 -0
- data/lefthook.yml +6 -0
- data/lib/kitchen/ancestor.rb +38 -1
- data/lib/kitchen/book_document.rb +20 -2
- data/lib/kitchen/book_element.rb +24 -3
- data/lib/kitchen/book_element_enumerator.rb +4 -0
- data/lib/kitchen/book_recipe.rb +15 -1
- data/lib/kitchen/chapter_element.rb +43 -3
- data/lib/kitchen/chapter_element_enumerator.rb +9 -1
- data/lib/kitchen/clipboard.rb +35 -4
- data/lib/kitchen/composite_chapter_element.rb +20 -1
- data/lib/kitchen/composite_page_element.rb +25 -2
- data/lib/kitchen/composite_page_element_enumerator.rb +8 -0
- data/lib/kitchen/config.rb +14 -7
- data/lib/kitchen/counter.rb +9 -2
- data/lib/kitchen/debug/print_recipe_error.rb +53 -35
- data/lib/kitchen/directions/.rubocop.yml +22 -0
- data/lib/kitchen/directions/bake_appendix.rb +4 -4
- data/lib/kitchen/directions/bake_chapter_glossary.rb +10 -7
- data/lib/kitchen/directions/bake_chapter_introductions.rb +6 -6
- data/lib/kitchen/directions/bake_chapter_key_equations.rb +9 -6
- data/lib/kitchen/directions/bake_chapter_summary.rb +16 -13
- data/lib/kitchen/directions/bake_chapter_title/main.rb +11 -0
- data/lib/kitchen/directions/bake_chapter_title/v1.rb +24 -0
- data/lib/kitchen/directions/bake_composite_pages.rb +2 -2
- data/lib/kitchen/directions/bake_example.rb +6 -4
- data/lib/kitchen/directions/bake_exercises/main.rb +11 -0
- data/lib/kitchen/directions/bake_exercises/v1.rb +166 -0
- data/lib/kitchen/directions/bake_figure.rb +8 -5
- data/lib/kitchen/directions/bake_footnotes/main.rb +2 -2
- data/lib/kitchen/directions/bake_footnotes/v1.rb +4 -4
- data/lib/kitchen/directions/bake_index/main.rb +2 -2
- data/lib/kitchen/directions/bake_index/v1.rb +22 -15
- data/lib/kitchen/directions/bake_link_placeholders.rb +24 -0
- data/lib/kitchen/directions/bake_math_in_paragraph.rb +5 -3
- data/lib/kitchen/directions/bake_notes.rb +8 -8
- data/lib/kitchen/directions/bake_numbered_table/main.rb +2 -2
- data/lib/kitchen/directions/bake_numbered_table/v1.rb +21 -16
- data/lib/kitchen/directions/bake_page_abstracts.rb +14 -0
- data/lib/kitchen/directions/bake_preface/main.rb +11 -0
- data/lib/kitchen/directions/bake_preface/v1.rb +18 -0
- data/lib/kitchen/directions/bake_stepwise.rb +7 -7
- data/lib/kitchen/directions/bake_suggested_reading.rb +26 -0
- data/lib/kitchen/directions/bake_toc.rb +41 -22
- data/lib/kitchen/directions/bake_unit_title/main.rb +11 -0
- data/lib/kitchen/directions/bake_unit_title/v1.rb +23 -0
- data/lib/kitchen/directions/bake_unnumbered_tables.rb +7 -5
- data/lib/kitchen/directions/move_title_text_into_span.rb +2 -2
- data/lib/kitchen/document.rb +72 -13
- data/lib/kitchen/element.rb +11 -0
- data/lib/kitchen/element_base.rb +276 -56
- data/lib/kitchen/element_enumerator.rb +8 -0
- data/lib/kitchen/element_enumerator_base.rb +210 -28
- data/lib/kitchen/element_enumerator_factory.rb +59 -52
- data/lib/kitchen/element_factory.rb +27 -12
- data/lib/kitchen/errors.rb +5 -0
- data/lib/kitchen/example_element.rb +19 -1
- data/lib/kitchen/example_element_enumerator.rb +9 -1
- data/lib/kitchen/figure_element.rb +36 -2
- data/lib/kitchen/figure_element_enumerator.rb +9 -1
- data/lib/kitchen/metadata_element.rb +28 -0
- data/lib/kitchen/metadata_element_enumerator.rb +21 -0
- data/lib/kitchen/mixins/block_error_if.rb +24 -4
- data/lib/kitchen/note_element.rb +37 -7
- data/lib/kitchen/note_element_enumerator.rb +9 -1
- data/lib/kitchen/oven.rb +66 -15
- data/lib/kitchen/page_element.rb +62 -13
- data/lib/kitchen/page_element_enumerator.rb +9 -1
- data/lib/kitchen/pantry.rb +28 -1
- data/lib/kitchen/patches/nokogiri.rb +19 -2
- data/lib/kitchen/patches/renderable.rb +9 -3
- data/lib/kitchen/patches/string.rb +8 -0
- data/lib/kitchen/recipe.rb +38 -34
- data/lib/kitchen/search_history.rb +43 -4
- data/lib/kitchen/search_query.rb +84 -0
- data/lib/kitchen/selectors/base.rb +26 -0
- data/lib/kitchen/selectors/standard_1.rb +8 -0
- data/lib/kitchen/table_element.rb +54 -3
- data/lib/kitchen/table_element_enumerator.rb +9 -1
- data/lib/kitchen/term_element.rb +15 -1
- data/lib/kitchen/term_element_enumerator.rb +9 -1
- data/lib/kitchen/transliterations.rb +7 -5
- data/lib/kitchen/type_casting_element_enumerator.rb +17 -1
- data/lib/kitchen/unit_element.rb +39 -0
- data/lib/kitchen/unit_element_enumerator.rb +20 -0
- data/lib/kitchen/utils.rb +10 -13
- data/lib/kitchen/version.rb +5 -1
- data/lib/locales/en.yml +6 -0
- data/lib/openstax_kitchen.rb +43 -42
- data/openstax_kitchen.gemspec +26 -20
- data/tutorials/00/solution1.rb +9 -0
- data/tutorials/00/solution2.rb +8 -0
- data/tutorials/01/solution1.rb +18 -0
- data/tutorials/01/solution2.rb +26 -0
- data/tutorials/02/solution1.rb +31 -0
- data/tutorials/03/{solution_1.rb → solution1.rb} +6 -4
- data/tutorials/03/solution2.rb +18 -0
- data/tutorials/04/{solution_1.rb → solution1.rb} +4 -2
- data/tutorials/04/{solution_2.rb → solution2.rb} +6 -4
- data/tutorials/05/solution1.rb +11 -0
- data/tutorials/check_it +16 -15
- data/tutorials/setup_my_recipes +7 -6
- metadata +101 -22
- data/Dockerfile +0 -19
- data/docker-compose.yml +0 -12
- data/docker/entrypoint +0 -9
- data/lib/kitchen/directions/bake_exercises.rb +0 -164
- data/tutorials/00/solution_1.rb +0 -7
- data/tutorials/00/solution_2.rb +0 -6
- data/tutorials/01/solution_1.rb +0 -16
- data/tutorials/01/solution_2.rb +0 -24
- data/tutorials/02/solution_1.rb +0 -29
- data/tutorials/03/solution_2.rb +0 -15
- data/tutorials/05/solution_1.rb +0 -9
data/lib/kitchen/version.rb
CHANGED
data/lib/locales/en.yml
CHANGED
@@ -2,14 +2,20 @@ en:
|
|
2
2
|
figure: Figure
|
3
3
|
table_label: Table
|
4
4
|
appendix: Appendix
|
5
|
+
chapter_outline: Chapter Outline
|
6
|
+
toc_title: Contents
|
5
7
|
example_label: Example
|
6
8
|
exercise_label: Exercise
|
9
|
+
chapter: Chapter
|
10
|
+
unit: Unit
|
11
|
+
learning_objectives: Learning Objectives
|
7
12
|
stepwise_step_label: Step
|
8
13
|
eoc_key_terms_title: Key Terms
|
9
14
|
eoc_summary_title: Summary
|
10
15
|
eoc_exercises_title: Exercises
|
11
16
|
eoc_answer_key_title: Answer Key
|
12
17
|
eoc_key_equations: Key Equations
|
18
|
+
eoc_suggested_reading: Suggestions for Further Study
|
13
19
|
eob_index_title: Index
|
14
20
|
eob_index_symbols_group: Symbols
|
15
21
|
notes:
|
data/lib/openstax_kitchen.rb
CHANGED
@@ -1,57 +1,58 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require 'kitchen/version'
|
4
|
+
|
5
|
+
require 'nokogiri'
|
6
|
+
require 'active_support/all'
|
5
7
|
|
6
8
|
module Kitchen
|
9
|
+
# Contains snippets of recipes that accomplish a certain medium-sized task
|
7
10
|
module Directions; end
|
8
11
|
end
|
9
12
|
|
10
13
|
def file_glob(relative_folder_and_extension)
|
11
|
-
Dir[File.expand_path(__dir__
|
14
|
+
Dir[File.expand_path("#{__dir__}/#{relative_folder_and_extension}")]
|
12
15
|
end
|
13
16
|
|
14
|
-
def require_all(relative_folder, file_matcher=
|
15
|
-
file_glob(relative_folder + "/#{file_matcher}").each{|f| require f}
|
17
|
+
def require_all(relative_folder, file_matcher='**/*.rb')
|
18
|
+
file_glob(relative_folder + "/#{file_matcher}").each { |f| require f }
|
16
19
|
end
|
17
20
|
|
18
|
-
require_all(
|
19
|
-
require_all(
|
20
|
-
|
21
|
-
require
|
22
|
-
require_all(
|
23
|
-
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
29
|
-
require
|
30
|
-
require
|
31
|
-
require
|
32
|
-
require
|
33
|
-
require
|
34
|
-
require
|
35
|
-
require
|
36
|
-
require
|
37
|
-
require
|
38
|
-
require
|
39
|
-
|
40
|
-
|
41
|
-
require
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
require_all(
|
50
|
-
|
51
|
-
I18n.load_path << file_glob(
|
52
|
-
|
21
|
+
require_all('kitchen/patches')
|
22
|
+
require_all('kitchen/mixins')
|
23
|
+
|
24
|
+
require 'kitchen/selectors/base'
|
25
|
+
require_all('kitchen/selectors')
|
26
|
+
|
27
|
+
require 'kitchen/utils'
|
28
|
+
require 'kitchen/transliterations'
|
29
|
+
require 'kitchen/errors'
|
30
|
+
require 'kitchen/ancestor'
|
31
|
+
require 'kitchen/search_query'
|
32
|
+
require 'kitchen/search_history'
|
33
|
+
require 'kitchen/config'
|
34
|
+
require 'kitchen/document'
|
35
|
+
require 'kitchen/book_document'
|
36
|
+
require 'kitchen/debug/print_recipe_error'
|
37
|
+
require 'kitchen/recipe'
|
38
|
+
require 'kitchen/book_recipe'
|
39
|
+
require 'kitchen/oven'
|
40
|
+
require 'kitchen/clipboard'
|
41
|
+
require 'kitchen/pantry'
|
42
|
+
require 'kitchen/counter'
|
43
|
+
|
44
|
+
require 'kitchen/element_enumerator_base'
|
45
|
+
require 'kitchen/element_enumerator_factory'
|
46
|
+
require_all('kitchen', '*enumerator.rb')
|
47
|
+
|
48
|
+
require 'kitchen/element_base'
|
49
|
+
require_all('kitchen', '*element.rb')
|
50
|
+
require 'kitchen/element_factory'
|
51
|
+
|
52
|
+
require_all('kitchen/directions')
|
53
|
+
|
54
|
+
I18n.load_path << file_glob('/locales/*.yml')
|
53
55
|
|
54
56
|
I18n.available_locales.each do |available_locale|
|
55
57
|
I18n.backend.store_translations(available_locale, Kitchen::TRANSLITERATIONS)
|
56
58
|
end
|
57
|
-
|
data/openstax_kitchen.gemspec
CHANGED
@@ -1,39 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'lib/kitchen/version'
|
2
4
|
|
3
5
|
Gem::Specification.new do |spec|
|
4
|
-
spec.name =
|
6
|
+
spec.name = 'openstax_kitchen'
|
5
7
|
spec.version = Kitchen::VERSION
|
6
|
-
spec.authors = [
|
7
|
-
spec.email = [
|
8
|
+
spec.authors = ['JP Slavinsky']
|
9
|
+
spec.email = ['jpslav@gmail.com']
|
8
10
|
|
9
|
-
spec.summary =
|
10
|
-
spec.description =
|
11
|
-
spec.homepage =
|
12
|
-
spec.license =
|
13
|
-
spec.required_ruby_version = Gem::Requirement.new(
|
11
|
+
spec.summary = 'OpenStax content baking library'
|
12
|
+
spec.description = 'OpenStax content baking library'
|
13
|
+
spec.homepage = 'https://github.com/openstax/kitchen'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
|
14
16
|
|
15
|
-
spec.metadata[
|
17
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
16
18
|
|
17
|
-
spec.metadata[
|
18
|
-
spec.metadata[
|
19
|
-
spec.metadata[
|
19
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
20
|
+
spec.metadata['source_code_uri'] = 'https://github.com/openstax/kitchen'
|
21
|
+
spec.metadata['changelog_uri'] = 'https://github.com/openstax/kitchen/CHANGELOG.md'
|
20
22
|
|
21
23
|
# Specify which files should be added to the gem when it is released.
|
22
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
-
spec.files
|
24
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(/^(test|spec|features)\//) }
|
25
27
|
end
|
26
|
-
spec.bindir =
|
27
|
-
spec.executables = spec.files.grep(
|
28
|
-
spec.require_paths = [
|
28
|
+
spec.bindir = 'exe'
|
29
|
+
spec.executables = spec.files.grep(/^exe\//) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ['lib']
|
29
31
|
|
30
|
-
spec.add_dependency 'nokogiri'
|
31
|
-
spec.add_dependency 'rainbow'
|
32
32
|
spec.add_dependency 'activesupport'
|
33
33
|
spec.add_dependency 'i18n'
|
34
|
+
spec.add_dependency 'nokogiri'
|
35
|
+
spec.add_dependency 'rainbow'
|
34
36
|
|
35
37
|
spec.add_development_dependency 'byebug'
|
36
|
-
spec.add_development_dependency '
|
38
|
+
spec.add_development_dependency 'inch'
|
37
39
|
spec.add_development_dependency 'nokogiri-diff'
|
38
40
|
spec.add_development_dependency 'rainbow'
|
41
|
+
spec.add_development_dependency 'rubocop'
|
42
|
+
spec.add_development_dependency 'rubocop-rake'
|
43
|
+
spec.add_development_dependency 'rubocop-rspec'
|
44
|
+
spec.add_development_dependency 'yard'
|
39
45
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
@solution1 = Kitchen::Recipe.new do |doc|
|
4
|
+
|
5
|
+
doc.search("[data-type='chapter']").each do |chapter|
|
6
|
+
movers = chapter.search('.will-move').cut
|
7
|
+
movers.each { |mover| mover.name = 'section' }
|
8
|
+
|
9
|
+
chapter.append(child: <<~HTML
|
10
|
+
<div class="eoc">
|
11
|
+
<div class="os-title">End of Chapter Collations</div>
|
12
|
+
#{movers.paste}
|
13
|
+
</div>
|
14
|
+
HTML
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
@solution2 = Kitchen::BookRecipe.new do |doc|
|
4
|
+
|
5
|
+
# ^
|
6
|
+
# |
|
7
|
+
#
|
8
|
+
# BookRecipe gives us `doc.book` and `book.chapters` to make the code cleaner
|
9
|
+
#
|
10
|
+
# | |
|
11
|
+
# v v
|
12
|
+
|
13
|
+
doc.book.chapters.each do |chapter|
|
14
|
+
movers = chapter.search('.will-move').cut
|
15
|
+
movers.each { |mover| mover.name = 'section' }
|
16
|
+
|
17
|
+
chapter.append(child: <<~HTML
|
18
|
+
<div class="eoc">
|
19
|
+
<div class="os-title">End of Chapter Collations</div>
|
20
|
+
#{movers.paste}
|
21
|
+
</div>
|
22
|
+
HTML
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
@solution1 = Kitchen::Recipe.new do |doc|
|
4
|
+
|
5
|
+
doc.search("[data-type='chapter']").each do |chapter|
|
6
|
+
review_questions = chapter.search('.review-questions').cut
|
7
|
+
critical_thinking = chapter.search('.critical-thinking').cut
|
8
|
+
|
9
|
+
[review_questions, critical_thinking].each do |clipboard|
|
10
|
+
clipboard.each do |element|
|
11
|
+
element.first('h3').trash
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
chapter.append(child: <<~HTML
|
16
|
+
<div class="eoc">
|
17
|
+
<h2 data-type="document-title">End of Chapter Stuff</h2>
|
18
|
+
<div class="critical-thinking-container">
|
19
|
+
<div class="os-title">Critical Thinking Questions</div>
|
20
|
+
#{critical_thinking.paste}
|
21
|
+
</div>
|
22
|
+
<div class="review-questions-container">
|
23
|
+
<div class="os-title">Review Questions</div>
|
24
|
+
#{review_questions.paste}
|
25
|
+
</div>
|
26
|
+
</div>
|
27
|
+
HTML
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -1,15 +1,17 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
@solution1 = Kitchen::BookRecipe.new do |doc|
|
2
4
|
book = doc.book
|
3
5
|
|
4
6
|
book.chapters.each do |chapter|
|
5
7
|
chapter.prepend(child: <<~HTML
|
6
|
-
|
7
|
-
|
8
|
+
<h1 data-type="document-title">Chapter #{chapter.count_in(:book)}</h1>
|
9
|
+
HTML
|
8
10
|
)
|
9
11
|
|
10
12
|
chapter.pages.each do |page|
|
11
13
|
page_title = page.title
|
12
|
-
page_title.name =
|
14
|
+
page_title.name = 'h2'
|
13
15
|
page_title.prepend(child: "#{chapter.count_in(:book)}.#{page.count_in(:chapter)} ")
|
14
16
|
end
|
15
17
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
@solution2 = Kitchen::BookRecipe.new do |doc|
|
4
|
+
book = doc.book
|
5
|
+
|
6
|
+
book.chapters.each do |chapter|
|
7
|
+
chapter.prepend(child: <<~HTML
|
8
|
+
<h1 data-type="document-title">Chapter #{chapter.count_in(:book)}</h1>
|
9
|
+
HTML
|
10
|
+
)
|
11
|
+
|
12
|
+
chapter.pages.each do |page|
|
13
|
+
page.title
|
14
|
+
.set(:name, 'h2')
|
15
|
+
.prepend(child: "#{chapter.count_in(:book)}.#{page.count_in(:chapter)} ")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
@solution1 = Kitchen::BookRecipe.new do |doc|
|
2
4
|
book = doc.book
|
3
5
|
|
4
6
|
book.tables.each do |table|
|
@@ -13,7 +15,7 @@
|
|
13
15
|
doc.pantry(name: :link_text).store figure_name, label: figure.id
|
14
16
|
end
|
15
17
|
|
16
|
-
book.search(
|
18
|
+
book.search('a.needs-label').each do |anchor|
|
17
19
|
id = anchor[:href][1..-1]
|
18
20
|
anchor.replace_children(with: doc.pantry(name: :link_text).get(id))
|
19
21
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
@solution2 = Kitchen::BookRecipe.new do |doc|
|
2
4
|
book = doc.book
|
3
5
|
|
4
6
|
# Solution 1 treats figures and tables almost identically and ends up duplicating
|
@@ -6,8 +8,8 @@
|
|
6
8
|
# enumerator and the label):
|
7
9
|
|
8
10
|
enumerators_to_labels_map = {
|
9
|
-
book.tables =>
|
10
|
-
book.figures =>
|
11
|
+
book.tables => 'Table',
|
12
|
+
book.figures => 'Figure'
|
11
13
|
}
|
12
14
|
|
13
15
|
enumerators_to_labels_map.each do |enumerator, label|
|
@@ -18,7 +20,7 @@
|
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
|
-
book.search(
|
23
|
+
book.search('a.needs-label').each do |anchor|
|
22
24
|
id = anchor[:href][1..-1]
|
23
25
|
anchor.replace_children(with: doc.pantry(name: :link_text).get(id))
|
24
26
|
end
|
data/tutorials/check_it
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'openstax_kitchen'
|
6
|
+
require 'rspec'
|
7
|
+
require 'byebug'
|
8
|
+
require 'rainbow'
|
8
9
|
|
9
10
|
def parse_doc(filename)
|
10
|
-
Nokogiri::XML(File.open(filename)){|config| config.noblanks}
|
11
|
+
Nokogiri::XML(File.open(filename)) { |config| config.noblanks }
|
11
12
|
end
|
12
13
|
|
13
14
|
def parse_doc_and_prep_for_diff(filename)
|
14
15
|
doc = parse_doc(filename)
|
15
16
|
string = doc.to_xhtml
|
16
17
|
# Get rid of whitespace at the start of lines (remove impact of indentation)
|
17
|
-
string.gsub(/^\s*/,
|
18
|
+
string.gsub(/^\s*/, '')
|
18
19
|
end
|
19
20
|
|
20
21
|
if ARGV.empty?
|
@@ -25,12 +26,12 @@ end
|
|
25
26
|
|
26
27
|
tutorial_number = ARGV[0]
|
27
28
|
|
28
|
-
Dir[File.expand_path(__dir__ + "/#{tutorial_number}/*.rb")].each{|f| require f}
|
29
|
+
Dir[File.expand_path(__dir__ + "/#{tutorial_number}/*.rb")].sort.each { |f| require f }
|
29
30
|
|
30
|
-
recipe_name = (ARGV[1] ||
|
31
|
+
recipe_name = (ARGV[1] || 'my_recipe')
|
31
32
|
recipe_variable_name = "@#{recipe_name}".to_sym
|
32
33
|
|
33
|
-
|
34
|
+
unless instance_variables.include?(recipe_variable_name)
|
34
35
|
puts Rainbow("There is no recipe named '#{recipe_variable_name}' defined in the " \
|
35
36
|
"tutorials/#{tutorial_number} directory").red
|
36
37
|
exit(1)
|
@@ -51,14 +52,14 @@ differ = RSpec::Support::Differ.new(color: true)
|
|
51
52
|
diff = differ.diff(expected, actual)
|
52
53
|
|
53
54
|
# Get rid of some coloring junk at the start
|
54
|
-
diff.sub!(/\e\[0m\n\e\[0m/,
|
55
|
+
diff.sub!(/\e\[0m\n\e\[0m/, '')
|
55
56
|
|
56
57
|
if diff.blank?
|
57
|
-
puts Rainbow(
|
58
|
+
puts Rainbow('The actual output matches the expected output! Way to go!').green
|
58
59
|
else
|
59
|
-
puts Rainbow(
|
60
|
-
puts Rainbow(
|
61
|
-
puts Rainbow(
|
60
|
+
puts Rainbow('The actual output does not match the expected output.').yellow
|
61
|
+
puts "#{Rainbow('-').red} = actual output"
|
62
|
+
puts "#{Rainbow('+').green} = expected output"
|
62
63
|
puts "\n"
|
63
64
|
puts diff
|
64
65
|
end
|