playgroundbook 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +80 -6
  3. data/lib/renderer/chapter_collator.rb +3 -2
  4. data/lib/renderer/contents_manifest_generator.rb +1 -1
  5. data/lib/renderer/page_writer.rb +3 -3
  6. data/lib/renderer/playgroundbook_renderer.rb +1 -1
  7. data/lib/version.rb +1 -1
  8. data/lib/wrapper/markdown_wrapper.rb +31 -3
  9. metadata +3 -45
  10. data/.gitignore +0 -50
  11. data/.rspec +0 -2
  12. data/.rubocop.yml +0 -112
  13. data/.ruby-version +0 -1
  14. data/Changelog.md +0 -30
  15. data/Gemfile +0 -13
  16. data/Gemfile.lock +0 -105
  17. data/Guardfile +0 -14
  18. data/Rakefile +0 -8
  19. data/playground_book_lint.gemspec +0 -21
  20. data/spec/fixtures/Starter.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Manifest.plist +0 -15
  21. data/spec/fixtures/Starter.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Pages/Page1.playgroundpage/Contents.swift +0 -8
  22. data/spec/fixtures/Starter.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Pages/Page1.playgroundpage/Manifest.plist +0 -12
  23. data/spec/fixtures/Starter.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Pages/Page2.playgroundpage/Contents.swift +0 -8
  24. data/spec/fixtures/Starter.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Pages/Page2.playgroundpage/Manifest.plist +0 -12
  25. data/spec/fixtures/Starter.playgroundbook/Contents/Manifest.plist +0 -20
  26. data/spec/fixtures/assets/file.jpeg +0 -0
  27. data/spec/fixtures/book.yml +0 -6
  28. data/spec/fixtures/test_chapter.playground/Contents.swift +0 -17
  29. data/spec/fixtures/test_chapter.playground/contents.xcplayground +0 -4
  30. data/spec/fixtures/wrapper/destination/swift_at_artsy_1.swift +0 -199
  31. data/spec/fixtures/wrapper/source/Swift-at-Artsy.playground/Contents.swift +0 -199
  32. data/spec/fixtures/wrapper/source/Swift-at-Artsy.playground/contents.xcplayground +0 -4
  33. data/spec/fixtures/wrapper/source/swift_at_artsy_1.md +0 -183
  34. data/spec/linter/chapter_linter_spec.rb +0 -30
  35. data/spec/linter/chapter_manifest_linter_spec.rb +0 -40
  36. data/spec/linter/contents_linter_spec.rb +0 -18
  37. data/spec/linter/cutscene_page_linter_spec.rb +0 -14
  38. data/spec/linter/cutscene_page_manifest_linter_spec.rb +0 -63
  39. data/spec/linter/manfiest_linter_spec.rb +0 -71
  40. data/spec/linter/page_linter_spec.rb +0 -19
  41. data/spec/linter/page_manifest_linter_spec.rb +0 -43
  42. data/spec/linter/playgroundbook_lint_spec.rb +0 -38
  43. data/spec/linter/root_manifest_linter_spec.rb +0 -35
  44. data/spec/renderer/chapter_collator_spec.rb +0 -70
  45. data/spec/renderer/contents_manfiest_generator_spec.rb +0 -41
  46. data/spec/renderer/glossary_generator_spec.rb +0 -54
  47. data/spec/renderer/page_processor_spec.rb +0 -86
  48. data/spec/renderer/page_writer_spec.rb +0 -70
  49. data/spec/renderer/playgroundbook_renderer_spec.rb +0 -122
  50. data/spec/spec_helper.rb +0 -84
  51. data/spec/wrapper/markdown_wrapper_spec.rb +0 -33
