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.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/Rakefile +1 -0
- data/Readme.markdownd +17 -0
- data/bin/playground +7 -0
- data/lib/playground.rb +5 -0
- data/lib/playground/cli.rb +11 -0
- data/lib/playground/data/contents.xcplayground.erb +6 -0
- data/lib/playground/data/section.html.erb +21 -0
- data/lib/playground/data/style.css +2225 -0
- data/lib/playground/generator.rb +87 -0
- data/lib/playground/version.rb +3 -0
- data/playground.gemspec +24 -0
- metadata +87 -0
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'erb'
|
3
|
+
require 'ostruct'
|
4
|
+
require 'cgi'
|
5
|
+
require 'redcarpet'
|
6
|
+
|
7
|
+
module Playground
|
8
|
+
class Generator
|
9
|
+
def generate(input, output)
|
10
|
+
@input = input
|
11
|
+
@output = output
|
12
|
+
|
13
|
+
# Remove anything already there
|
14
|
+
FileUtils.rm_rf(@output)
|
15
|
+
|
16
|
+
# Make folders
|
17
|
+
@doc_dir = @output + '/Documentation'
|
18
|
+
FileUtils.mkdir_p(@doc_dir)
|
19
|
+
|
20
|
+
# Copy stylesheet
|
21
|
+
@data_dir = File.expand_path('../data', __FILE__)
|
22
|
+
FileUtils.cp(@data_dir + '/style.css', @doc_dir)
|
23
|
+
|
24
|
+
# Setup
|
25
|
+
section = 1
|
26
|
+
@contents_sections = []
|
27
|
+
html = ''
|
28
|
+
|
29
|
+
# Parse markdown
|
30
|
+
chunks = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new).render(File.read(input)).split("\n\n")
|
31
|
+
|
32
|
+
# Loop through chunks
|
33
|
+
chunks.each do |chunk|
|
34
|
+
# Code
|
35
|
+
if chunk.start_with?('<pre><code>')
|
36
|
+
if html.length > 0
|
37
|
+
write_html(html, section)
|
38
|
+
section += 1
|
39
|
+
end
|
40
|
+
|
41
|
+
swift = CGI.unescapeHTML(chunk[11, chunk.length - 11 - 13])
|
42
|
+
write_swift(swift, section)
|
43
|
+
section += 1
|
44
|
+
html = ''
|
45
|
+
# HTML
|
46
|
+
else
|
47
|
+
html << chunk + "\n\n"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Write any remaining HTML
|
52
|
+
if html.length > 0
|
53
|
+
write_html(html, section)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Create contents
|
57
|
+
contents = erb(@data_dir + '/contents.xcplayground.erb', { sdk: 'macosx', sections: @contents_sections.join("\n ") })
|
58
|
+
File.write(output + '/contents.xcplayground', contents)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Write an HTML file to the output package and add its metadata to the contents
|
62
|
+
def write_html(html, section)
|
63
|
+
filename = "section-#{section.to_s.rjust(3, '0')}.html"
|
64
|
+
@contents_sections << %Q{<documentation relative-path="#{filename}"/>}
|
65
|
+
|
66
|
+
html = html[0, html.length - 2]
|
67
|
+
html = erb(@data_dir + '/section.html.erb', { title: filename, content: html })
|
68
|
+
File.write(@doc_dir + "/#{filename}", html)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Write a Swift file to the output package and add its metadata to the contents
|
72
|
+
def write_swift(swift, section)
|
73
|
+
filename = "section-#{section.to_s.rjust(3, '0')}.swift"
|
74
|
+
@contents_sections << %Q{<code source-file-name="#{filename}"/>}
|
75
|
+
|
76
|
+
File.write(@output + "/#{filename}", swift)
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
# Render an ERB template
|
82
|
+
def erb(template_path, vars)
|
83
|
+
template = File.read(template_path)
|
84
|
+
ERB.new(template).result(OpenStruct.new(vars).instance_eval { binding })
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/playground.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'playground/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'playground'
|
8
|
+
spec.version = Playground::VERSION
|
9
|
+
spec.authors = ['Sam Soffes']
|
10
|
+
spec.email = ['sam@soff.es']
|
11
|
+
spec.summary = 'A simple utility for converting Markdown into Swift playgrounds.'
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = 'https://github.com/soffes/playground'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.required_ruby_version = '>= 1.9.2'
|
22
|
+
spec.add_dependency 'redcarpet'
|
23
|
+
spec.add_dependency 'thor'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: playground
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sam Soffes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: redcarpet
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: A simple utility for converting Markdown into Swift playgrounds.
|
42
|
+
email:
|
43
|
+
- sam@soff.es
|
44
|
+
executables:
|
45
|
+
- playground
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE
|
52
|
+
- Rakefile
|
53
|
+
- Readme.markdownd
|
54
|
+
- bin/playground
|
55
|
+
- lib/playground.rb
|
56
|
+
- lib/playground/cli.rb
|
57
|
+
- lib/playground/data/contents.xcplayground.erb
|
58
|
+
- lib/playground/data/section.html.erb
|
59
|
+
- lib/playground/data/style.css
|
60
|
+
- lib/playground/generator.rb
|
61
|
+
- lib/playground/version.rb
|
62
|
+
- playground.gemspec
|
63
|
+
homepage: https://github.com/soffes/playground
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.9.2
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.2.2
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: A simple utility for converting Markdown into Swift playgrounds.
|
87
|
+
test_files: []
|