playgroundbook 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +110 -0
  3. data/Changelog.md +4 -0
  4. data/Gemfile +10 -9
  5. data/Gemfile.lock +4 -2
  6. data/Guardfile +2 -2
  7. data/Rakefile +3 -3
  8. data/bin/playgroundbook +9 -7
  9. data/lib/{playgroundbook_lint → linter}/abstract_linter.rb +2 -2
  10. data/lib/{playgroundbook_lint → linter}/chapter_linter.rb +4 -4
  11. data/lib/{playgroundbook_lint → linter}/chapter_manifest_linter.rb +5 -5
  12. data/lib/{playgroundbook_lint → linter}/contents_linter.rb +3 -3
  13. data/lib/{playgroundbook_lint → linter}/cutscene_page_linter.rb +2 -2
  14. data/lib/{playgroundbook_lint → linter}/cutscene_page_manifest_linter.rb +2 -2
  15. data/lib/{playgroundbook_lint → linter}/manifest_linter.rb +5 -5
  16. data/lib/{playgroundbook_lint → linter}/page_linter.rb +2 -2
  17. data/lib/{playgroundbook_lint → linter}/page_manifest_linter.rb +3 -3
  18. data/lib/{playgroundbook_lint → linter}/playgroundbook_lint.rb +6 -6
  19. data/lib/{playgroundbook_lint → linter}/root_manifest_linter.rb +9 -9
  20. data/lib/playgroundbook.rb +8 -7
  21. data/lib/{playgroundbook_renderer → renderer}/chapter_collator.rb +18 -18
  22. data/lib/renderer/contents_manifest_generator.rb +35 -0
  23. data/lib/{playgroundbook_renderer → renderer}/glossary_generator.rb +13 -16
  24. data/lib/{playgroundbook_renderer → renderer}/page_parser.rb +4 -3
  25. data/lib/{playgroundbook_renderer → renderer}/page_processor.rb +0 -0
  26. data/lib/{playgroundbook_renderer → renderer}/page_writer.rb +11 -11
  27. data/lib/{playgroundbook_renderer → renderer}/playgroundbook_renderer.rb +29 -29
  28. data/lib/version.rb +1 -1
  29. data/lib/wrapper/markdown_wrapper.rb +58 -0
  30. data/playground_book_lint.gemspec +14 -14
  31. data/spec/fixtures/wrapper/destination/swift_at_artsy_1.swift +199 -0
  32. data/spec/fixtures/wrapper/source/Swift-at-Artsy.playground/Contents.swift +199 -0
  33. data/spec/fixtures/wrapper/source/Swift-at-Artsy.playground/contents.xcplayground +4 -0
  34. data/spec/fixtures/wrapper/source/swift_at_artsy_1.md +183 -0
  35. data/spec/{playground_book_lint → linter}/chapter_linter_spec.rb +5 -5
  36. data/spec/{playground_book_lint → linter}/chapter_manifest_linter_spec.rb +12 -12
  37. data/spec/{playground_book_lint → linter}/contents_linter_spec.rb +3 -3
  38. data/spec/{playground_book_lint → linter}/cutscene_page_linter_spec.rb +2 -2
  39. data/spec/linter/cutscene_page_manifest_linter_spec.rb +63 -0
  40. data/spec/linter/manfiest_linter_spec.rb +71 -0
  41. data/spec/{playground_book_lint → linter}/page_linter_spec.rb +4 -4
  42. data/spec/{playground_book_lint → linter}/page_manifest_linter_spec.rb +13 -13
  43. data/spec/{playground_book_lint → linter}/playgroundbook_lint_spec.rb +6 -6
  44. data/spec/linter/root_manifest_linter_spec.rb +35 -0
  45. data/spec/renderer/chapter_collator_spec.rb +70 -0
  46. data/spec/renderer/contents_manfiest_generator_spec.rb +41 -0
  47. data/spec/renderer/glossary_generator_spec.rb +54 -0
  48. data/spec/{playgroundbook_renderer_spec → renderer}/page_processor_spec.rb +12 -12
  49. data/spec/{playgroundbook_renderer_spec → renderer}/page_writer_spec.rb +19 -19
  50. data/spec/renderer/playgroundbook_renderer_spec.rb +122 -0
  51. data/spec/spec_helper.rb +38 -38
  52. data/spec/wrapper/markdown_wrapper_spec.rb +33 -0
  53. metadata +43 -37
  54. data/lib/playgroundbook_renderer/contents_manifest_generator.rb +0 -35
  55. data/spec/playground_book_lint/cutscene_page_manifest_linter_spec.rb +0 -63
  56. data/spec/playground_book_lint/manfiest_linter_spec.rb +0 -71
  57. data/spec/playground_book_lint/root_manifest_linter_spec.rb +0 -35
  58. data/spec/playgroundbook_renderer_spec/chapter_collator_spec.rb +0 -70
  59. data/spec/playgroundbook_renderer_spec/contents_manfiest_generator_spec.rb +0 -41
  60. data/spec/playgroundbook_renderer_spec/glossary_generator_spec.rb +0 -52
  61. data/spec/playgroundbook_renderer_spec/playgroundbook_renderer_spec.rb +0 -122
