module SugarCube

Constants

Version

Public Class Methods

flush_log(notification=nil) click to toggle source
# 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
log(message=nil) click to toggle source
# 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) click to toggle source
# 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={}) click to toggle source
# 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
stderr(message) click to toggle source
# File lib/android/sugarcube/log.rb, line 1
def SugarCube.stderr(message)
  puts message
end
suppress?(value=nil) click to toggle source
# 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

Public Instance Methods

add_app_files(app, package_name) click to toggle source
# 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?() click to toggle source
# File lib/sugarcube.rb, line 44
def android?
  App.template.to_s =~ /\bandroid\b/
end
android_only!(package) click to toggle source
# 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?() click to toggle source
# File lib/sugarcube.rb, line 48
def cocoa?
  ios? || osx?
end
cocoa_only!(package) click to toggle source
# 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
ios?() click to toggle source
# File lib/sugarcube.rb, line 36
def ios?
  App.template.to_s =~ /\bios\b/
end
ios_only!(package) click to toggle source
# 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
osx?() click to toggle source
# File lib/sugarcube.rb, line 40
def osx?
  App.template.to_s =~ /\bosx\b/
end
osx_only!(package) click to toggle source
# 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
platform() click to toggle source
# 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) click to toggle source
# File lib/cocoa/sugarcube/log.rb, line 4
def stderr(message)
  NSLog("%@", message)
end