Class: Coolstrap::Generator::Generate::Project

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

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Utils

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


7
8
9
# File 'lib/coolstrap-generator/generate/project.rb', line 7

def app_id
  @app_id
end

.device_platformObject

Returns the value of attribute device_platform


7
8
9
# File 'lib/coolstrap-generator/generate/project.rb', line 7

def device_platform
  @device_platform
end

.project_nameObject

Returns the value of attribute project_name


7
8
9
# File 'lib/coolstrap-generator/generate/project.rb', line 7

def project_name
  @project_name
end

Class Method Details

.copy_defaultsObject


28
29
30
31
# File 'lib/coolstrap-generator/generate/project.rb', line 28

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

Coolstrap::Generator::Generate::Project.create('demo', 'org.codewranglers.demo', 'ipad')


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

def create(name, id, platform='iphone')
  @project_name    = name
  @device_platform = platform
  @app_id          = id

  begin
    create_directories('tmp')
    copy_defaults
    remove_old_files
    generate_files
    log "Your Coolstrap project is ready for you to get coding!"
  rescue => e
    error "There was an error generating your Coolstrap project. #{e} #{e.backtrace}"
  end
end

.create_project_directoryObject


57
58
59
60
61
62
63
64
65
66
# File 'lib/coolstrap-generator/generate/project.rb', line 57

def create_project_directory
  create_directories('docs', 'spec',
                     "source/assets",
                     "source/assets/images",
                     "source/assets/fonts",
                     "source/assets/stylesheets",
                     "source/assets/javascripts",
                     "source/views",
                     "source/models") 
end

.generate_filesObject


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

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('.gitignore', 'defaults/gitignore', full_app_hash)
  create_with_template('Gemfile', 'defaults/Gemfile', full_app_hash)
  create_with_template('LICENSE', 'defaults/LICENSE', full_app_hash)
  
  create_with_template('config.rb', 'defaults/config', full_app_hash)
  default_templates = ['Readme.mkd']
  default_templates.each do |tempfile|
    create_with_template(tempfile, "defaults/#{tempfile}", full_app_hash)
  end
  
  FileUtils.cp_r(templates("app/views/shared/."), location.join("source/views/shared") )
  FileUtils.cp_r(templates("app/assets/."), location.join("source/assets") )
  
  create_with_template('source/index.html.haml', 'app/index.html.haml', full_app_hash)
  create_with_template('source/layout.haml', 'app/layout.haml', full_app_hash)
  create_with_template('source/views/_home.haml', 'app/views/_home.haml', full_app_hash)
  
end

.generate_titanium_projectObject

TODO: generate ios bridge here


78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/coolstrap-generator/generate/project.rb', line 78

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


73
74
75
# File 'lib/coolstrap-generator/generate/project.rb', line 73

def location
  base_location.join(@project_name)
end

.remove_old_filesObject


68
69
70
71
# File 'lib/coolstrap-generator/generate/project.rb', line 68

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