Class: Ti::Generate::Project

Inherits:
Object
  • Object
show all
Extended by:
Utils
Defined in:
lib/ti/generate/project.rb

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Utils

append_to_router, base_location, create_directories, create_new_file, create_with_template, error, get_app_name, log, remove_directories, remove_files, templates, touch, underscore

Class Attribute Details

.app_idObject

Returns the value of attribute app_id.



6
7
8
# File 'lib/ti/generate/project.rb', line 6

def app_id
  @app_id
end

.device_platformObject

Returns the value of attribute device_platform.



6
7
8
# File 'lib/ti/generate/project.rb', line 6

def device_platform
  @device_platform
end

.project_nameObject

Returns the value of attribute project_name.



6
7
8
# File 'lib/ti/generate/project.rb', line 6

def project_name
  @project_name
end

Class Method Details

.copy_defaultsObject



27
28
29
30
# File 'lib/ti/generate/project.rb', line 27

def copy_defaults
  FileUtils.cp(location.join("Resources/KS_nav_ui.png"),    "/tmp/")
  FileUtils.cp(location.join("Resources/KS_nav_views.png"), "/tmp/")
end

.create(name, id, platform = 'iphone') ⇒ Object

Ti::Generate::Project.create(‘demo’, ‘org.codewranglers.demo’, ‘ipad’)



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ti/generate/project.rb', line 10

def create(name, id, platform='iphone')
  @project_name    = name
  @device_platform = platform
  @app_id          = id
  
  if generate_titanium_project
    create_directories('tmp')
    copy_defaults
    remove_old_files
    generate_files
    log "Your Titanium project is ready for you to get coding!"
  else
    error "There was an error generating your Titanium project."
  end
end

.create_project_directoryObject



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/ti/generate/project.rb', line 59

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') 
end

.generate_filesObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ti/generate/project.rb', line 33

def generate_files
  create_project_directory
  full_app_hash = {:app_name => @project_name, :app_name_underscore => underscore(@project_name), :platform => @device_platform}
  create_with_template('app/app.coffee', 'app/app.coffee', full_app_hash)
  create_with_template("app/#{underscore(@project_name)}/app.coffee", 'app/app_project.coffee', full_app_hash)
  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)

  default_templates = ['Rakefile', 'Readme.mkd', 'Guardfile', 'Coffeefile']
  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

.generate_titanium_projectObject



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/ti/generate/project.rb', line 80

def generate_titanium_project
  platform = ::Config::CONFIG['host_os']
  if platform =~ /linux/i || platform =~ /darwin/i
    cmd = "titanium create --name=#{@project_name} --platform=#{@device_platform} --id=#{@app_id}"
    # We need to use the session gem so that we can access the user's aliases
    bash = Session::Bash::new 'program' => 'bash --login -i'
    bash.execute(cmd) { |out, err| puts out }
  else
     error("Currently, your OS (#{::Config::CONFIG['host_os']}) is not supported.")
     exit(0)
  end
end

.locationObject



76
77
78
# File 'lib/ti/generate/project.rb', line 76

def location
  base_location.join(@project_name)
end

.remove_old_filesObject



71
72
73
74
# File 'lib/ti/generate/project.rb', line 71

def remove_old_files
  remove_files('README')          
  remove_directories('Resources')
end