playgroundbook 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +50 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +2 -0
  5. data/.ruby-version +1 -0
  6. data/Changelog.md +17 -0
  7. data/Gemfile +12 -0
  8. data/Gemfile.lock +103 -0
  9. data/Guardfile +14 -0
  10. data/LICENSE +21 -0
  11. data/README.md +92 -0
  12. data/Rakefile +8 -0
  13. data/bin/playgroundbook +22 -0
  14. data/lib/playgroundbook.rb +9 -0
  15. data/lib/playgroundbook_lint/abstract_linter.rb +23 -0
  16. data/lib/playgroundbook_lint/chapter_linter.rb +34 -0
  17. data/lib/playgroundbook_lint/chapter_manifest_linter.rb +43 -0
  18. data/lib/playgroundbook_lint/contents_linter.rb +20 -0
  19. data/lib/playgroundbook_lint/cutscene_page_linter.rb +17 -0
  20. data/lib/playgroundbook_lint/cutscene_page_manifest_linter.rb +18 -0
  21. data/lib/playgroundbook_lint/manifest_linter.rb +39 -0
  22. data/lib/playgroundbook_lint/page_linter.rb +23 -0
  23. data/lib/playgroundbook_lint/page_manifest_linter.rb +18 -0
  24. data/lib/playgroundbook_lint/playgroundbook_lint.rb +31 -0
  25. data/lib/playgroundbook_lint/root_manifest_linter.rb +36 -0
  26. data/lib/playgroundbook_renderer/chapter_collator.rb +77 -0
  27. data/lib/playgroundbook_renderer/contents_manifest_generator.rb +33 -0
  28. data/lib/playgroundbook_renderer/page_writer.rb +34 -0
  29. data/lib/playgroundbook_renderer/playgroundbook_renderer.rb +75 -0
  30. data/lib/version.rb +3 -0
  31. data/playground_book_lint.gemspec +21 -0
  32. data/spec/fixtures/Starter.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Manifest.plist +15 -0
  33. data/spec/fixtures/Starter.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Pages/Page1.playgroundpage/Contents.swift +8 -0
  34. data/spec/fixtures/Starter.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Pages/Page1.playgroundpage/Manifest.plist +12 -0
  35. data/spec/fixtures/Starter.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Pages/Page2.playgroundpage/Contents.swift +8 -0
  36. data/spec/fixtures/Starter.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Pages/Page2.playgroundpage/Manifest.plist +12 -0
  37. data/spec/fixtures/Starter.playgroundbook/Contents/Manifest.plist +20 -0
  38. data/spec/fixtures/assets/file.jpeg +0 -0
  39. data/spec/fixtures/book.yml +5 -0
  40. data/spec/fixtures/test_chapter.playground/Contents.swift +17 -0
  41. data/spec/fixtures/test_chapter.playground/contents.xcplayground +4 -0
  42. data/spec/playground_book_lint/chapter_linter_spec.rb +30 -0
  43. data/spec/playground_book_lint/chapter_manifest_linter_spec.rb +40 -0
  44. data/spec/playground_book_lint/contents_linter_spec.rb +18 -0
  45. data/spec/playground_book_lint/cutscene_page_linter_spec.rb +14 -0
  46. data/spec/playground_book_lint/cutscene_page_manifest_linter_spec.rb +63 -0
  47. data/spec/playground_book_lint/manfiest_linter_spec.rb +71 -0
  48. data/spec/playground_book_lint/page_linter_spec.rb +19 -0
  49. data/spec/playground_book_lint/page_manifest_linter_spec.rb +43 -0
  50. data/spec/playground_book_lint/playgroundbook_lint_spec.rb +38 -0
  51. data/spec/playground_book_lint/root_manifest_linter_spec.rb +35 -0
  52. data/spec/playgroundbook_renderer_spec/chapter_collator_spec.rb +70 -0
  53. data/spec/playgroundbook_renderer_spec/contents_manfiest_generator_spec.rb +37 -0
  54. data/spec/playgroundbook_renderer_spec/page_writer_spec.rb +57 -0
  55. data/spec/playgroundbook_renderer_spec/playgroundbook_renderer_spec.rb +112 -0
  56. data/spec/spec_helper.rb +75 -0
  57. metadata +141 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 50c5634d2dc4a7cc4835cb8f22d8635e5d6af5b9
