Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding more rake tasks. Updated template

  • Loading branch information...
commit 76e5af97a3ad1242b929fb289641aa1936708b72 1 parent 6648923
@baldrailers baldrailers authored
View
2  README.rdoc
@@ -5,7 +5,7 @@ A rapid development framework for titanium.
== Requirements
* ruby 1.9.2
-* Titanium Developer Mobile SDK 1.6.2
+* Titanium Developer Mobile SDK 1.6.2/1.7.x
* CoffeeScript
* libffi `brew install libffi`
View
12 lib/ti.rb
@@ -13,17 +13,17 @@
module Ti
ROOT_PATH = Pathname(__FILE__).dirname.expand_path
TITANIUM_VERSION = '1.6.2'
-
+
# TODO: Need to support those how have install Titanium in their $HOME dir.
OSX_TITANIUM_HOME = "$HOME/Library/Application\\ Support/Titanium/mobilesdk/osx/#{::Ti::TITANIUM_VERSION}/titanium.py"
OSX_TITANIUM = "/Library/Application\\ Support/Titanium/mobilesdk/osx/#{::Ti::TITANIUM_VERSION}/titanium.py"
LINUX_TITANIUM = "$HOME/.titanium/mobilesdk/linux/#{::Ti::TITANIUM_VERSION}/titanium.py"
-
+
autoload :VERSION, 'ti/version.rb'
autoload :CLI, 'ti/cli.rb'
autoload :Logger, "ti/logger.rb"
autoload :Utils, "ti/utils.rb"
-
+
module Compiler
autoload :CoffeeScripts, 'ti/compiler/coffee_scripts.rb'
autoload :SASSScripts, 'ti/compiler/sass_scripts.rb'
@@ -32,16 +32,16 @@ module Compiler
module Builder
autoload :Titanium, "ti/builder/titanium.rb"
end
-
+
module Generate
autoload :Project, "ti/generate/project.rb"
autoload :Model, "ti/generate/model.rb"
autoload :View, "ti/generate/view.rb"
autoload :Controller, "ti/generate/controller.rb"
end
-
+
def self.root
@root ||= Pathname(__FILE__).dirname.expand_path
end
-
+
end
View
8 lib/ti/cli.rb
@@ -23,7 +23,7 @@ def cli_error(message, exit_status=nil)
def info
say "Version #{::Ti::VERSION}"
end
-
+
map %(n) => 'new'
desc "new <name> <id> <platform>", "generates a new Titanium project."
long_desc "Generates a new Titanium project. See 'ti help new' for more information.
@@ -34,7 +34,7 @@ def info
def new(name, device_id='org.mycompany.demo', platform='iphone')
::Ti::Generate::Project.create(name, device_id, platform)
end
-
+
map %w(g) => 'generate'
desc "generate <model/controller/view> <name>", "generate a new model or view with jasmine specs."
def generate(type, name)
@@ -48,8 +48,6 @@ def generate(type, name)
end
end
-
-
map %w(s) => 'scaffold'
desc "scaffold <window/tabgroup/view> <domain> <name>", "generate a scaffold for Titanium elements."
def scaffold(ti_type, domain, name)
@@ -67,7 +65,7 @@ def controller(name)
:app_name => get_app_name,
:name => name })
end
-
+
desc "compile <all/coffee/sass>", "compiles all CoffeeScripts"
def compile(type)
case
View
48 lib/ti/generate/project.rb
@@ -26,7 +26,7 @@ def copy_defaults
FileUtils.cp(location.join("Resources/KS_nav_ui.png"), "/tmp/")
FileUtils.cp(location.join("Resources/KS_nav_views.png"), "/tmp/")
end
-
+
def generate_files
create_project_directory
@@ -36,10 +36,10 @@ def generate_files
create_with_template("app/#{underscore(@project_name)}/api.coffee", 'app/api.coffee', full_app_hash)
create_with_template('.gitignore', 'defaults/gitignore', full_app_hash)
-
+
create_new_file("spec/app_spec.coffee", templates('specs/app_spec.coffee'))
create_new_file("app/#{underscore(@project_name)}/stylesheets/app.sass", templates('app/stylesheets/app.sass'))
-
+
create_with_template('config/config.rb', 'defaults/config', full_app_hash)
create_with_template("app/#{underscore(@project_name)}/helpers/application.coffee", 'app/helpers/application.coffee', full_app_hash)
@@ -47,25 +47,25 @@ def generate_files
default_templates.each do |tempfile|
create_with_template(tempfile, "defaults/#{tempfile}", full_app_hash)
end
-
+
# load default images
FileUtils.cp("/tmp/KS_nav_ui.png", location.join("Resources/images/"))
FileUtils.cp("/tmp/KS_nav_views.png", location.join("Resources/images/"))
end
-
-
+
+
def create_project_directory
create_directories('Resources', 'Resources/images', 'Resources/vendor',
- 'config',
- 'docs',
- "app/#{underscore(@project_name)}/models",
- "app/#{underscore(@project_name)}/helpers",
- "app/#{underscore(@project_name)}/views",
- "app/#{underscore(@project_name)}/stylesheets",
- "app/#{underscore(@project_name)}/stylesheets/partials",
- 'spec/models', 'spec/views', 'spec/helpers')
+ 'config',
+ 'docs',
+ "app/#{underscore(@project_name)}/models",
+ "app/#{underscore(@project_name)}/helpers",
+ "app/#{underscore(@project_name)}/views",
+ "app/#{underscore(@project_name)}/stylesheets",
+ "app/#{underscore(@project_name)}/stylesheets/partials",
+ 'spec/models', 'spec/views', 'spec/helpers')
end
-
+
def remove_old_files
remove_files('README')
remove_directories('Resources')
@@ -78,15 +78,15 @@ def location
def generate_titanium_project
titanium_platform = case ::Config::CONFIG['host_os']
- when /linux/i
- ::Ti::LINUX_TITANIUM
- when /darwin/i
- File.exists?(::Ti::OSX_TITANIUM.gsub('\\', '')) ? ::Ti::OSX_TITANIUM : ::Ti::OSX_TITANIUM_HOME
- else
- error("Currently, your OS (#{::Config::CONFIG['host_os']}) is not supported.")
- exit(0)
- end
-
+ when /linux/i
+ ::Ti::LINUX_TITANIUM
+ when /darwin/i
+ File.exists?(::Ti::OSX_TITANIUM.gsub('\\', '')) ? ::Ti::OSX_TITANIUM : ::Ti::OSX_TITANIUM_HOME
+ else
+ error("Currently, your OS (#{::Config::CONFIG['host_os']}) is not supported.")
+ exit(0)
+ end
+
"#{titanium_platform} create --name=#{@project_name} --platform=#{@device_platform} --id=#{@app_id}"
end
View
6 lib/ti/logger.rb
@@ -1,6 +1,6 @@
module Ti
class Logger
-
+
def self.report(msg)
$stdout.puts(msg.green.bold)
end
@@ -8,6 +8,6 @@ def self.report(msg)
def self.error(msg)
$stderr.puts(msg.red.bold)
end
-
+
end
-end
+end
View
11 lib/ti/templates/defaults/Rakefile.erb
@@ -63,6 +63,13 @@ namespace :build do
task :iphone do
build
end
+
+ desc "Recreate build folder"
+ task :new do
+ system "rm -rf build"
+ system "mkdir -p build/iphone"
+ Rake::Task["setup:all"].invoke
+ end
end
def compile
@@ -111,7 +118,7 @@ def compile_coffee
puts "Compiling CoffeeScript".blue
paths = `find app/<%= app_name_underscore %> -name '*.coffee'`.split("\n")
compilation = (
- system "coffee -p --join --bare #{paths.join(' ')} > Resources/<%= app_name_underscore%>.js" and
+ system "coffee -c -b --join Resources/<%= app_name_underscore %>.js -c -b #{paths.join(' ')}" and
system "coffee -p --bare app/app.coffee > Resources/app.js"
)
@@ -125,7 +132,7 @@ def compile_coffee
end
def build(options={})
- return unless compile
+ return "Broken" unless compile
options[:device] ||= 'iphone'
puts "Building with Titanium... (DEVICE_TYPE: #{options[:device]})".blue
sh %Q{bash -c "#{TI_BUILD} run #{PROJECT_ROOT}/ #{IPHONE_SDK_VERSION} #{APP_ID} #{APP_NAME} #{APP_DEVICE} " \
View
23 lib/ti/templates/rakefile
@@ -40,6 +40,13 @@ namespace :build do
task :iphone do
build
end
+
+ desc "Recreate build folder"
+ task :new do
+ system "rm -rf build"
+ system "mkdir -p build/iphone"
+ Rake::Task["setup:all"].invoke
+ end
end
def compile
@@ -57,17 +64,25 @@ def compile_coffee
paths = [
"app/#{APP_NAME}.coffee",
"app/models/*.coffee",
- "app/views/*.coffee"
+ "app/views/*.coffee"
]
puts "PATHS: #{paths.join(' ')} ".yellow
- `coffee -p --join --bare #{paths.join(' ')} > Resources/#{APP_NAME}.js`
- `coffee -p --bare src/app.coffee > Resources/app.js`
+ compilation = (
+ system "coffee -c -b --join Resources/#{APP_NAME}.js -c -b #{paths.join(' ')}" and
+ system "coffee -p --bare src/app.coffee > Resources/app.js"
+ )
+
+ if compilation
+ puts "Successfully compiled CoffeeScript".green
+ else
+ puts "Error compiling CoffeeScript".red
+ end
end
def build(options={})
- compile
+ return "Broken" unless compile
options[:device] ||= 'iphone'
puts "Building with Titanium with Ti... (DEVICE_TYPE:#{options[:device]})"
FileUtils.mkdir_p "#{PROJECT_ROOT}/#{PROJECT_NAME}/build/iphone/"
View
42 lib/ti/utils.rb
@@ -1,6 +1,6 @@
module Ti
module Utils
-
+
def create_new_file(name, file=nil)
log "Creating #{name}"
contents = file.nil? ? '' : File.read(file)
@@ -8,38 +8,38 @@ def create_new_file(name, file=nil)
File.open(location.join(name), 'w') { |f| f.write(contents) }
end
end
-
+
def get_app_name
config = File.open("tiapp.xml")
doc = ::Nokogiri::XML(config)
config.close
doc.xpath('ti:app/name').text
end
-
+
def remove_files(*files)
files.each do |file|
log "Removing #{file} file."
FileUtils.rm(location.join(file))
end
end
-
-
+
+
def touch(*filenames)
filenames.each do |filename|
log "Creating #{filename} file."
FileUtils.touch(location.join(filename))
end
end
-
-
+
+
def create_directories(*dirs)
dirs.each do |dir|
log "Creating the #{dir} directory."
FileUtils.mkdir_p(location.join(dir))
end
end
-
-
+
+
def remove_directories(*names)
names.each do |name|
log "Removing #{name} directory."
@@ -47,16 +47,16 @@ def remove_directories(*names)
end
end
-
+
def create_with_template(name, template_location, contents={})
template = templates("#{template_location}.erb")
eruby = Erubis::Eruby.new(File.read(template))
File.open(location.join(name.gsub(/^\//, '')), 'w') { |f| f.write(eruby.result(contents))}
end
-
+
def append_to_router(name, type)
router_contents = File.read(location.join("app/app.coffee"))
-
+
if router_contents.include?(type.capitalize)
contents = router_contents.sub( "#{type.capitalize}:", "#{type.capitalize}:\n #{name.capitalize}: {}" )
else
@@ -64,27 +64,27 @@ def append_to_router(name, type)
end
File.open(location.join("app/app.coffee"), 'w') { |f| f.write(contents) }
end
-
-
+
+
def templates(path)
::Ti.root.join('ti/templates').join(path)
end
-
-
+
+
def log(msg)
::Ti::Logger.report(msg)
end
-
+
def error(msg)
::Ti::Logger.error(msg)
end
-
+
def base_location
@location ||= Pathname.new(Dir.pwd)
end
alias_method :location, :base_location
-
-
+
+
def underscore(string)
string.gsub(/::/, '/').
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
@@ -92,6 +92,6 @@ def underscore(string)
tr("-", "_").
downcase
end
-
+
end
end
View
5 ti.gemspec
@@ -28,8 +28,9 @@ Gem::Specification.new do |s|
s.add_runtime_dependency(%q<nokogiri>, ["~> 1.4.4"])
s.add_runtime_dependency(%q<erubis>, ["~> 2.7.0"])
s.add_runtime_dependency(%q<rocco>, ["~> 0.7"])
- s.add_runtime_dependency(%q<thor>, ["~> 0.14.6"])
- s.add_runtime_dependency(%q<rocco>, ["~> 0.7"])
+ s.add_runtime_dependency(%q<thor>, ["~> 0.14.6"])
+ s.add_runtime_dependency(%q<rocco>, ["~> 0.7"])
+ s.add_runtime_dependency(%q<compass>, ["~> 0.7"])
s.add_development_dependency(%q<bundler>, ["~> 1.0.14"])
s.add_development_dependency(%q<rspec>, ["~> 2.6.0"])
Please sign in to comment.
Something went wrong with that request. Please try again.