Module: SugarCube

Defined in:
lib/version.rb,
lib/sugarcube.rb,
lib/cocoa/sugarcube/log.rb,
lib/all/sugarcube-repl/repl.rb,
lib/ios/sugarcube-repl/repl.rb,
lib/osx/sugarcube-repl/repl.rb,
lib/cocoa/sugarcube-repl/repl.rb,
lib/ios/sugarcube-modal/modal.rb,
lib/android/sugarcube-repl/repl.rb,
lib/cocoa/sugarcube-timer/timer.rb,
lib/cocoa/sugarcube-ui/frameable.rb,
lib/ios/sugarcube-events/uicontrol.rb,
lib/cocoa/sugarcube-nsdate/date_parser.rb,
lib/cocoa/sugarcube-anonymous/anonymous.rb,
lib/ios/sugarcube-factories/uialertview.rb,
lib/ios/sugarcube-factories/uiactionsheet.rb,
lib/ios/sugarcube-animations/animation_chain.rb,
lib/ios/sugarcube-coregraphics/core_graphics.rb,
lib/ios/sugarcube-factories/uialertcontroller.rb

Defined Under Namespace

Modules: CoreGraphics, DateParser, Frameable, Modal, Timer Classes: ActionSheetDelegate, AlertViewDelegate, AnimationChain, Anonymous, PlatformException, Repl, UIAlertControllerCallbackHelper, UIControlCallbackHelper

Constant Summary collapse

Version =
'3.3.2'

Class Method Summary collapse

Class Method Details

.add_app_files(app, package_name) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/sugarcube.rb', line 64

def add_app_files(app, package_name)
  # scans app.files until it finds app/ (the default)
  # if found, it inserts just before those files, otherwise it will insert to
  # the end of the list
  platforms = [SugarCube.platform]  # ios, osx, or android specific files
  if SugarCube.cocoa?
    platforms << 'cocoa'
  end
  platforms << 'all'

  platforms.reverse.each do |platform|
    Dir.glob(File.join(File.dirname(__FILE__), platform, package_name, '**/*.rb')).each do |file|
      app.files << file
    end
  end
end

.android?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/sugarcube.rb', line 44

def android?
  App.template.to_s =~ /\bandroid\b/
end

.android_only!(package) ⇒ Object



30
31
32
33
34
# File 'lib/sugarcube.rb', line 30

def android_only!(package)
  unless android?
    raise PlatformException.new("The '\033[0;1msugarcube-#{package}\033[0m' package is only available on Android.")
  end
end

.cocoa?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/sugarcube.rb', line 48

def cocoa?
  ios? || osx?
end

.cocoa_only!(package) ⇒ Object



24
25
26
27
28
# File 'lib/sugarcube.rb', line 24

def cocoa_only!(package)
  unless cocoa?
    raise PlatformException.new("The '\033[0;1msugarcube-#{package}\033[0m' package is only available on OS X or iOS.")
  end
end

.flush_log(notification = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/all/sugarcube/log.rb', line 17

def SugarCube.flush_log(notification=nil)
  return unless @log && ! @log.empty?

  output = "SugarCube recorded the following warnings:"
  @log.uniq.each do |message|
    output << "\n"
    output << message
  end
  SugarCube.stderr(output)
  @log = nil
end

.ios?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/sugarcube.rb', line 36

def ios?
  App.template.to_s =~ /\bios\b/
end

.ios_only!(package) ⇒ Object



12
13
14
15
16
# File 'lib/sugarcube.rb', line 12

def ios_only!(package)
  unless ios?
    raise PlatformException.new("The '\033[0;1msugarcube-#{package}\033[0m' package is only available on iOS.")
  end
end

.log(message = nil) ⇒ Object



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/all/sugarcube/log.rb', line 1

def SugarCube.log(message=nil)
  @log ||= []

  if message.nil?
    return @log
  end

  if suppress?
    log << message
  elsif log?
    SugarCube.stderr(message)
  end

  self
end

.log?(value = nil) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/all/sugarcube/log.rb', line 29

def SugarCube.log?(value=nil)
  if value.nil?
    if @logging.nil?
      @logging = (RUBYMOTION_ENV == 'development')
    end
    @logging
  else
    @logging = value
    unless @logging
      @log = nil
    end
  end
end

.look_in(where, here, here__deprecated = {}) ⇒ Object



1
2
3
4
5
6
7
8
9
# File 'lib/all/sugarcube/look_in.rb', line 1

def SugarCube.look_in(where, here, here__deprecated={})
  return here[where] if here.has_key? where
  if here__deprecated[where]
    translated = here__deprecated[where]
    SugarCube.log("The symbol #{where.inspect} has been deprecated in favor of #{translated.inspect}")
    return here[translated]
  end
  raise SugarCubeNotFoundException.new(where.inspect)
end

.osx?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/sugarcube.rb', line 40

def osx?
  App.template.to_s =~ /\bosx\b/
end

.osx_only!(package) ⇒ Object



18
19
20
21
22
# File 'lib/sugarcube.rb', line 18

def osx_only!(package)
  unless osx?
    raise PlatformException.new("The '\033[0;1msugarcube-#{package}\033[0m' package is only available on OS X.")
  end
end

.platformObject



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/sugarcube.rb', line 52

def platform
  if ios?
    'ios'
  elsif osx?
    'osx'
  elsif android?
    'android'
  else
    App.template.to_s
  end
end

.stderr(message) ⇒ Object



4
5
6
# File 'lib/cocoa/sugarcube/log.rb', line 4

def stderr(message)
  NSLog("%@", message)
end

.suppress?(value = nil) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
51
52
# File 'lib/all/sugarcube/log.rb', line 43

def SugarCube.suppress?(value=nil)
  if value.nil?
    @suppress
  else
    @suppress = value
    unless @suppress
      @log = nil
    end
  end
end