playgroundbook 0.6.0 → 1.0.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 (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -45
  3. data/lib/renderer/chapter_collator.rb +24 -1
  4. data/lib/renderer/page_parser.rb +24 -2
  5. data/lib/renderer/page_writer.rb +20 -1
  6. data/lib/renderer/playgroundbook_renderer.rb +25 -5
  7. data/lib/version.rb +1 -1
  8. metadata +2 -46
  9. data/.gitignore +0 -50
  10. data/.rspec +0 -2
  11. data/.rubocop.yml +0 -112
  12. data/.ruby-version +0 -1
  13. data/Changelog.md +0 -37
  14. data/CodeOfConduct.md +0 -50
  15. data/Community.md +0 -52
  16. data/Gemfile +0 -13
  17. data/Gemfile.lock +0 -102
  18. data/Guardfile +0 -14
  19. data/Rakefile +0 -8
  20. data/playgroundbook.gemspec +0 -21
  21. data/spec/fixtures/Starter.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Manifest.plist +0 -15
  22. data/spec/fixtures/Starter.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Pages/Page1.playgroundpage/Contents.swift +0 -8
  23. data/spec/fixtures/Starter.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Pages/Page1.playgroundpage/Manifest.plist +0 -12
  24. data/spec/fixtures/Starter.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Pages/Page2.playgroundpage/Contents.swift +0 -8
  25. data/spec/fixtures/Starter.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Pages/Page2.playgroundpage/Manifest.plist +0 -12
  26. data/spec/fixtures/Starter.playgroundbook/Contents/Manifest.plist +0 -20
  27. data/spec/fixtures/assets/file.jpeg +0 -0
  28. data/spec/fixtures/book.yml +0 -6
  29. data/spec/fixtures/test_chapter.playground/Contents.swift +0 -17
  30. data/spec/fixtures/test_chapter.playground/contents.xcplayground +0 -4
  31. data/spec/fixtures/wrapper/destination/swift_at_artsy_1.swift +0 -200
  32. data/spec/fixtures/wrapper/source/Swift-at-Artsy.playground/Contents.swift +0 -199
  33. data/spec/fixtures/wrapper/source/Swift-at-Artsy.playground/contents.xcplayground +0 -4
  34. data/spec/fixtures/wrapper/source/swift_at_artsy_1.md +0 -183
  35. data/spec/linter/chapter_linter_spec.rb +0 -30
  36. data/spec/linter/chapter_manifest_linter_spec.rb +0 -40
  37. data/spec/linter/contents_linter_spec.rb +0 -18
  38. data/spec/linter/cutscene_page_linter_spec.rb +0 -14
  39. data/spec/linter/cutscene_page_manifest_linter_spec.rb +0 -63
  40. data/spec/linter/manfiest_linter_spec.rb +0 -71
  41. data/spec/linter/page_linter_spec.rb +0 -19
  42. data/spec/linter/page_manifest_linter_spec.rb +0 -43
  43. data/spec/linter/playgroundbook_lint_spec.rb +0 -38
  44. data/spec/linter/root_manifest_linter_spec.rb +0 -35
  45. data/spec/renderer/chapter_collator_spec.rb +0 -70
  46. data/spec/renderer/contents_manfiest_generator_spec.rb +0 -41
  47. data/spec/renderer/glossary_generator_spec.rb +0 -54
  48. data/spec/renderer/page_processor_spec.rb +0 -86
  49. data/spec/renderer/page_writer_spec.rb +0 -70
  50. data/spec/renderer/playgroundbook_renderer_spec.rb +0 -122
  51. data/spec/spec_helper.rb +0 -85
  52. data/spec/wrapper/markdown_wrapper_spec.rb +0 -90
@@ -1,18 +0,0 @@
1
- require File.expand_path("../../spec_helper", __FILE__)
2
-
3
- module Playgroundbook
4
- describe ContentsLinter do
5
- include FakeFS::SpecHelpers
6
- let(:contents_linter) { ContentsLinter.new(root_manifest_linter) }
7
- let(:root_manifest_linter) { double(RootManifestLinter) }
8
-
9
- it "calls through to root manifest linter" do
10
- expect(root_manifest_linter).to receive(:lint)
11
-
12
- FakeFS do
13
- Dir.mkdir "Contents"
14
- contents_linter.lint
15
- end
16
- end
17
- end
18
- end
@@ -1,14 +0,0 @@
1
- require File.expand_path("../../spec_helper", __FILE__)
2
-
3
- module Playgroundbook
4
- describe CutscenePageLinter do
5
- include FakeFS::SpecHelpers
6
- let(:cutscene_page_linter) { CutscenePageLinter.new(cutscene_page_manifest_linter) }
7
- let(:cutscene_page_manifest_linter) { double(CutscenePageManifestLinter) }
8
-
9
- it "passes through to cutscene_page_manifest_linter" do
10
- expect(cutscene_page_manifest_linter).to receive(:lint)
11
- expect { cutscene_page_linter.lint }.to_not raise_error
12
- end
13
- end
14
- end
@@ -1,63 +0,0 @@
1
- require File.expand_path("../../spec_helper", __FILE__)
2
-
3
- module Playgroundbook
4
- describe CutscenePageManifestLinter do
5
- include FakeFS::SpecHelpers
6
- let(:cutscene_page_manifest_linter) { CutscenePageManifestLinter.new }
7
-
8
- it "given a valid manifest does not fail" do
9
- FakeFS do
10
- cutscene_reference = "RealFile.html"
11
- plist = {
12
- "Name" => "Test Page",
13
- "CutsceneReference" => cutscene_reference
14
- }.to_plist
15
- File.open("Manifest.plist", "w") { |f| f.write(plist) }
16
- File.open(cutscene_reference, "w")
17
-
18
- expect { cutscene_page_manifest_linter.lint }.not_to raise_error
19
- end
20
- end
21
-
22
- context "given a cutscene path" do
23
- it "fails if the key doesn't exist" do
24
- FakeFS do
25
- cutscene_reference = "FakeFile.html"
26
- plist = {
27
- "Name" => "Test Page"
28
- }.to_plist
29
- File.open("Manifest.plist", "w") { |f| f.write(plist) }
30
-
31
- expect { cutscene_page_manifest_linter.lint }.to raise_error(SystemExit)
32
- end
33
- end
34
-
35
- it "fails if that file doesn't exist" do
36
- FakeFS do
37
- cutscene_reference = "FakeFile.html"
38
- plist = {
39
- "Name" => "Test Page",
40
- "CutsceneReference" => cutscene_reference
41
- }.to_plist
42
- File.open("Manifest.plist", "w") { |f| f.write(plist) }
43
-
44
- expect { cutscene_page_manifest_linter.lint }.to raise_error(SystemExit)
45
- end
46
- end
47
-
48
- it "fails with a non-HTML file" do
49
- FakeFS do
50
- cutscene_reference = "RealFile.xml"
51
- plist = {
52
- "Name" => "Test Page",
53
- "CutsceneReference" => cutscene_reference
54
- }.to_plist
55
- File.open("Manifest.plist", "w") { |f| f.write(plist) }
56
- File.open(cutscene_reference, "w")
57
-
58
- expect { cutscene_page_manifest_linter.lint }.to raise_error(SystemExit)
59
- end
60
- end
61
- end
62
- end
63
- end
@@ -1,71 +0,0 @@
1
- require File.expand_path("../../spec_helper", __FILE__)
2
-
3
- module Playgroundbook
4
- describe RootManifestLinter do
5
- include FakeFS::SpecHelpers
6
- let(:manifest_linter) { ManifestLinter.new }
7
-
8
- it "fails if a Manifest.plist file does not exist" do
9
- expect { manifest_linter.lint }.to raise_error(SystemExit)
10
- end
11
-
12
- it "fails if the Manifest.plist file does not contain a Name value" do
13
- FakeFS do
14
- plist = {}.to_plist
15
- File.open("Manifest.plist", "w") { |f| f.write(plist) }
16
-
17
- expect { manifest_linter.lint }.to raise_error(SystemExit)
18
- end
19
- end
20
-
21
- it "succeeds if the Manifest.plist file is well-formed" do
22
- FakeFS do
23
- plist = { "Name" => "My Test Name" }.to_plist
24
- File.open("Manifest.plist", "w") { |f| f.write(plist) }
25
-
26
- expect { manifest_linter.lint }.to_not raise_error
27
- end
28
- end
29
-
30
- it "extracts Manfiest.plist contents from pwd" do
31
- FakeFS do
32
- contents = { "key" => "value" }
33
- File.open("Manifest.plist", "w") { |f| f.write(contents.to_plist) }
34
-
35
- expect(manifest_linter.manifest_plist_contents).to eq(contents)
36
- end
37
- end
38
-
39
- describe "key-value checking" do
40
- before do
41
- end
42
-
43
- it "checks for non-defined keys in manifest" do
44
- FakeFS do
45
- plist = {}.to_plist
46
- File.open("Manifest.plist", "w") { |f| f.write(plist) }
47
-
48
- expect(manifest_linter.value_defined_in_manifest?("key")).to be_falsy
49
- end
50
- end
51
-
52
- it "checks for nil keys in manifest" do
53
- FakeFS do
54
- plist = { "key" => nil }.to_plist
55
- File.open("Manifest.plist", "w") { |f| f.write(plist) }
56
-
57
- expect(manifest_linter.value_defined_in_manifest?("key")).to be_falsy
58
- end
59
- end
60
-
61
- it "checks for empty keys in manifest" do
62
- FakeFS do
63
- plist = { "key" => "value" }.to_plist
64
- File.open("Manifest.plist", "w") { |f| f.write(plist) }
65
-
66
- expect(manifest_linter.value_defined_in_manifest?("key")).to be_truthy
67
- end
68
- end
69
- end
70
- end
71
- end
@@ -1,19 +0,0 @@
1
- require File.expand_path("../../spec_helper", __FILE__)
2
-
3
- module Playgroundbook
4
- describe PageLinter do
5
- include FakeFS::SpecHelpers
6
- let(:page_linter) { PageLinter.new(page_manifest_linter) }
7
- let(:page_manifest_linter) { double(PageManifestLinter) }
8
-
9
- it "fails if Contents.swift does not exist" do
10
- expect { page_linter.lint }.to raise_error(SystemExit)
11
- end
12
-
13
- it "passes through to page_manifest_linter" do
14
- File.open(ContentsSwiftFileName, "w") { |f| f.write("") }
15
- expect(page_manifest_linter).to receive(:lint)
16
- expect { page_linter.lint }.to_not raise_error
17
- end
18
- end
19
- end
@@ -1,43 +0,0 @@
1
- require File.expand_path("../../spec_helper", __FILE__)
2
-
3
- module Playgroundbook
4
- describe PageManifestLinter do
5
- include FakeFS::SpecHelpers
6
- let(:page_manifest_linter) { PageManifestLinter.new }
7
-
8
- it "given a valid manifest does not fail" do
9
- # TODO: We're not checking optional values yet, more tests to come.
10
- # See page_manifest_linter.rb and https://github.com/ashfurrow/playground-book-lint/issues/3 for details.
11
-
12
- FakeFS do
13
- plist = { "Name" => "Test Page" }.to_plist
14
- File.open("Manifest.plist", "w") { |f| f.write(plist) }
15
- expect { page_manifest_linter.lint }.to_not raise_error
16
- end
17
- end
18
-
19
- describe "context given a live view mode" do
20
- it "succeeds with valid values" do
21
- FakeFS do
22
- plist = {
23
- "Name" => "Test Page",
24
- "LiveViewMode" => "HiddenByDefault"
25
- }.to_plist
26
- File.open("Manifest.plist", "w") { |f| f.write(plist) }
27
- expect { page_manifest_linter.lint }.to_not raise_error
28
- end
29
- end
30
-
31
- it "fails with invalid values" do
32
- FakeFS do
33
- plist = {
34
- "Name" => "Test Page",
35
- "LiveViewMode" => "UnsupportedViewMode"
36
- }.to_plist
37
- File.open("Manifest.plist", "w") { |f| f.write(plist) }
38
- expect { page_manifest_linter.lint }.to raise_error(SystemExit)
39
- end
40
- end
41
- end
42
- end
43
- end
@@ -1,38 +0,0 @@
1
- require File.expand_path("../../spec_helper", __FILE__)
2
-
3
- module Playgroundbook
4
- describe Linter do
5
- let(:linter) { Linter.new(test_playground_book, contents_linter) }
6
- let(:contents_linter) { double(ContentsLinter) }
7
-
8
- it "initializes correctly" do
9
- expect(linter.playground_file_name) == test_playground_book
10
- end
11
-
12
- it "exits on lint failure" do
13
- allow(linter).to receive(:contents_dir_exists?)
14
- .and_return(false)
15
-
16
- expect { linter.lint }.to raise_error(SystemExit)
17
- end
18
-
19
- it "fails when file does not exist" do
20
- allow(linter).to receive(:contents_dir_exists?)
21
- .and_return(false)
22
- allow(linter).to receive(:fail_lint)
23
- .with("No Contents directory")
24
- .and_raise(SystemExit)
25
-
26
- expect { linter.lint }.to raise_error(SystemExit)
27
- end
28
-
29
- it "lints" do
30
- allow(linter).to receive(:contents_dir_exists?)
31
- .and_return(true)
32
- allow(contents_linter).to receive(:lint)
33
- expect(Dir).to receive(:chdir).with(test_playground_book)
34
-
35
- linter.lint
36
- end
37
- end
38
- end
@@ -1,35 +0,0 @@
1
- require File.expand_path("../../spec_helper", __FILE__)
2
-
3
- module Playgroundbook
4
- describe RootManifestLinter do
5
- include FakeFS::SpecHelpers
6
- let(:root_manifest_linter) { RootManifestLinter.new(chapter_linter) }
7
- let(:chapter_linter) { double(ChapterLinter) }
8
-
9
- it "fails if Chapters directory does not exist" do
10
- expect { root_manifest_linter.lint }.to raise_error(SystemExit)
11
- end
12
-
13
- it "fails if manfiest does not include Chapters" do
14
- FakeFS do
15
- Dir.mkdir("Chapters")
16
- plist = { "Name" => "Test" }.to_plist
17
- File.open("Manifest.plist", "w") { |f| f.write(plist) }
18
-
19
- expect { root_manifest_linter.lint }.to raise_error(SystemExit)
20
- end
21
- end
22
-
23
- it "calls through to lint each chapter" do
24
- FakeFS do
25
- plist = { "Chapters" => ["test_chapter_name"], "Name" => "Test" }.to_plist
26
- File.open("Manifest.plist", "w") { |f| f.write(plist) }
27
- Dir.mkdir("Chapters")
28
-
29
- expect(chapter_linter).to receive(:lint).with("test_chapter_name")
30
-
31
- expect { root_manifest_linter.lint }.to_not raise_error
32
- end
33
- end
34
- end
35
- end
@@ -1,70 +0,0 @@
1
- require File.expand_path("../../spec_helper", __FILE__)
2
-
3
- module Playgroundbook
4
- describe ChapterCollator do
5
- include FakeFS::SpecHelpers
6
- let(:collator) { ChapterCollator.new(page_writer, test_ui) }
7
- let(:page_writer) { double(PageWriter) }
8
- let(:test_ui) { Cork::Board.new(silent: true) }
9
- let(:parsed_chapter) { PageParser.new.parse_chapter_pages(test_chapter_contents) }
10
- let(:chapter) { { 'name' => "test_chapter" } }
11
-
12
- before do
13
- allow(page_writer).to receive(:write_page)
14
- end
15
-
16
- it "creates a chapter manifest" do
17
- collator.collate(chapter, parsed_chapter, [])
18
-
19
- expect(File.exist?("#{chapter['name']}.playgroundchapter/#{ManifestFileName}")).to be_truthy
20
- end
21
-
22
- context "the chapter manifest" do
23
- before do
24
- collator.collate(chapter, parsed_chapter, ["UIKit"])
25
- end
26
-
27
- it "has the correct name" do
28
- expect(get_manifest("#{chapter['name']}.playgroundchapter/#{ManifestFileName}")["Name"]).to eq(chapter['name'])
29
- end
30
-
31
- it "has the correct pages" do
32
- expect(get_manifest("#{chapter['name']}.playgroundchapter/#{ManifestFileName}")["Pages"]).to eq([
33
- "Page 1.playgroundpage",
34
- "Page 2.playgroundpage"
35
- ])
36
- end
37
- end
38
-
39
- it "calls the page_writer for each page" do
40
- expect(page_writer).to receive(:write_page).with("Page 1", "Page 1.playgroundpage", [], "str = \"Yo, it's page 1.\"\nsharedFunc()", {"name"=>"test_chapter"})
41
- expect(page_writer).to receive(:write_page).with("Page 2", "Page 2.playgroundpage", [], "str = \"Page 2 awww yeah.\"\nsharedFunc()", {"name"=>"test_chapter"})
42
-
43
- collator.collate(chapter, parsed_chapter, [])
44
- end
45
-
46
- it "does not explode if a Source directory already exists" do
47
- expect { collator.collate(chapter, parsed_chapter, []) }.to_not raise_error
48
- end
49
-
50
- context "having colated" do
51
- before do
52
- collator.collate(chapter, parsed_chapter, [])
53
- end
54
-
55
- it "creates a Source directory if one does not exist" do
56
- expect(Dir.exist?("#{chapter['name']}.playgroundchapter/#{SharedSourcesDirectoryName}")).to be_truthy
57
- end
58
-
59
- context "Sources folder" do
60
- it "has a Preamble.swift file" do
61
- expect(File.exist?("#{chapter['name']}.playgroundchapter/#{SharedSourcesDirectoryName}/#{PreambleFileName}")).to be_truthy
62
- end
63
-
64
- it "has the correct preamble contents" do
65
- expect(File.read("#{chapter['name']}.playgroundchapter/#{SharedSourcesDirectoryName}/#{PreambleFileName}")).to eq("import UIKit\n\nvar str = \"Hello, playground\"\n\nfunc sharedFunc() {\n print(\"This should be accessible to all pages.\")\n}")
66
- end
67
- end
68
- end
69
- end
70
- end
@@ -1,41 +0,0 @@
1
- require File.expand_path("../../spec_helper", __FILE__)
2
-
3
- module Playgroundbook
4
- describe ContentsManifestGenerator do
5
- include FakeFS::SpecHelpers
6
- let(:generator) { ContentsManifestGenerator.new(test_ui) }
7
- let(:test_ui) { Cork::Board.new(silent: true) }
8
-
9
- it "creates the manifest file" do
10
- generator.generate(test_book_metadata)
11
-
12
- expect(File.exist?("Manifest.plist")).to be_truthy
13
- end
14
-
15
- describe "the manifest file" do
16
- before do
17
- generator.generate(test_book_metadata)
18
- end
19
-
20
- it "has a book name" do
21
- expect(get_manifest["Name"]).to eq("Testing Book")
22
- end
23
-
24
- it "has an identifier" do
25
- expect(get_manifest["ContentIdentifier"]).to eq("com.ashfurrow.testing")
26
- end
27
-
28
- it "has a deployment target" do
29
- expect(get_manifest["DeploymentTarget"]).to eq("ios10.0")
30
- end
31
-
32
- it "has chapters specified" do
33
- expect(get_manifest["Chapters"]).to eq(["test_chapter.playgroundchapter"])
34
- end
35
-
36
- it "has a ImageReference" do
37
- expect(get_manifest["ImageReference"]).to eq("file.jpeg")
38
- end
39
- end
40
- end
41
- end
@@ -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