Class: Swift::Playground

Inherits:
Object
  • Object
show all
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.4'

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  self.sections = []
  self.stylesheets = []
  self.javascripts = []

  stylesheet_path = template_path 'Documentation', 'defaults.css.scss'
  self.stylesheets << Stylesheet.new(stylesheet_path)

  options = {
    platform: 'ios',
    allow_reset: true,
    convert_emoji: true,
    syntax_highlighting: true
  }.merge(options)

  self.platform = options[:platform]
  self.allow_reset = options[:allow_reset]
  self.convert_emoji = options[:convert_emoji]
  self.syntax_highlighting = options[:syntax_highlighting]
end

Instance Attribute Details

#allow_resetObject

Returns the value of attribute allow_reset.



25
26
27
# File 'lib/swift/playground.rb', line 25

def allow_reset
  @allow_reset
end

#convert_emojiObject

Returns the value of attribute convert_emoji.



25
26
27
# File 'lib/swift/playground.rb', line 25

def convert_emoji
  @convert_emoji
end

#javascriptsObject

Returns the value of attribute javascripts.



26
27
28
# File 'lib/swift/playground.rb', line 26

def javascripts
  @javascripts
end

#platformObject

Returns the value of attribute platform.



25
26
27
# File 'lib/swift/playground.rb', line 25

def platform
  @platform
end

#sectionsObject

Returns the value of attribute sections.



26
27
28
# File 'lib/swift/playground.rb', line 26

def sections
  @sections
end

#stylesheetsObject

Returns the value of attribute stylesheets.



26
27
28
# File 'lib/swift/playground.rb', line 26

def stylesheets
  @stylesheets
end

#syntax_highlightingObject

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

Returns:

  • (Boolean)


82
83
84
# File 'lib/swift/playground.rb', line 82

def allows_reset?
  allow_reset == true
end

#convert_emoji?Boolean

Returns:

  • (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).expand_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

#sdkObject



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