playgroundbook 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +50 -0
- data/.rspec +2 -0
- data/.rubocop.yml +112 -0
- data/.ruby-version +1 -0
- data/Changelog.md +37 -0
- data/CodeOfConduct.md +50 -0
- data/Community.md +52 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +102 -0
- data/Guardfile +14 -0
- data/README.md +7 -1
- data/Rakefile +8 -0
- data/lib/playgroundbook.rb +1 -0
- data/lib/renderer/playgroundbook_renderer.rb +11 -0
- data/lib/version.rb +1 -1
- data/playgroundbook.gemspec +21 -0
- data/spec/fixtures/Starter.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Manifest.plist +15 -0
- data/spec/fixtures/Starter.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Pages/Page1.playgroundpage/Contents.swift +8 -0
- data/spec/fixtures/Starter.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Pages/Page1.playgroundpage/Manifest.plist +12 -0
- data/spec/fixtures/Starter.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Pages/Page2.playgroundpage/Contents.swift +8 -0
- data/spec/fixtures/Starter.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Pages/Page2.playgroundpage/Manifest.plist +12 -0
- data/spec/fixtures/Starter.playgroundbook/Contents/Manifest.plist +20 -0
- data/spec/fixtures/assets/file.jpeg +0 -0
- data/spec/fixtures/book.yml +6 -0
- data/spec/fixtures/test_chapter.playground/Contents.swift +17 -0
- data/spec/fixtures/test_chapter.playground/contents.xcplayground +4 -0
- data/spec/fixtures/wrapper/destination/swift_at_artsy_1.swift +200 -0
- data/spec/fixtures/wrapper/source/Swift-at-Artsy.playground/Contents.swift +199 -0
- data/spec/fixtures/wrapper/source/Swift-at-Artsy.playground/contents.xcplayground +4 -0
- data/spec/fixtures/wrapper/source/swift_at_artsy_1.md +183 -0
- data/spec/linter/chapter_linter_spec.rb +30 -0
- data/spec/linter/chapter_manifest_linter_spec.rb +40 -0
- data/spec/linter/contents_linter_spec.rb +18 -0
- data/spec/linter/cutscene_page_linter_spec.rb +14 -0
- data/spec/linter/cutscene_page_manifest_linter_spec.rb +63 -0
- data/spec/linter/manfiest_linter_spec.rb +71 -0
- data/spec/linter/page_linter_spec.rb +19 -0
- data/spec/linter/page_manifest_linter_spec.rb +43 -0
- data/spec/linter/playgroundbook_lint_spec.rb +38 -0
- data/spec/linter/root_manifest_linter_spec.rb +35 -0
- data/spec/renderer/chapter_collator_spec.rb +70 -0
- data/spec/renderer/contents_manfiest_generator_spec.rb +41 -0
- data/spec/renderer/glossary_generator_spec.rb +54 -0
- data/spec/renderer/page_processor_spec.rb +86 -0
- data/spec/renderer/page_writer_spec.rb +70 -0
- data/spec/renderer/playgroundbook_renderer_spec.rb +122 -0
- data/spec/spec_helper.rb +85 -0
- data/spec/wrapper/markdown_wrapper_spec.rb +90 -0
- metadata +46 -2
@@ -0,0 +1,14 @@
|
|
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
|
@@ -0,0 +1,63 @@
|
|
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
|
@@ -0,0 +1,71 @@
|
|
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
|
@@ -0,0 +1,19 @@
|
|
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
|
@@ -0,0 +1,43 @@
|
|
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
|
@@ -0,0 +1,38 @@
|
|
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
|
@@ -0,0 +1,35 @@
|
|
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
|
@@ -0,0 +1,70 @@
|
|
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
|
@@ -0,0 +1,41 @@
|
|
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
|
@@ -0,0 +1,54 @@
|
|
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
|
@@ -0,0 +1,86 @@
|
|
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
|
@@ -0,0 +1,70 @@
|
|
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
|