swift-playground 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.ruby-version +1 -0
  4. data/Gemfile +19 -0
  5. data/LICENSE +22 -0
  6. data/README.md +209 -0
  7. data/Rakefile +16 -0
  8. data/bin/swift-playground +5 -0
  9. data/lib/swift/playground.rb +193 -0
  10. data/lib/swift/playground/asset.rb +52 -0
  11. data/lib/swift/playground/assets/javascript.rb +9 -0
  12. data/lib/swift/playground/assets/stylesheet.rb +36 -0
  13. data/lib/swift/playground/cli.rb +29 -0
  14. data/lib/swift/playground/cli/commands/generate.rb +95 -0
  15. data/lib/swift/playground/cli/commands/new.rb +49 -0
  16. data/lib/swift/playground/cli/definition.rb +32 -0
  17. data/lib/swift/playground/cli/global/error_handling.rb +34 -0
  18. data/lib/swift/playground/cli/shared_attributes.rb +19 -0
  19. data/lib/swift/playground/cli/ui.rb +120 -0
  20. data/lib/swift/playground/debug.rb +4 -0
  21. data/lib/swift/playground/generator.rb +32 -0
  22. data/lib/swift/playground/metadata.rb +12 -0
  23. data/lib/swift/playground/section.rb +117 -0
  24. data/lib/swift/playground/sections/code_section.rb +19 -0
  25. data/lib/swift/playground/sections/documentation_section.rb +63 -0
  26. data/lib/swift/playground/template/Documentation/defaults.css.scss +96 -0
  27. data/lib/swift/playground/template/Documentation/section.html.erb +23 -0
  28. data/lib/swift/playground/template/contents.xcplayground.erb +8 -0
  29. data/lib/swift/playground/util.rb +3 -0
  30. data/lib/swift/playground/util/path_or_content.rb +31 -0
  31. data/lib/swift/playground/util/pipeline.rb +53 -0
  32. data/lib/swift/playground/util/pipeline/section_filter.rb +55 -0
  33. data/lib/swift/playground/util/pipeline/unicode_emoji_filter.rb +27 -0
  34. data/lib/swift/playground/util/syntax_highlighting.rb +24 -0
  35. data/swift-playground.gemspec +29 -0
  36. metadata +207 -0