4
+ data.tar.gz: a63778b8a2f1ff34a8574eb32b248e4cfc9e5c37
5
+ SHA512:
6
+ metadata.gz: 1ef0dd0789b88d8e532cfc15012b46e041ab8d9ade116e017dfe89661283498f88e8c32551526a95f5233173b37c6513d0cbcb853267e252a8b33c093ee5ace4
7
+ data.tar.gz: 71b69a509bfc4d797cc8bec0411e8781fc88232b17f5f7846a342cc35d1f7a811596f073f33ec369a7077e771a3301bd544456c562032ee067618d6a3c3a33aa
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ Metrics/LineLength:
2
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.1.1
data/Changelog.md ADDED
@@ -0,0 +1,17 @@
1
+ # Current Master
2
+
3
+ - Nothing yet.
4
+
5
+ # 0.2.0
6
+
7
+ - Book rendering.
8
+ - Book linting moved to subcommand.
9
+
10
+ # 0.1.0
11
+
12
+ - Adds support for linting manifest file optional values. See [#3](https://github.com/ashfurrow/playground-book-lint/issues/3). - @rpowelll
13
+ - Adds support for playground cutscene linting. See [#9](https://github.com/ashfurrow/playground-book-lint/issues/9). - @rpowelll
14
+
15
+ # 0.0.1
16
+
17
+ - Initial release.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'guard-rspec'
4
+ gem 'mocha'
5
+ gem 'bacon'
6
+ gem 'mocha-on-bacon'
7
+ gem 'prettybacon'
8
+ gem 'fakefs'
9
+ gem 'rubocop', '~> 0.41.2', require: false
10
+
11
+ require 'pp' # https://github.com/defunkt/fakefs/issues/99
12
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,103 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ playground-book-lint (0.2.0)
5
+ colored (~> 1.2)
6
+ cork (~> 0.1)
7
+ plist (~> 3.2)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ ast (2.3.0)
13
+ bacon (1.2.0)
14
+ coderay (1.1.1)
15
+ colored (1.2)
16
+ cork (0.1.0)
17
+ colored (~> 1.2)
18
+ diff-lcs (1.2.5)
19
+ fakefs (0.9.0)
20
+ ffi (1.9.10)
21
+ formatador (0.2.5)
22
+ guard (2.14.0)
23
+ formatador (>= 0.2.4)
24
+ listen (>= 2.7, < 4.0)
25
+ lumberjack (~> 1.0)
26
+ nenv (~> 0.1)
27
+ notiffany (~> 0.0)
28
+ pry (>= 0.9.12)
29
+ shellany (~> 0.0)
30
+ thor (>= 0.18.1)
31
+ guard-compat (1.2.1)
32
+ guard-rspec (4.7.2)
33
+ guard (~> 2.1)
34
+ guard-compat (~> 1.1)
35
+ rspec (>= 2.99.0, < 4.0)
36
+ listen (3.0.7)
37
+ rb-fsevent (>= 0.9.3)
38
+ rb-inotify (>= 0.9.7)
39
+ lumberjack (1.0.10)
40
+ metaclass (0.0.4)
41
+ method_source (0.8.2)
42
+ mocha (1.1.0)
43
+ metaclass (~> 0.0.1)
44
+ mocha-on-bacon (0.2.2)
45
+ mocha (>= 0.13.0)
46
+ nenv (0.3.0)
47
+ notiffany (0.1.0)
48
+ nenv (~> 0.1)
49
+ shellany (~> 0.0)
50
+ parser (2.3.1.2)
51
+ ast (~> 2.2)
52
+ plist (3.2.0)
53
+ powerpack (0.1.1)
54
+ prettybacon (0.0.2)
55
+ bacon (~> 1.2)
56
+ pry (0.10.3)
57
+ coderay (~> 1.1.0)
58
+ method_source (~> 0.8.1)
59
+ slop (~> 3.4)
60
+ rainbow (2.1.0)
61
+ rb-fsevent (0.9.7)
62
+ rb-inotify (0.9.7)
63
+ ffi (>= 0.5.0)
64
+ rspec (3.5.0)
65
+ rspec-core (~> 3.5.0)
66
+ rspec-expectations (~> 3.5.0)
67
+ rspec-mocks (~> 3.5.0)
68
+ rspec-core (3.5.1)
69
+ rspec-support (~> 3.5.0)
70
+ rspec-expectations (3.5.0)
71
+ diff-lcs (>= 1.2.0, < 2.0)
72
+ rspec-support (~> 3.5.0)
73
+ rspec-mocks (3.5.0)
74
+ diff-lcs (>= 1.2.0, < 2.0)
75
+ rspec-support (~> 3.5.0)
76
+ rspec-support (3.5.0)
77
+ rubocop (0.41.2)
78
+ parser (>= 2.3.1.1, < 3.0)
79
+ powerpack (~> 0.1)
80
+ rainbow (>= 1.99.1, < 3.0)
81
+ ruby-progressbar (~> 1.7)
82
+ unicode-display_width (~> 1.0, >= 1.0.1)
83
+ ruby-progressbar (1.8.1)
84
+ shellany (0.0.1)
85
+ slop (3.6.0)
86
+ thor (0.19.1)
87
+ unicode-display_width (1.1.0)
88
+
89
+ PLATFORMS
90
+ ruby
91
+
92
+ DEPENDENCIES
93
+ bacon
94
+ fakefs
95
+ guard-rspec
96
+ mocha
97
+ mocha-on-bacon
98
+ playground-book-lint!
99
+ prettybacon
100
+ rubocop (~> 0.41.2)
101
+
102
+ BUNDLED WITH
103
+ 1.12.5
data/Guardfile ADDED
@@ -0,0 +1,14 @@
1
+ guard :rspec, cmd: 'bundle exec rspec' do
2
+ require 'guard/rspec/dsl'
3
+ dsl = Guard::RSpec::Dsl.new(self)
4
+
5
+ # RSpec files
6
+ rspec = dsl.rspec
7
+ watch(rspec.spec_helper) { rspec.spec_dir }
8
+ watch(rspec.spec_support) { rspec.spec_dir }
9
+ watch(rspec.spec_files)
10
+
11
+ # Ruby files
12
+ ruby = dsl.ruby
13
+ dsl.watch_spec_files_for(ruby.lib_files)
14
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ash Furrow
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,92 @@
1
+ [![CircleCI](https://circleci.com/gh/ashfurrow/playground-book-lint.svg?style=svg)](https://circleci.com/gh/ashfurrow/playground-book-lint)
2
+
3
+ # playgroundbook
4
+
5
+ Linter for Swift Playground books based on [Apple's documentation](https://developer.apple.com/library/prerelease/content/documentation/Xcode/Conceptual/swift_playgrounds_doc_format/index.html#//apple_ref/doc/uid/TP40017343-CH47-SW4). It's a work in progress (see [issues](https://github.com/ashfurrow/playground-book-lint/issues)) but you can use it now.
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ > [sudo] gem install playgroundbook
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ To lint an existing playground book:
16
+
17
+ ```sh
18
+ > playgroundbook lint MyPlaygroundbook.playgroundbook
19
+ ```
20
+
21
+ To generate a playground book:
22
+
23
+ ```sh
24
+ > playgroundbook render book.yaml
25
+ ```
26
+
27
+ The yml file should be in the following format:
28
+
29
+ ```yaml
30
+ name: Testing book
31
+ identifier: com.ashfurrow.example
32
+ resources: assets # Optional
33
+ deployment_target: ios10.0 # Optional
34
+ imports: # Optional, defaults to UIKit
35
+ - UIKit
36
+ - CoreGraphics
37
+ chapters:
38
+ - Chapter 1
39
+ - Chapter 2
40
+ - etc...
41
+ ```
42
+
43
+ Each chapter needs to have a corresponding playground; so `Chapter 1` requires there be a `Chapter 1.playground` playground. The playgrounds can reference (not copy) resources from an optionally specified directory. `import` frameworks are specified in the yaml file and are added to every page of the book. Each chapter needs to be in the following format:
44
+
45
+ ```swift
46
+ // This is the preamble that is shared among all the pages within this chapter.
47
+
48
+ func sharedFunc() {
49
+ print("This should be accessible to all pages.")
50
+ }
51
+
52
+ //// Page 1
53
+
54
+ str = "Yo, it's page 1."
55
+ sharedFunc()
56
+
57
+ //// Page 2
58
+
59
+ sharedFunc()
60
+ str = "Page 2 awww yeah."
61
+ ```
62
+
63
+ Pages are divided by lines beginning with a quadruple slash, followed by that pages name.
64
+
65
+ ### Limitations of Book Rendering
66
+
67
+ Preamble (anything about the first `////` page) is put in its own file. That means declarations there need to be `public` to be visible within individual pages (even though when you're writing, everything is in one file). Additionally, the preamble is at the top-level and can't contain experessions. This would cause a compiler error in the Swift Playrounds iPad app:
68
+
69
+ ```swift
70
+ public let layout = UICollectionViewFlowLayout()
71
+ layout.itemSize = CGSize(width: 20, height: 20)
72
+ ```
73
+
74
+ Instead, you have to wrap it in a closure, like this:
75
+
76
+ ```swift
77
+ public var layout: UICollectionViewFlowLayout = {
78
+ let layout = UICollectionViewFlowLayout()
79
+ layout.itemSize = CGSize(width: 20, height: 20)
80
+ return layout
81
+ }()
82
+ ```
83
+
84
+ It's awkward; if you have suggestions, open an issue :+1:
85
+
86
+ Sharing resources is only available book-wide and not specific to chapters. Sharing code outside the preamble isn't supported yet.
87
+
88
+ Playground books support a rich set of awesome features to make learning how to code really easy, and this tool uses almost none of them. It sacrifices this experience for the sake of being able to easily write the books on your Mac.
89
+
90
+ ## License
91
+
92
+ MIT, except for the `starter.playgroundbook` in the unit tests, which is licensed by Apple.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :spec
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ unless ARGV.length >= 2
4
+ puts 'You must specify either lint or render. Example usage:'
5
+ puts ' playgroundbook [lint|render] file_name'
6
+ exit 1
7
+ end
8
+
9
+ command = ARGV[0]
10
+ file_name = ARGV[1]
11
+
12
+ require 'playgroundbook'
13
+
14
+ if command == 'lint'
15
+ Playgroundbook::Linter.new(file_name).lint
16
+ elsif command == 'render'
17
+ Playgroundbook::Renderer.new(file_name).render!
18
+ else
19
+ puts "Unknown command: #{command}"
20
+ exit 1
21
+ end
22
+
@@ -0,0 +1,9 @@
1
+ require 'playgroundbook_lint/playgroundbook_lint'
2
+ require 'playgroundbook_renderer/playgroundbook_renderer'
3
+
4
+ module Playgroundbook
5
+ ManifestFileName = 'Manifest.plist'.freeze
6
+ ContentsSwiftFileName = 'Contents.swift'.freeze
7
+ ResourcesDirectoryName = 'Resources'.freeze
8
+ PagesDirectoryName = 'Pages'.freeze
9
+ end
@@ -0,0 +1,23 @@
1
+ require 'colored'
2
+ require 'cork'
3
+
4
+ module Playgroundbook
5
+ # AbstractLinter provides a base implementation of a linter which a concrete
6
+ # linter subclass can inherit from
7
+ class AbstractLinter
8
+ @ui = Cork::Board.new
9
+
10
+ class << self
11
+ attr_accessor :ui
12
+ end
13
+
14
+ def fail_lint(msg)
15
+ AbstractLinter.ui.puts msg.red
16
+ exit 1
17
+ end
18
+
19
+ def message(msg)
20
+ AbstractLinter.ui.puts msg
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,34 @@
1
+ require 'plist'
2
+ require 'playgroundbook_lint/abstract_linter'
3
+ require 'playgroundbook_lint/chapter_manifest_linter'
4
+
5
+ module Playgroundbook
6
+ PAGES_DIRECTORY_NAME = 'Pages'.freeze
7
+
8
+ # A linter for verifying a chapter directory
9
+ class ChapterLinter < AbstractLinter
10
+ attr_accessor :chapter_manifest_linter
11
+
12
+ def initialize(chapter_manifest_linter = ChapterManifestLinter.new)
13
+ @chapter_manifest_linter = chapter_manifest_linter
14
+ end
15
+
16
+ def lint(chapter_directory_name)
17
+ fail_lint "Chapter specified in manifest does not exist: #{chapter_directory_name}." unless chapter_directory_exists?(chapter_directory_name)
18
+
19
+ Dir.chdir chapter_directory_name do
20
+ fail_lint "Pages directory in chapter does not exist: #{chapter_directory_name}." unless pages_directory_exists?
21
+
22
+ chapter_manifest_linter.lint
23
+ end
24
+ end
25
+
26
+ def chapter_directory_exists?(chapter_directory_name)
27
+ Dir.exist? chapter_directory_name
28
+ end
29
+
30
+ def pages_directory_exists?
31
+ Dir.exist? PAGES_DIRECTORY_NAME
32
+ end
33
+ end
34
+ end