lib/sugarcube.rb in sugarcube-2.12.3 vs lib/sugarcube.rb in sugarcube-3.0.0

- old
+ new

@@ -22,20 +22,26 @@ unless cocoa? raise "The '\033[0;1msugarcube-#{package}\033[0m' package is only available on OS X or iOS." end end + def android_only!(package) + unless android? + raise "The '\033[0;1msugarcube-#{package}\033[0m' package is only available on Android." + end + end + def ios? - App.template.to_s =~ /ios/ + App.template.to_s =~ /\bios\b/ end def osx? - App.template.to_s =~ /osx/ + App.template.to_s =~ /\bosx\b/ end def android? - App.template.to_s =~ /android/ + App.template.to_s =~ /\bandroid\b/ end def cocoa? ios? || osx? end @@ -50,27 +56,35 @@ else App.template.to_s end end + 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 = ['all'] + if SugarCube.cocoa? + platforms << 'cocoa' + end + platforms << SugarCube.platform # ios, osx, or android specific files + + platforms.each do |platform| + Dir.glob(File.join(File.dirname(__FILE__), platform, package_name, '**/*.rb')).each do |file| + app.files << file + end + end + end + end -Motion::Project::App.setup do |app| - # 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 - insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0 +if ! App.respond_to?(:pre_setup) + require 'sugarcube_pre_setup' +end - app.files.insert(insert_point, File.join(File.dirname(__FILE__), 'version.rb')) - Dir.glob(File.join(File.dirname(__FILE__), SugarCube.platform, 'sugarcube/**/*.rb')).reverse.each do |file| - app.files.insert(insert_point, file) - end - Dir.glob(File.join(File.dirname(__FILE__), 'cocoa/sugarcube/**/*.rb')).reverse.each do |file| - app.files.insert(insert_point, file) - end - Dir.glob(File.join(File.dirname(__FILE__), 'all/sugarcube/**/*.rb')).reverse.each do |file| - app.files.insert(insert_point, file) - end +Motion::Project::App.pre_setup do |app| + app.files << File.join(File.dirname(__FILE__), 'version.rb') + + SugarCube.add_app_files(app, 'sugarcube') end -require File.join(File.dirname(__FILE__), 'sugarcube-coregraphics.rb') require File.join(File.dirname(__FILE__), 'sugarcube-to_s.rb')