Class: Swift::Playground
- Inherits:
-
Object
- Object
- Swift::Playground
- Defined in:
- lib/swift/playground.rb,
lib/swift/playground/cli.rb,
lib/swift/playground/asset.rb,
lib/swift/playground/section.rb,
lib/swift/playground/metadata.rb,
lib/swift/playground/generator.rb,
lib/swift/playground/assets/javascript.rb,
lib/swift/playground/assets/stylesheet.rb,
lib/swift/playground/sections/code_section.rb,
lib/swift/playground/util/syntax_highlighting.rb,
lib/swift/playground/sections/documentation_section.rb
Defined Under Namespace
Modules: CLI, Util Classes: Asset, CodeSection, DocumentationSection, Generator, Javascript, Section, Stylesheet, TemplateContext
Constant Summary collapse
- NAME =
'swift-playground'
- SUMMARY =
'Create Xcode Swift Playgrounds, including generating from ' \ 'Markdown files.'
- DESCRIPTION =
'A Ruby API and CLI tool for manipulating Xcode Swift ' \ 'Playgrounds. Supports generation from markdown files ' \ 'with the intent to aide in the production of polished ' \ 'playground documents.'
- VERSION =
'0.0.1'
Instance Attribute Summary collapse
-
#allow_reset ⇒ Object
Returns the value of attribute allow_reset.
-
#convert_emoji ⇒ Object
Returns the value of attribute convert_emoji.
-
#javascripts ⇒ Object
Returns the value of attribute javascripts.
-
#platform ⇒ Object
Returns the value of attribute platform.
-
#sections ⇒ Object
Returns the value of attribute sections.
-
#stylesheets ⇒ Object
Returns the value of attribute stylesheets.
-
#syntax_highlighting ⇒ Object
Returns the value of attribute syntax_highlighting.
Instance Method Summary collapse
- #allows_reset? ⇒ Boolean
- #convert_emoji? ⇒ Boolean
-
#initialize(options = {}) ⇒ Playground
constructor
A new instance of Playground.
- #save(destination_path) ⇒ Object
- #sdk ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Playground
Returns a new instance of Playground.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/swift/playground.rb', line 46 def initialize( = {}) self.sections = [] self.stylesheets = [] self.javascripts = [] stylesheet_path = template_path 'Documentation', 'defaults.css.scss' self.stylesheets << Stylesheet.new(stylesheet_path) = { platform: 'ios', allow_reset: true, convert_emoji: true, syntax_highlighting: true }.merge() self.platform = [:platform] self.allow_reset = [:allow_reset] self.convert_emoji = [:convert_emoji] self.syntax_highlighting = [:syntax_highlighting] end |
Instance Attribute Details
#allow_reset ⇒ Object
Returns the value of attribute allow_reset.
25 26 27 |
# File 'lib/swift/playground.rb', line 25 def allow_reset @allow_reset end |
#convert_emoji ⇒ Object
Returns the value of attribute convert_emoji.
25 26 27 |
# File 'lib/swift/playground.rb', line 25 def convert_emoji @convert_emoji end |
#javascripts ⇒ Object
Returns the value of attribute javascripts.
26 27 28 |
# File 'lib/swift/playground.rb', line 26 def javascripts @javascripts end |
#platform ⇒ Object
Returns the value of attribute platform.
25 26 27 |
# File 'lib/swift/playground.rb', line 25 def platform @platform end |
#sections ⇒ Object
Returns the value of attribute sections.
26 27 28 |
# File 'lib/swift/playground.rb', line 26 def sections @sections end |
#stylesheets ⇒ Object
Returns the value of attribute stylesheets.
26 27 28 |
# File 'lib/swift/playground.rb', line 26 def stylesheets @stylesheets end |
#syntax_highlighting ⇒ Object
Returns the value of attribute syntax_highlighting.
25 26 27 |
# File 'lib/swift/playground.rb', line 25 def syntax_highlighting @syntax_highlighting end |
Instance Method Details
#allows_reset? ⇒ Boolean
82 83 84 |
# File 'lib/swift/playground.rb', line 82 def allows_reset? allow_reset == true end |
#convert_emoji? ⇒ Boolean
86 87 88 |
# File 'lib/swift/playground.rb', line 86 def convert_emoji? convert_emoji == true end |
#save(destination_path) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/swift/playground.rb', line 90 def save(destination_path) destination_path = Pathname.new(destination_path). validate! destination_path insert_highlighting_stylesheet # Create playground in a temporary directory before moving in place of # any existing playground. This avoids any partially written playground # files being re-loaded by Xcode: temp_path = Pathname.new(Dir.mktmpdir) write_stylesheets(temp_path) write_javascripts(temp_path) write_sections(temp_path) write_xcplayground(temp_path) FileUtils.rm_rf(destination_path) if destination_path.exist? FileUtils.mv(temp_path, destination_path) ensure remove_highlighting_stylesheet FileUtils.remove_entry_secure(temp_path) if temp_path && temp_path.exist? end |
#sdk ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/swift/playground.rb', line 73 def sdk case platform.to_s when 'ios' 'iphonesimulator' when 'osx' 'macosx' end end |