playgroundbook 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
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,183 +0,0 @@
1
- (Note: a screen recording of a presentation of this material is [available on YouTube](https://github.com/artsy/Swift-at-Artsy/tree/master/Beginners/Lesson%20One).)
2
-
3
- Hey! So we're going to be looking at Swift from the perspective of learning programming. This means you get to ask awkward questions and I struggle to verbalise concepts that are the programming equivalent of muscle memory. It'll be fun!
4
-
5
- To start off we need to get to a point where we can write any code. We're going to assume that you already have a copy of Xcode 7 installed. With that, let's get started!
6
-
7
- Open Xcode and you'll get this Welcome dialogue.
8
-
9
- ![Xcode Welcome Screen](img/welcome.png)
10
-
11
- We'll be using _playgrounds_ to learn Swift. Click "Get started with a playground", give it a name, and make sure the platform is set to **OS X**.
12
-
13
- ![Creating a new playground](img/newplayground.png)
14
-
15
- Awesome. Xcode will create an open the playground for you. It'll look something like this.
16
-
17
- ![Empty Playground](img/emptyplayground.png)
18
-
19
- The large pane on the left is where we're going to write code. On the right is where the results of our code are displayed. You can see that there's already one line of code written for us, `var str = "Hello, playground"`, and the results pane says `"Hello, playground"`. Neat.
20
-
21
-
22
- Normally for things I work with, the code we are writing gets transformed from something we, as humans, kind-of understand to something a machine understands via a compiler. Let's stick with the idea that it's basically a translator from human to machine. Normally its a big upfront conversion, for example Eigen can take 5 minutes to compile.
23
-
24
- We're going to use Playgrounds, which is more like a back and forth conversation with the compiler, so it's much faster to write code and test things out. These are called REPLs.
25
-
26
- What this means is whatever you type will be run by Xcode and the results will be shown on the right. When Xcode is compiling code (whenever you change text), the top bar of the window will change to say "Running" and will show a little spinner.
27
-
28
- Let's start by saying what _isn't_ code. You see the the first line, how it is greyed out? Well that's a comment. Comments are annotations in the code that are not ran by the compiler. We'll be using comments occasionally to skip bits of code, or to remind us what something is.
29
-
30
- OK let's write some code, let's try typing some things.
31
-
32
- ```swift
33
- 1 + 2
34
-
35
- 1 / 2
36
- 1.0 / 2.0
37
-
38
- "Hello, Artsy"
39
- ```
40
-
41
- You can see the results in the results pane:
42
-
43
- ![Results](img/results.png)
44
-
45
- In programming, we want to work with abstractions. So let's make our first variable. A variable holds a value that you can refer to later, you can name them (almost) whatever you want.
46
-
47
- Variables are themselves an abstract concept, and it's normal for beginners to take time getting comfortable with them. In essence, a variable is a way to store something in a place that you can refer to later. There are a few good reasons to do this, but the most common one is that we need to refer to the same value more than once.
48
-
49
- On an artist's Artsy page, we show their name more than once. It's useful to be able to store the artists name in a variable _once_ and then refer to that variable multiple times to show the user an artist's page.
50
-
51
- We're going to make a simple calculator with 3 variables. What I'd like to do is define a variable called `a` and `b` then add them together to make `c`. This is a simple example, but it's about foundations.
52
-
53
- ```swift
54
- var a = 2
55
- var b = 3
56
-
57
- var c = a + b
58
- ```
59
-
60
- In this case, you can see that we're referring back to `a` and `b` as variables, instead of the numbers `2` and `3`. This is a simple example, and with more experience, you'll get more comfortable.
61
-
62
- Variables all have a _type_. Some variables are numbers, and some are strings, and some are other things, too! Numbers are often `Int`, or an integer (basically a round number: 1, 2, 3, -500, 401). Swift is a **strongly-typed language**, which means that types matter a lot. Swift won't let you confuse one type for another. Even though we haven't _told_ Swift what the type of our variables are, the compiler figures it out automatically.
63
-
64
- In Swift, `:` specifies a type. So the following two lines are equivalent.
65
-
66
- ```swift
67
- var myString = "Hello, Artsy"
68
- var myString: String = "Hello, Artsy"
69
- ```
70
-
71
- In this case we're dealing with a collection of letters, that combined, we call a string. This is common terminology in most programming languages, think of it as a string of letters.
72
-
73
- ```swift
74
- var myString: String = 1
75
- ```
76
-
77
- Swift will complain and say that `'Int' is not convertible to 'String'`. This is Swift's compile-time type checking. It prevents bugs from happening in apps at runtime by giving you errors before-hand. Swift's primary goal is safety against crashes in apps.
78
-
79
- When we're writing code, very often we want to print out some useful information for someone to read. We're going to use this to show that some of our code is running. So lets add a print statement saying what the value of `c` is:
80
-
81
- ```swift
82
- print(c)
83
- ```
84
-
85
- With `print` working, we can start doing some logic. We want to start checking how big our `c` is, and just like in English, we'll use an `if` statement:
86
-
87
- ```swift
88
- if c > 6 {
89
- print("Pretty big c you got there.")
90
- }
91
- ```
92
-
93
- Let's unpack what we're seeing here. `if [something]` - what's happening here is that the bit after the `if` is checking to see if `c` is greater than the number (`Int`) `6`. If it is, then it will run the code inside the braces.
94
-
95
- `if` statements are fundamentally about doing some code only under certain circumstances. For example, Artsy only shows the "Inquire on Artwork" button **if** that artwork can be inquired upon. There are lots of different places in our code where it's useful to do something only if a condition is met.
96
-
97
- It is common to use a left margin / indentation to indicate that something is inside a braced section. It's not enforced though.
98
-
99
- ```swift
100
- if c > 6 {
101
- print("Pretty big c you got there.")
102
- }
103
- ```
104
-
105
- ```swift
106
- if c > 6 {
107
- print("Pretty big c you got there.")
108
- }
109
- ```
110
-
111
- ```swift
112
- if c > 6 { print("Pretty big c you got there.") }
113
- ```
114
-
115
- We've got one more thing to go over, and that is loops. Loops repeat a section of code. Computers are really good at doing the same thing over and over, and loops are how programmers tell computers to do that. Repeating code is really useful in the Artsy's artwork pages, specifically in the related artworks section. As programmers, we tell the computer how to add _one_ artwork to the page, and then tell the computer to do that over and over for all the related artworks.
116
-
117
- Let's make a nice simple loop, one that reads like English. For _a_ number in _zero to c_.
118
-
119
- ```swift
120
- for number in 0...c {
121
- print("hi")
122
- }
123
- ```
124
-
125
- It has the same behavior that we saw in the `if` example. It will run the thing inside the braces as many times as the value of `c`. Each time it will print out `"hi"`. I think we can expand on this one little bit. The word `number` here is actually a variable, let's make it sound all mathematical and call it `x` instead.
126
-
127
- ```swift
128
- for x in 0...c {
129
- print("hi")
130
- }
131
- ```
132
-
133
- Now we know it's a variable, lets print it!
134
-
135
- ```swift
136
- for x in 0...c {
137
- print(x)
138
- }
139
- ```
140
-
141
- For loops, often just called "loops", are foundational to programming. In this example above, we've looped over all the numbers from `0` to `c`, but you can loop over other things, too. Say we're making an app at Artsy that shows a bunch of artworks – we might loop over all the artworks to show them on the screen.
142
-
143
- If you hit the little triangle in the bottom left you can see the printed output!
144
-
145
- ----------------
146
-
147
- So let's recap.
148
-
149
- * We've learned a little bit about variables, they are named values that make it easier for us to think about what something represents vs what it is.
150
-
151
- * Then we looked at some `String`s, and showed that you can't change something from a string to a number once you've start using it as a `String`,
152
-
153
- * We then printed some information.
154
-
155
- * After that we looked at adding an `if` statement to add some logic to our code.
156
-
157
- * Finally we wrapped up with a `for in` loop.
158
-
159
- If you're keen, feel free to keep playing in the playground. Try changing things in the loops to see what happens. Is it what you expected to happen? Why or why not?
160
-
161
- What do you think this code would do?
162
-
163
- ```swift
164
- for number in 0...15 {
165
- if number > 5 {
166
- print("This is greater than five")
167
- }
168
- }
169
- ```
170
-
171
- What about this?
172
-
173
- ```swift
174
- for number in 0...15 {
175
- if number > 5 {
176
- print("This is greater than five")
177
- } else {
178
- print("This is less than five")
179
- }
180
- }
181
- ```
182
-
183
- You can also look at the free Stanford Swift Course: https://www.youtube.com/playlist?list=PLxwBNxx9j4PW4sY-wwBwQos3G6Kn3x6xP
@@ -1,30 +0,0 @@
1
- require File.expand_path("../../spec_helper", __FILE__)
2
-
3
- module Playgroundbook
4
- describe RootManifestLinter do
5
- include FakeFS::SpecHelpers
6
- let(:chapter_linter) { ChapterLinter.new(chapter_manifest_linter) }
7
- let(:chapter_manifest_linter) { double(ChapterManifestLinter) }
8
- let(:chapter_directory_name) { "test_chapter" }
9
-
10
- it "fails when chapter directory does not exist" do
11
- expect { chapter_linter.lint(chapter_directory_name) }.to raise_error(SystemExit)
12
- end
13
-
14
- it "fails when Pages subdirectory of chapter dir does not exist" do
15
- FakeFS do
16
- Dir.mkdir(chapter_directory_name)
17
- expect { chapter_linter.lint(chapter_directory_name) }.to raise_error(SystemExit)
18
- end
19
- end
20
-
21
- it "calls through to chapter manifest linter" do
22
- FakeFS do
23
- expect(chapter_manifest_linter).to receive(:lint)
24
- FileUtils.mkdir_p("#{chapter_directory_name}/Pages")
25
-
26
- expect { chapter_linter.lint(chapter_directory_name) }.to_not raise_error
27
- end
28
- end
29
- end
30
- end
@@ -1,40 +0,0 @@
1
- require File.expand_path("../../spec_helper", __FILE__)
2
-
3
- module Playgroundbook
4
- describe ChapterManifestLinter do
5
- include FakeFS::SpecHelpers
6
- let(:chapter_manifest_linter) { ChapterManifestLinter.new(page_linter) }
7
- let(:page_linter) { double(PageLinter) }
8
- let(:page_directory_name) { "test.playgroundpage" }
9
-
10
- it "fails if no Pages defined in Manifest" do
11
- FakeFS do
12
- plist = { "Name" => "Test" }.to_plist
13
- File.open("Manifest.plist", "w") { |f| f.write(plist) }
14
-
15
- expect { chapter_manifest_linter.lint }.to raise_error(SystemExit)
16
- end
17
- end
18
-
19
- it "fails if Pages dir specified in Manifest does not exist" do
20
- FakeFS do
21
- plist = { "Name" => "Test", "Pages" => [page_directory_name] }.to_plist
22
- File.open("Manifest.plist", "w") { |f| f.write(plist) }
23
- Dir.mkdir("Pages")
24
-
25
- expect { chapter_manifest_linter.lint }.to raise_error(SystemExit)
26
- end
27
- end
28
-
29
- it "calls through to page linter" do
30
- FakeFS do
31
- expect(page_linter).to receive(:lint)
32
- plist = { "Name" => "Test", "Pages" => [page_directory_name] }.to_plist
33
- File.open("Manifest.plist", "w") { |f| f.write(plist) }
34
- FileUtils.mkdir_p("Pages/#{page_directory_name}")
35
-
36
- expect { chapter_manifest_linter.lint }.to_not raise_error
37
- end
38
- end
39
- end
40
- end
@@ -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_name, 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_name, 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()")
41
- expect(page_writer).to receive(:write_page).with("Page 2", "Page 2.playgroundpage", [], "str = \"Page 2 awww yeah.\"\nsharedFunc()")
42
-
43
- collator.collate(chapter_name, parsed_chapter, [])
44
- end
45
-
46
- it "does not explode if a Source directory already exists" do
47
- expect { collator.collate(chapter_name, parsed_chapter, []) }.to_not raise_error
48
- end
49
-
50
- context "having colated" do
51
- before do
52
- collator.collate(chapter_name, 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