@@ -0,0 +1,55 @@
1
+ require 'html/pipeline'
2
+
3
+ module Swift::Playground::Util
4
+ class Pipeline
5
+ class SectionFilter < HTML::Pipeline::Filter
6
+ def call
7
+ # Solution derived from http://stackoverflow.com/a/4799902
8
+ children = doc.children # Every immediate child of the doc
9
+ doc.inner_html = '' # Empty the doc now that we have our nodes
10
+
11
+ # Comments preceding a swift code section can have meaning, so we need
12
+ # to track the last comment made:
13
+ last_comment = nil
14
+ section = new_section(doc) # Create our first container in the doc
15
+ children.each do |node|
16
+ if node.name == 'comment'
17
+ last_comment = node.content.strip
18
+ elsif node.name == 'pre' && node[:lang] == 'swift' && last_comment != 'IGNORE'
19
+ # If this code is the first thing in the document then the previous
20
+ # section will be empty and the only child of the document, so we
21
+ # should remove it:
22
+ section.remove if section.content.empty? && doc.children.count == 1
23
+
24
+ swift_section = new_section(doc, role: 'code')
25
+ swift_section[:title] = last_comment unless last_comment.blank?
26
+ node.remove_attribute('lang')
27
+ swift_section << node
28
+
29
+ section = new_section(doc) # Create a new container for subsequent nodes
30
+ else
31
+ last_comment = nil unless node.name == 'text' && node.content.blank?
32
+ section << node
33
+ end
34
+ end
35
+ section.remove if section.content.empty? # Get rid of a trailing, empty section
36
+
37
+ doc
38
+ end
39
+
40
+ private
41
+
42
+ def new_section(doc, attributes = {})
43
+ attributes = {
44
+ role: 'documentation'
45
+ }.merge(attributes)
46
+
47
+ section = (doc << '<section>').children.last
48
+ attributes.each do |attribute, value|
49
+ section[attribute] = value
50
+ end
51
+ section
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,27 @@
1
+ require 'html/pipeline'
2
+
3
+ module Swift::Playground::Util
4
+ class Pipeline
5
+ class UnicodeEmojiFilter < HTML::Pipeline::EmojiFilter
6
+
7
+ def validate
8
+ # No need to for :asset_root in context like EmojiFilter requires
9
+ end
10
+
11
+ # Override EmojiFilter's image replacement to replace with Unicode instead:
12
+ def emoji_image_filter(text)
13
+ text.gsub(emoji_pattern) do |match|
14
+ name = $1
15
+ "<span class='emoji'>#{emoji_unicode_replacement(name)}</span>"
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def emoji_unicode_replacement(name)
22
+ Emoji.find_by_alias(name).raw
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,24 @@
1
+ require 'pygments'
2
+
3
+ module Swift
4
+ class Playground
5
+ module Util
6
+ class SyntaxHighlighting
7
+ class << self
8
+ def available?
9
+ Gem::Specification::find_all_by_name('github-linguist').any? &&
10
+ Gem::Specification::find_all_by_name('pygments.rb').any?
11
+ end
12
+
13
+ def css(style = 'default')
14
+ if available?
15
+ Pygments.css('.highlight', style: style)
16
+ else
17
+ ''
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,29 @@
1
+ # Ensure we require the local version and not one we might have installed already
2
+ require File.join([File.dirname(__FILE__), 'lib', 'swift', 'playground', 'metadata.rb'])
3
+ spec = Gem::Specification.new do |s|
4
+ s.name = 'swift-playground'
5
+ s.version = Swift::Playground::VERSION
6
+ s.authors = ['Mark Haylock']
7
+ s.email = ['mark@resolvedigital.co.nz']
8
+ s.homepage = 'https://github.com/resolve/swift-playground'
9
+ s.license = 'MIT'
10
+ s.summary = Swift::Playground::SUMMARY
11
+ s.description = Swift::Playground::DESCRIPTION
12
+
13
+ s.files = `git ls-files -z`.split("\x0")
14
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
16
+ s.require_paths = ['lib']
17
+
18
+ s.required_ruby_version = '>= 2.0.0'
19
+
20
+ s.add_runtime_dependency 'html-pipeline', '~> 1.11'
21
+ s.add_runtime_dependency 'activesupport', '~> 4.0'
22
+ s.add_runtime_dependency 'github-markdown', '~> 0.6.7'
23
+ s.add_runtime_dependency 'sanitize', '~> 3.0'
24
+ s.add_runtime_dependency 'gemoji', '~> 2.1.0'
25
+ s.add_runtime_dependency 'gli', '~> 2.12.2'
26
+ s.add_runtime_dependency 'paint', '~> 0.9.0'
27
+ s.add_runtime_dependency 'highline', '~> 1.6.21'
28
+ s.add_runtime_dependency 'sass', '~> 3.4.10'
29
+ end
metadata ADDED
@@ -0,0 +1,207 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: swift-playground
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mark Haylock
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: html-pipeline
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: github-markdown
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.6.7
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.6.7
55
+ - !ruby/object:Gem::Dependency
56
+ name: sanitize
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: gemoji
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 2.1.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 2.1.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: gli
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 2.12.2
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 2.12.2
97
+ - !ruby/object:Gem::Dependency
98
+ name: paint
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 0.9.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 0.9.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: highline
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 1.6.21
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: 1.6.21
125
+ - !ruby/object:Gem::Dependency
126
+ name: sass
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: 3.4.10
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: 3.4.10
139
+ description: A Ruby API and CLI tool for manipulating Xcode Swift Playgrounds. Supports
140
+ generation from markdown files with the intent to aide in the production of polished
141
+ playground documents.
142
+ email:
143
+ - mark@resolvedigital.co.nz
144
+ executables:
145
+ - swift-playground
146
+ extensions: []
147
+ extra_rdoc_files: []
148
+ files:
149
+ - .gitignore
150
+ - .ruby-version
151
+ - Gemfile
152
+ - LICENSE
153
+ - README.md
154
+ - Rakefile
155
+ - bin/swift-playground
156
+ - lib/swift/playground.rb
157
+ - lib/swift/playground/asset.rb
158
+ - lib/swift/playground/assets/javascript.rb
159
+ - lib/swift/playground/assets/stylesheet.rb
160
+ - lib/swift/playground/cli.rb
161
+ - lib/swift/playground/cli/commands/generate.rb
162
+ - lib/swift/playground/cli/commands/new.rb
163
+ - lib/swift/playground/cli/definition.rb
164
+ - lib/swift/playground/cli/global/error_handling.rb
165
+ - lib/swift/playground/cli/shared_attributes.rb
166
+ - lib/swift/playground/cli/ui.rb
167
+ - lib/swift/playground/debug.rb
168
+ - lib/swift/playground/generator.rb
169
+ - lib/swift/playground/metadata.rb
170
+ - lib/swift/playground/section.rb
171
+ - lib/swift/playground/sections/code_section.rb
172
+ - lib/swift/playground/sections/documentation_section.rb
173
+ - lib/swift/playground/template/Documentation/defaults.css.scss
174
+ - lib/swift/playground/template/Documentation/section.html.erb
175
+ - lib/swift/playground/template/contents.xcplayground.erb
176
+ - lib/swift/playground/util.rb
177
+ - lib/swift/playground/util/path_or_content.rb
178
+ - lib/swift/playground/util/pipeline.rb
179
+ - lib/swift/playground/util/pipeline/section_filter.rb
180
+ - lib/swift/playground/util/pipeline/unicode_emoji_filter.rb
181
+ - lib/swift/playground/util/syntax_highlighting.rb
182
+ - swift-playground.gemspec
183
+ homepage: https://github.com/resolve/swift-playground
184
+ licenses:
185
+ - MIT
186
+ metadata: {}
187
+ post_install_message:
188
+ rdoc_options: []
189
+ require_paths:
190
+ - lib
191
+ required_ruby_version: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - '>='
194
+ - !ruby/object:Gem::Version
195
+ version: 2.0.0
196
+ required_rubygems_version: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - '>='
199
+ - !ruby/object:Gem::Version
200
+ version: '0'
201
+ requirements: []
202
+ rubyforge_project:
203
+ rubygems_version: 2.0.14
204
+ signing_key:
205
+ specification_version: 4
206
+ summary: Create Xcode Swift Playgrounds, including generating from Markdown files.
207
+ test_files: []