swift-playground 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{LICENSE → LICENSE.md} +1 -1
- data/README.md +3 -11
- data/lib/swift/playground/asset.rb +2 -2
- data/lib/swift/playground/generator.rb +2 -2
- data/lib/swift/playground/metadata.rb +1 -1
- data/lib/swift/playground/section.rb +2 -2
- data/lib/swift/playground/util.rb +1 -1
- data/lib/swift/playground/util/source_io.rb +24 -0
- data/lib/swift/playground/util/syntax_highlighting.rb +5 -1
- metadata +4 -4
- data/lib/swift/playground/util/path_or_content.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a82e1a693c4fffb926083d9f54ad64e4383b653
|
4
|
+
data.tar.gz: 8398c90bb94f30143c596ad8dfafa8d004407ae8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4b4c7c2d6613b0d10550053cf351914ecdf40f578cae0245c8cf2206014d9e2eba2684ee19b895cec4e72fd260b1ca27e090569febfaf92bde016c1d18b189c
|
7
|
+
data.tar.gz: 1033f44454bf70624b8f71f506df65af411c571ed1fe6e587d5960610d7167786a6d25e0272aa6b9c8e8562f9cfdecbfbb9362746cfa3d9f690c6041b5db6246
|
data/{LICENSE → LICENSE.md}
RENAMED
data/README.md
CHANGED
@@ -24,7 +24,7 @@ Create and modify Xcode Swift Playgrounds from Ruby. Includes both a Ruby API an
|
|
24
24
|
|
25
25
|
Install via RubyGems:
|
26
26
|
```
|
27
|
-
$ gem install playground
|
27
|
+
$ gem install swift-playground
|
28
28
|
```
|
29
29
|
|
30
30
|
## CLI Usage
|
@@ -61,12 +61,6 @@ This command supports the following options (see `swift-playground help generate
|
|
61
61
|
CSS stylesheet for the HTML documentation sections of the playground. [SASS/SCSS syntax](http://sass-lang.com) is supported. This will be included after the default stylesheet. (default: none).
|
62
62
|
* __`--javascript=<file>`__
|
63
63
|
|
64
|
-
A javascript file for the HTML documentation sections of the playground. Each section is rendered independently of another and the script will not have access to the DOM from any other sections (default: none).
|
65
|
-
* __`--[no-]reset`__
|
66
|
-
|
67
|
-
Allow the playground to be reset to it's original state via "Editor > Reset Playground" in Xcode (default: enabled).
|
68
|
-
* __`--open`__
|
69
|
-
|
70
64
|
Open the playground in Xcode once it has been created.
|
71
65
|
* __`--[no-]emoji`__
|
72
66
|
|
@@ -124,11 +118,10 @@ There are two section types you can use to construct a playground in Ruby:
|
|
124
118
|
|
125
119
|
#### `DocumentationSection`
|
126
120
|
|
127
|
-
These contain HTML that is rendered within the playground. You can construct a `DocumentationSection` with either
|
121
|
+
These contain HTML that is rendered within the playground. You can construct a `DocumentationSection` with either an IO object or a string representing the contents of the HTML file:
|
128
122
|
|
129
123
|
```ruby
|
130
124
|
# All of the following are valid values for content:
|
131
|
-
content = '/path/to/file.html'
|
132
125
|
content = Pathname.new('/path/to/file.html')
|
133
126
|
content = File.open('/path/to/file.html')
|
134
127
|
content = <<-HTML
|
@@ -151,11 +144,10 @@ The content you provide _must_ be an HTML fragment - if a `<html>`, `<head>` or
|
|
151
144
|
|
152
145
|
#### `CodeSection`
|
153
146
|
|
154
|
-
These contain the executable swift code, and each playground must contain at least one of these sections. Constructing these sections is the same as `DocumentationSection` - you can use either
|
147
|
+
These contain the executable swift code, and each playground must contain at least one of these sections. Constructing these sections is the same as `DocumentationSection` - you can use either an IO object or a string representing the contents of the swift file:
|
155
148
|
|
156
149
|
```ruby
|
157
150
|
# All of the following are valid values for content:
|
158
|
-
content = '/path/to/file.swift'
|
159
151
|
content = Pathname.new('/path/to/file.swift')
|
160
152
|
content = File.open('/path/to/file.swift')
|
161
153
|
content = <<-SWIFT
|
@@ -5,7 +5,7 @@ module Swift
|
|
5
5
|
autoload :Javascript, assets_path.join('javascript')
|
6
6
|
|
7
7
|
class Asset
|
8
|
-
include Util::
|
8
|
+
include Util::SourceIO
|
9
9
|
|
10
10
|
class << self
|
11
11
|
protected
|
@@ -19,7 +19,7 @@ module Swift
|
|
19
19
|
attr_accessor :content
|
20
20
|
|
21
21
|
def initialize(content, options = {})
|
22
|
-
pathname_or_content =
|
22
|
+
pathname_or_content = source_as_io(content)
|
23
23
|
self.content = pathname_or_content.read
|
24
24
|
|
25
25
|
filename = options[:filename] || derived_filename(pathname_or_content)
|
@@ -4,10 +4,10 @@ module Swift
|
|
4
4
|
class Playground
|
5
5
|
class Generator
|
6
6
|
class << self
|
7
|
-
include Util::
|
7
|
+
include Util::SourceIO
|
8
8
|
|
9
9
|
def generate(markdown, options={})
|
10
|
-
markdown_file =
|
10
|
+
markdown_file = source_as_io(markdown)
|
11
11
|
|
12
12
|
playground = Playground.new
|
13
13
|
|
@@ -7,7 +7,7 @@ module Swift
|
|
7
7
|
autoload :CodeSection, sections_path.join('code_section')
|
8
8
|
|
9
9
|
class Section
|
10
|
-
include Util::
|
10
|
+
include Util::SourceIO
|
11
11
|
|
12
12
|
class TemplateContext
|
13
13
|
attr_accessor :content, :number
|
@@ -68,7 +68,7 @@ module Swift
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def initialize(content)
|
71
|
-
@content =
|
71
|
+
@content = source_as_io(content).read
|
72
72
|
@content.freeze
|
73
73
|
end
|
74
74
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module Swift::Playground::Util
|
4
|
+
module SourceIO
|
5
|
+
def source_as_io(source)
|
6
|
+
# Return path_or_content if it is an IO-like object
|
7
|
+
return source if source.respond_to?(:read)
|
8
|
+
|
9
|
+
unless source.is_a?(String)
|
10
|
+
raise "You must provide either a String or an IO object when constructing a #{self.class.name}."
|
11
|
+
end
|
12
|
+
|
13
|
+
StringIO.new(source)
|
14
|
+
end
|
15
|
+
|
16
|
+
def derived_filename(source)
|
17
|
+
if source.respond_to?(:basename)
|
18
|
+
source.basename.to_s
|
19
|
+
elsif source.respond_to?(:path)
|
20
|
+
File.basename(source.path)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swift-playground
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Haylock
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: html-pipeline
|
@@ -149,7 +149,7 @@ files:
|
|
149
149
|
- .gitignore
|
150
150
|
- .ruby-version
|
151
151
|
- Gemfile
|
152
|
-
- LICENSE
|
152
|
+
- LICENSE.md
|
153
153
|
- README.md
|
154
154
|
- Rakefile
|
155
155
|
- bin/swift-playground
|
@@ -174,10 +174,10 @@ files:
|
|
174
174
|
- lib/swift/playground/template/Documentation/section.html.erb
|
175
175
|
- lib/swift/playground/template/contents.xcplayground.erb
|
176
176
|
- lib/swift/playground/util.rb
|
177
|
-
- lib/swift/playground/util/path_or_content.rb
|
178
177
|
- lib/swift/playground/util/pipeline.rb
|
179
178
|
- lib/swift/playground/util/pipeline/section_filter.rb
|
180
179
|
- lib/swift/playground/util/pipeline/unicode_emoji_filter.rb
|
180
|
+
- lib/swift/playground/util/source_io.rb
|
181
181
|
- lib/swift/playground/util/syntax_highlighting.rb
|
182
182
|
- swift-playground.gemspec
|
183
183
|
homepage: https://github.com/resolve/swift-playground
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
|
3
|
-
module Swift::Playground::Util
|
4
|
-
module PathOrContent
|
5
|
-
def path_or_content_as_io(path_or_content)
|
6
|
-
# Return path_or_content if it is an IO-like object
|
7
|
-
return path_or_content if path_or_content.respond_to?(:read)
|
8
|
-
|
9
|
-
unless path_or_content.is_a?(String)
|
10
|
-
raise "You must provide either a String or an IO object when constructing a #{self.class.name}."
|
11
|
-
end
|
12
|
-
|
13
|
-
if path_or_content !~ /[^\n]/ && !path_or_content.blank?
|
14
|
-
path = Pathname.new(path_or_content).expand_path
|
15
|
-
return path if path.exist?
|
16
|
-
|
17
|
-
raise "Path '#{path}' not found. Please add a newline to any raw content."
|
18
|
-
else
|
19
|
-
StringIO.new(path_or_content)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def derived_filename(pathname_or_content)
|
24
|
-
if pathname_or_content.respond_to?(:basename)
|
25
|
-
pathname_or_content.basename.to_s
|
26
|
-
elsif pathname_or_content.respond_to?(:path)
|
27
|
-
File.basename(pathname_or_content.path)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|