@@ -1,54 +0,0 @@
1
- require File.expand_path("../../spec_helper", __FILE__)
2
-
3
- module Playgroundbook
4
- describe GlossaryGenerator do
5
- include FakeFS::SpecHelpers
6
- let(:glossary_generator) { GlossaryGenerator.new }
7
- let(:glossary) do
8
- {
9
- "example term" => "example definition"
10
- }
11
- end
12
- let(:glossary_file_name) { "Contents/Resources/Glossary.plist" }
13
-
14
- before do
15
- FileUtils.mkdir_p("Contents/Resources")
16
- end
17
-
18
- it "generates a glossary plist" do
19
- glossary_generator.generate({}, [], glossary)
20
-
21
- expect(File.exist?(glossary_file_name)).to be_truthy
22
- end
23
-
24
- context "glossary plist" do
25
- let(:glossary_plist) { Plist.parse_xml(glossary_file_name) }
26
-
27
- it "has a glossary with correct terms" do
28
- glossary_generator.generate({}, [], glossary)
29
-
30
- expect(glossary_plist["Terms"]["example term"]["Definition"]).to eq("example definition")
31
- end
32
-
33
- it "generates correct first use page references" do
34
- glossary_generator.generate([
35
- {
36
- page_names: ["Page 1"],
37
- page_contents: ["/*: Here's how to use [a thing](glossary://example%20term) */"]
38
- },
39
- {
40
- page_names: ["Should not see this"],
41
- page_contents: ["/*: Here's how to use [a thing](glossary://example%20term) even though this shouldn't match' */"]
42
- }
43
- ],
44
- ["Chapter 1", "Chapter 2"],
45
- glossary)
46
-
47
- expect(glossary_plist["Terms"]["example term"]["FirstUse"]).to eq({
48
- "PageReference" => "Chapter%201/Page%201",
49
- "Title" => "Page 1"
50
- })
51
- end
52
- end
53
- end
54
- end
@@ -1,86 +0,0 @@
1
- require File.expand_path("../../spec_helper", __FILE__)
2
-
3
- module Playgroundbook
4
- describe PageProcessor do
5
- let(:page_processor) { PageProcessor.new }
6
-
7
- it "removes newlines before markdown blocks" do
8
- page_contents = <<-EOS
9
- let a = 6
10
-
11
- /*:
12
- Some markdown.
13
- */
14
- EOS
15
- processed_page_contents = <<-EOS
16
- let a = 6
17
- /*:
18
- Some markdown.
19
- */
20
- EOS
21
-
22
- expect(page_processor.strip_extraneous_newlines(page_contents)).to eq(processed_page_contents)
23
- end
24
-
25
- it "removes newlines after markdown blocks" do
26
- page_contents = <<-EOS
27
- /*:
28
- Some markdown.
29
- */
30
-
31
- let a = 6
32
- EOS
33
- processed_page_contents = <<-EOS
34
- /*:
35
- Some markdown.
36
- */
37
- let a = 6
38
- EOS
39
-
40
- expect(page_processor.strip_extraneous_newlines(page_contents)).to eq(processed_page_contents)
41
- end
42
-
43
- it "removes newlines surrounding single-line markdown blocks" do
44
- page_contents = <<-EOS
45
- let a = 6
46
-
47
- //: Some markdown.
48
-
49
- let b = a
50
- EOS
51
- processed_page_contents = <<-EOS
52
- let a = 6
53
- //: Some markdown.
54
- let b = a
55
- EOS
56
-
57
- expect(page_processor.strip_extraneous_newlines(page_contents)).to eq(processed_page_contents)
58
- end
59
-
60
- it "does not strip newlines from code" do
61
- page_contents = <<-EOS
62
- let a = 6
63
-
64
- let b = a
65
- EOS
66
-
67
- expect(page_processor.strip_extraneous_newlines(page_contents)).to eq(page_contents)
68
- end
69
-
70
- it "it does not strip newlines from the markdown" do
71
- page_contents = <<-EOS
72
- /*:
73
-
74
- # Header
75
-
76
- Some markdown. The following lines are purposefull left blank.
77
-
78
-
79
-
80
- */
81
- EOS
82
-
83
- expect(page_processor.strip_extraneous_newlines(page_contents)).to eq(page_contents)
84
- end
85
- end
86
- end
@@ -1,70 +0,0 @@
1
- require File.expand_path("../../spec_helper", __FILE__)
2
-
3
- module Playgroundbook
4
- describe PageWriter do
5
- include FakeFS::SpecHelpers
6
- let(:page_writer) { PageWriter.new(page_processor, test_ui) }
7
- let(:page_processor) { double(PageProcessor) }
8
- let(:test_ui) { Cork::Board.new(silent: true) }
9
- let(:page_name) { "test page name" }
10
- let(:page_dir_name) { "test page name.playgroundpage" }
11
- let(:page_contents) { "// Some swift goes here." }
12
- let(:generated_page_contesnts) { "//#-hidden-code\nimport UIKit\n//#-end-hidden-code\n// Some swift goes here." }
13
-
14
- before do
15
- allow(page_processor).to receive(:strip_extraneous_newlines) do |page_contents|
16
- # Returns the parameter, unprocessed.
17
- page_contents
18
- end
19
- end
20
-
21
- context "with a pre-existing page directory" do
22
- before do
23
- Dir.mkdir(page_dir_name)
24
- end
25
-
26
- it "does not explode" do
27
- expect { page_writer.write_page(page_name, page_dir_name, ["UIKit"], page_contents) }.to_not raise_error
28
- end
29
- end
30
-
31
- it "calls the page processor" do
32
- expect(page_processor).to receive(:strip_extraneous_newlines)
33
- page_writer.write_page(page_name, page_dir_name, ["UIKit"], page_contents)
34
- end
35
-
36
- context "as a consequence of writing rendering" do
37
- before do
38
- page_writer.write_page(page_name, page_dir_name, ["UIKit"], page_contents)
39
- end
40
-
41
- it "creates a directory" do
42
- expect(Dir.exist?(page_dir_name)).to be_truthy
43
- end
44
-
45
- it "writes a manifest" do
46
- expect(Dir.exist?(page_dir_name)).to be_truthy
47
- end
48
-
49
- it "writes a Contents.swift file" do
50
- expect(File.exist?("#{page_dir_name}/Contents.swift")).to be_truthy
51
- end
52
-
53
- it "has correct Contents.swift contents" do
54
- expect(File.read("#{page_dir_name}/Contents.swift")).to eq(generated_page_contesnts)
55
- end
56
-
57
- context "the manifest" do
58
- let(:manifest) { get_manifest("#{page_dir_name}/#{MANIFEST_FILE_NAME}") }
59
-
60
- it "has a name" do
61
- expect(manifest["Name"]).to eq(page_name)
62
- end
63
-
64
- it "has a LiveViewMode" do
65
- expect(manifest["LiveViewMode"]).to eq("HiddenByDefault")
66
- end
67
- end
68
- end
69
- end
70
- end
@@ -1,122 +0,0 @@
1
- require File.expand_path("../../spec_helper", __FILE__)
2
-
3
- module Playgroundbook
4
- describe Renderer do
5
- include FakeFS::SpecHelpers
6
- let(:renderer) { Renderer.new(yaml_file_name, contents_manifest_generator, page_parser, chapter_collator, glossary_generator, test_ui) }
7
- let(:yaml_file_name) { "book.yml" }
8
- let(:contents_manifest_generator) { double(ContentsManifestGenerator) }
9
- let(:page_parser) { double(PageParser) }
10
- let(:chapter_collator) { double(ChapterCollator) }
11
- let(:glossary_generator) { double(GlossaryGenerator) }
12
- let(:test_ui) { Cork::Board.new(silent: true) }
13
-
14
- before do
15
- File.open(yaml_file_name, "w") do |file|
16
- file.write(test_book_metadata.to_yaml)
17
- end
18
-
19
- allow(contents_manifest_generator).to receive(:generate)
20
- allow(chapter_collator).to receive(:collate)
21
- allow(glossary_generator).to receive(:generate)
22
- end
23
-
24
- it "initializes correctly" do
25
- expect(renderer.yaml_file_name) == yaml_file_name
26
- end
27
-
28
- it "explodes when there is no playground" do
29
- expect { renderer.render }.to raise_error
30
- end
31
-
32
- context "with a playground" do
33
- before do
34
- allow(page_parser).to receive(:parse_chapter_pages)
35
- Dir.mkdir("assets")
36
- FileUtils.touch("assets/file.png")
37
- Dir.mkdir("test_chapter.playground/")
38
- File.open("test_chapter.playground/Contents.swift", "w") do |file|
39
- file.write("")
40
- end
41
- end
42
-
43
- it "creates a directory with book name" do
44
- renderer.render
45
-
46
- expect(Dir.exist?("Testing Book.playgroundbook")).to be_truthy
47
- end
48
-
49
- it "creates a resources folder" do
50
- renderer.render
51
-
52
- expect(Dir.exist?("Testing Book.playgroundbook/Contents/Resources")).to be_truthy
53
- end
54
-
55
- it "copies a resources folder contents" do
56
- renderer.render
57
-
58
- expect(File.exist?("Testing Book.playgroundbook/Contents/Resources/file.png")).to be_truthy
59
- end
60
-
61
- context "within an existing playgroundbook directory" do
62
- before do
63
- Dir.mkdir("Testing Book.playgroundbook")
64
- end
65
-
66
- it "does not explode when the directory already exists" do
67
- expect { renderer.render }.to_not raise_error
68
- end
69
-
70
- it "creates a Contents directory within the main bundle dir" do
71
- renderer.render
72
-
73
- expect(Dir.exist?("Testing Book.playgroundbook/Contents")).to be_truthy
74
- end
75
-
76
- context "within the Contents directory" do
77
- before do
78
- Dir.mkdir("Testing Book.playgroundbook/Contents")
79
- end
80
-
81
- it "does not explode when the Contents directory already exists" do
82
- expect { renderer.render }.to_not raise_error
83
- end
84
-
85
- it "renders main manifest" do
86
- expect(contents_manifest_generator).to receive(:generate)
87
-
88
- renderer.render
89
- end
90
-
91
- it "creates a Chapters directory within the Contents dir" do
92
- renderer.render
93
-
94
- expect(Dir.exist?("Testing Book.playgroundbook/Contents/Chapters")).to be_truthy
95
- end
96
-
97
- context "within the Chapters directory" do
98
- before do
99
- Dir.mkdir("Testing Book.playgroundbook/Contents/Chapters")
100
- end
101
-
102
- it "does not explode when the Chapters directory already exists" do
103
- expect { renderer.render }.to_not raise_error
104
- end
105
-
106
- it "generates each chapter" do
107
- expect(chapter_collator).to receive(:collate)
108
-
109
- renderer.render
110
- end
111
- end
112
- end
113
- end
114
-
115
- it "generates a glossary" do
116
- expect(glossary_generator).to receive(:generate)
117
-
118
- renderer.render
119
- end
120
- end
121
- end
122
- end
data/spec/spec_helper.rb DELETED
@@ -1,84 +0,0 @@
1
- require "pathname"
2
- require "cork"
3
- require "rspec"
4
- require "plist"
5
- require "fileutils"
6
- require "fakefs/spec_helpers"
7
-
8
- ROOT = Pathname.new(File.expand_path("../../", __FILE__))
9
- $LOAD_PATH.unshift((ROOT + "lib").to_s)
10
- $LOAD_PATH.unshift((ROOT + "spec").to_s)
11
-
12
- require "playgroundbook"
13
- require "linter/abstract_linter"
14
- require "linter/chapter_linter"
15
- require "linter/chapter_manifest_linter"
16
- require "linter/contents_linter"
17
- require "linter/manifest_linter"
18
- require "linter/page_linter"
19
- require "linter/page_manifest_linter"
20
- require "linter/cutscene_page_linter"
21
- require "linter/cutscene_page_manifest_linter"
22
- require "linter/root_manifest_linter"
23
-
24
- require "renderer/contents_manifest_generator"
25
- require "renderer/chapter_collator"
26
- require "renderer/page_writer"
27
- require "renderer/page_parser"
28
- require "renderer/glossary_generator"
29
- require "renderer/page_processor"
30
-
31
- RSpec.configure do |config|
32
- config.color = true
33
-
34
- config.order = :random
35
- Kernel.srand config.seed
36
- end
37
- RSpec::Expectations.configuration.on_potential_false_positives = :nothing
38
-
39
- Playgroundbook::AbstractLinter.ui = Cork::Board.new(silent: true)
40
-
41
- def test_playground_book
42
- "spec/fixtures/Starter.playgroundbook"
43
- end
44
-
45
- def test_book_metadata
46
- {
47
- "name" => "Testing Book",
48
- "chapters" => ["test_chapter"],
49
- "identifier" => "com.ashfurrow.testing",
50
- "resources" => "assets",
51
- "cover" => "file.jpeg",
52
- "glossary" => [
53
- {
54
- "term" => "definition"
55
- }
56
- ]
57
- }
58
- end
59
-
60
- def get_manifest(file_name = Playgroundbook::ManifestFileName)
61
- Plist.parse_xml(file_name)
62
- end
63
-
64
- def test_chapter_contents
65
- <<-EOSwift
66
- import UIKit
67
-
68
- var str = "Hello, playground"
69
-
70
- func sharedFunc() {
71
- print("This should be accessible to all pages.")
72
- }
73
-
74
- //// Page 1
75
-
76
- str = "Yo, it's page 1."
77
- sharedFunc()
78
-
79
- //// Page 2
80
-
81
- str = "Page 2 awww yeah."
82
- sharedFunc()
83
- EOSwift
84
- end
@@ -1,33 +0,0 @@
1
- require File.expand_path("../../spec_helper", __FILE__)
2
-
3
- module Playgroundbook
4
- describe MarkdownWrapper do
5
- let(:test_ui) { Cork::Board.new(silent: true) }
6
-
7
- it "creates a swift file from a markdown file" do
8
- source = "spec/fixtures/wrapper/source/swift_at_artsy_1.md"
9
- destination = "spec/fixtures/wrapper/destination/swift_at_artsy_1.swift"
10
- subject = MarkdownWrapper.new(source, "Swift at Artsy")
11
- contents = File.read(source)
12
- expect(subject.swap_code_context(contents)).to eq(File.read(destination))
13
- end
14
-
15
- it "creates a playground around the file" do
16
- source = "spec/fixtures/wrapper/source/swift_at_artsy_1.md"
17
-
18
- Dir.mktmpdir do |dir|
19
- new_source = File.join(dir, File.basename(source))
20
- FileUtils.cp(source, new_source)
21
- subject = MarkdownWrapper.new(new_source, "Swift at Artsy")
22
-
23
- subject.generate
24
-
25
- playground = File.join(dir, "Swift at Artsy.playground")
26
- expect(Dir.exist?(playground)).to eq(true)
27
- expect(File.exist?(File.join(playground, "Contents.swift"))).to eq(true)
28
- expect(File.exist?(File.join(playground, "timeline.xctimeline"))).to eq(true)
29
- expect(File.exist?(File.join(playground, "contents.xcplayground"))).to eq(true)
30
- end
31
- end
32
- end
33
- end