@@ -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
@@ -1,10 +1,10 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require File.expand_path("../../spec_helper", __FILE__)
2
2
 
3
3
  module Playgroundbook
4
4
  describe PageProcessor do
5
5
  let(:page_processor) { PageProcessor.new }
6
-
7
- it 'removes newlines before markdown blocks' do
6
+
7
+ it "removes newlines before markdown blocks" do
8
8
  page_contents = <<-EOS
9
9
  let a = 6
10
10
 
@@ -18,11 +18,11 @@ let a = 6
18
18
  Some markdown.
19
19
  */
20
20
  EOS
21
-
21
+
22
22
  expect(page_processor.strip_extraneous_newlines(page_contents)).to eq(processed_page_contents)
23
23
  end
24
24
 
25
- it 'removes newlines after markdown blocks' do
25
+ it "removes newlines after markdown blocks" do
26
26
  page_contents = <<-EOS
27
27
  /*:
28
28
  Some markdown.
@@ -36,11 +36,11 @@ let a = 6
36
36
  */
37
37
  let a = 6
38
38
  EOS
39
-
39
+
40
40
  expect(page_processor.strip_extraneous_newlines(page_contents)).to eq(processed_page_contents)
41
41
  end
42
42
 
43
- it 'removes newlines surrounding single-line markdown blocks' do
43
+ it "removes newlines surrounding single-line markdown blocks" do
44
44
  page_contents = <<-EOS
45
45
  let a = 6
46
46
 
@@ -53,11 +53,11 @@ let a = 6
53
53
  //: Some markdown.
54
54
  let b = a
55
55
  EOS
56
-
56
+
57
57
  expect(page_processor.strip_extraneous_newlines(page_contents)).to eq(processed_page_contents)
58
58
  end
59
59
 
60
- it 'does not strip newlines from code' do
60
+ it "does not strip newlines from code" do
61
61
  page_contents = <<-EOS
62
62
  let a = 6
63
63
 
@@ -67,19 +67,19 @@ let b = a
67
67
  expect(page_processor.strip_extraneous_newlines(page_contents)).to eq(page_contents)
68
68
  end
69
69
 
70
- it 'it does not strip newlines from the markdown' do
70
+ it "it does not strip newlines from the markdown" do
71
71
  page_contents = <<-EOS
72
72
  /*:
73
73
 
74
74
  # Header
75
-
75
+
76
76
  Some markdown. The following lines are purposefull left blank.
77
77
 
78
78
 
79
79
 
80
80
  */
81
81
  EOS
82
-
82
+
83
83
  expect(page_processor.strip_extraneous_newlines(page_contents)).to eq(page_contents)
84
84
  end
85
85
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require File.expand_path("../../spec_helper", __FILE__)
2
2
 
3
3
  module Playgroundbook
4
4
  describe PageWriter do
@@ -6,8 +6,8 @@ module Playgroundbook
6
6
  let(:page_writer) { PageWriter.new(page_processor, test_ui) }
7
7
  let(:page_processor) { double(PageProcessor) }
8
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' }
9
+ let(:page_name) { "test page name" }
10
+ let(:page_dir_name) { "test page name.playgroundpage" }
11
11
  let(:page_contents) { "// Some swift goes here." }
12
12
  let(:generated_page_contesnts) { "//#-hidden-code\nimport UIKit\n//#-end-hidden-code\n// Some swift goes here." }
13
13
 
@@ -18,51 +18,51 @@ module Playgroundbook
18
18
  end
19
19
  end
20
20
 
21
- context 'with a pre-existing page directory' do
21
+ context "with a pre-existing page directory" do
22
22
  before do
23
23
  Dir.mkdir(page_dir_name)
24
24
  end
25
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
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
28
  end
29
29
  end
30
30
 
31
- it 'calls the page processor' do
31
+ it "calls the page processor" do
32
32
  expect(page_processor).to receive(:strip_extraneous_newlines)
33
- page_writer.write_page!(page_name, page_dir_name, ['UIKit'], page_contents)
33
+ page_writer.write_page(page_name, page_dir_name, ["UIKit"], page_contents)
34
34
  end
