playgroundbook 0.6.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,199 +0,0 @@
1
- /*:
2
- (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).)
3
-
4
- 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!
5
-
6
- 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!
7
-
8
- Open Xcode and you'll get this Welcome dialogue.
9
-
10
- ![Xcode Welcome Screen](img/welcome.png)
11
-
12
- 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**.
13
-
14
- ![Creating a new playground](img/newplayground.png)
15
-
16
- Awesome. Xcode will create an open the playground for you. It'll look something like this.
17
-
18
- ![Empty Playground](img/emptyplayground.png)
19
-
20
- 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.
21
-
22
-
23
- 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.
24
-
25
- 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.
26
-
27
- 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.
28
-
29
- 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.
30
-
31
- OK let's write some code, let's try typing some things.
32
-
33
- */
34
-
35
- 1 + 2
36
-
37
- 1 / 2
38
- 1.0 / 2.0
39
-
40
- "Hello, Artsy"
41
- /*:
42
-
43
- You can see the results in the results pane:
44
-
45
- ![Results](img/results.png)
46
-
47
- 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.
48
-
49
- 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.
50
-
51
- 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.
52
-
53
- 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.
54
-
55
- */
56
-
57
- var a = 2
58
- var b = 3
59
-
60
- var c = a + b
61
- /*:
62
-
63
- 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.
64
-
65
- 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.
66
-
67
- In Swift, `:` specifies a type. So the following two lines are equivalent.
68
-
69
- */
70
-
71
- var myString = "Hello, Artsy"
72
- var myString: String = "Hello, Artsy"
73
- /*:
74
-
75
- 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.
76
-
77
- */
78
-
79
- var myString: String = 1
80
- /*:
81
-
82
- 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.
83
-
84
- 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:
85
-
86
- */
87
-
88
- print(c)
89
- /*:
90
-
91
- 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:
92
-
93
- */
94
-
95
- if c > 6 {
96
- print("Pretty big c you got there.")
97
- }
98
- /*:
99
-
100
- 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.
101
-
102
- `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.
103
-
104
- It is common to use a left margin / indentation to indicate that something is inside a braced section. It's not enforced though.
105
-
106
- */
107
-
108
- if c > 6 {
109
- print("Pretty big c you got there.")
110
- }
111
- /*:
112
-
113
- */
114
-
115
- if c > 6 {
116
- print("Pretty big c you got there.")
117
- }
118
- /*:
119
-
120
- */
121
-
122
- if c > 6 { print("Pretty big c you got there.") }
123
- /*:
124
-
125
- 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.
126
-
127
- Let's make a nice simple loop, one that reads like English. For _a_ number in _zero to c_.
128
-
129
- */
130
-
131
- for number in 0...c {
132
- print("hi")
133
- }
134
- /*:
135
-
136
- 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.
137
-
138
- */
139
-
140
- for x in 0...c {
141
- print("hi")
142
- }
143
- /*:
144
-
145
- Now we know it's a variable, lets print it!
146
-
147
- */
148
-
149
- for x in 0...c {
150
- print(x)
151
- }
152
- /*:
153
-
154
- 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.
155
-
156
- If you hit the little triangle in the bottom left you can see the printed output!
157
-
158
- ----------------
159
-
160
- So let's recap.
161
-
162
- * 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.
163
-
164
- * 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`,
165
-
166
- * We then printed some information.
167
-
168
- * After that we looked at adding an `if` statement to add some logic to our code.
169
-
170
- * Finally we wrapped up with a `for in` loop.
171
-
172
- 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?
173
-
174
- What do you think this code would do?
175
-
176
- */
177
-
178
- for number in 0...15 {
179
- if number > 5 {
180
- print("This is greater than five")
181
- }
182
- }
183
- /*:
184
-
185
- What about this?
186
-
187
- */
188
-
189
- for number in 0...15 {
190
- if number > 5 {
191
- print("This is greater than five")
192
- } else {
193
- print("This is less than five")
194
- }
195
- }
196
- /*:
197
-
198
- You can also look at the free Stanford Swift Course: https://www.youtube.com/playlist?list=PLxwBNxx9j4PW4sY-wwBwQos3G6Kn3x6xP
199
- */
@@ -1,4 +0,0 @@
1
- <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
2
- <playground version='5.0' target-platform='osx' display-mode='rendered'>
3
- <timeline fileName='timeline.xctimeline'/>
4
- </playground>
@@ -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