35
35
 
36
- context 'as a consequence of writing rendering' do
36
+ context "as a consequence of writing rendering" do
37
37
  before do
38
- page_writer.write_page!(page_name, page_dir_name, ['UIKit'], page_contents)
38
+ page_writer.write_page(page_name, page_dir_name, ["UIKit"], page_contents)
39
39
  end
40
40
 
41
- it 'creates a directory' do
41
+ it "creates a directory" do
42
42
  expect(Dir.exist?(page_dir_name)).to be_truthy
43
43
  end
44
44
 
45
- it 'writes a manifest' do
45
+ it "writes a manifest" do
46
46
  expect(Dir.exist?(page_dir_name)).to be_truthy
47
47
  end
48
48
 
49
- it 'writes a Contents.swift file' do
49
+ it "writes a Contents.swift file" do
50
50
  expect(File.exist?("#{page_dir_name}/Contents.swift")).to be_truthy
51
51
  end
52
52
 
53
- it 'has correct Contents.swift contents' do
53
+ it "has correct Contents.swift contents" do
54
54
  expect(File.read("#{page_dir_name}/Contents.swift")).to eq(generated_page_contesnts)
55
55
  end
56
56
 
57
- context 'the manifest' do
57
+ context "the manifest" do
58
58
  let(:manifest) { get_manifest("#{page_dir_name}/#{MANIFEST_FILE_NAME}") }
59
59
 
60
- it 'has a name' do
61
- expect(manifest['Name']).to eq(page_name)
60
+ it "has a name" do
61
+ expect(manifest["Name"]).to eq(page_name)
62
62
  end
63
63
 
64
- it 'has a LiveViewMode' do
65
- expect(manifest['LiveViewMode']).to eq('HiddenByDefault')
64
+ it "has a LiveViewMode" do
65
+ expect(manifest["LiveViewMode"]).to eq("HiddenByDefault")
66
66
  end
67
67
  end
68
68
  end
@@ -0,0 +1,122 @@
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
@@ -1,32 +1,32 @@
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 'playgroundbook_lint/abstract_linter'
14
- require 'playgroundbook_lint/chapter_linter'
15
- require 'playgroundbook_lint/chapter_manifest_linter'
16
- require 'playgroundbook_lint/contents_linter'
17
- require 'playgroundbook_lint/manifest_linter'
18
- require 'playgroundbook_lint/page_linter'
19
- require 'playgroundbook_lint/page_manifest_linter'
20
- require 'playgroundbook_lint/cutscene_page_linter'
21
- require 'playgroundbook_lint/cutscene_page_manifest_linter'
22
- require 'playgroundbook_lint/root_manifest_linter'
23
-
24
- require 'playgroundbook_renderer/contents_manifest_generator'
25
- require 'playgroundbook_renderer/chapter_collator'
26
- require 'playgroundbook_renderer/page_writer'
27
- require 'playgroundbook_renderer/page_parser'
28
- require 'playgroundbook_renderer/glossary_generator'
29
- require 'playgroundbook_renderer/page_processor'
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
30
 
31
31
  RSpec.configure do |config|
32
32
  config.color = true
@@ -39,19 +39,19 @@ RSpec::Expectations.configuration.on_potential_false_positives = :nothing
39
39
  Playgroundbook::AbstractLinter.ui = Cork::Board.new(silent: true)
40
40
 
41
41
  def test_playground_book
42
- 'spec/fixtures/Starter.playgroundbook'
42
+ "spec/fixtures/Starter.playgroundbook"
43
43
  end
44
44
 
45
45
  def test_book_metadata
46
46
  {
47
- 'name' => 'Testing Book',
48
- 'chapters' => ['test_chapter'],
49
- 'identifier' => 'com.ashfurrow.testing',
50
- 'resources' => 'assets',
51
- 'cover' => 'file.jpeg',
52
- 'glossary' => [
47
+ "name" => "Testing Book",
48
+ "chapters" => ["test_chapter"],
49
+ "identifier" => "com.ashfurrow.testing",
50
+ "resources" => "assets",
51
+ "cover" => "file.jpeg",
52
+ "glossary" => [
53
53
  {
54
- 'term' => 'definition'
54
+ "term" => "definition"
55
55
  }
56
56
  ]
57
57
  }
@@ -62,7 +62,7 @@ def get_manifest(file_name = Playgroundbook::ManifestFileName)
62
62
  end
63
63
 
64
64
  def test_chapter_contents
65
- <<-EOSwift
65
+ <<-EOSwift
66
66
  import UIKit
67
67
 
68
68
  var str = "Hello, playground"