Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#already_generated?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/skeleti.rb', line 10

def already_generated?
  File.exists? 'Resources/app/helper/general_includes.js'
end

#app_js_contentObject



1
2
3
4
5
6
7
8
9
# File 'lib/content.rb', line 1

def app_js_content
<<eos
// root_path
var root_path = "";
Ti.include("app/helper/general_includes.js");
Ti.include("app/controller/application_controller.js");

eos
end

#append_to_file(file, content) ⇒ Object



13
14
15
# File 'lib/file.rb', line 13

def append_to_file file, content
  write_to_file file, content, 'a'
end

#application_controller_contentObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/content.rb', line 26

def application_controller_content
<<eos
var win = Titanium.UI.currentWindow;

// Current view
Ti.include("app/view/application_view.js");

// Current events
Ti.include("app/event/application_events.js");

eos
end

#controller_content(mvce) ⇒ Object



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

def controller_content mvce
<<eos
var win = Titanium.UI.currentWindow;
// App root path
var root_path = "../../";
Ti.include("../helper/general_includes.js");

// Current view
Ti.include("../view/#{mvce}_view.js");

// Current events
Ti.include("../event/#{mvce}_events.js");
eos
end

#create_file(file, content) ⇒ Object



9
10
11
# File 'lib/file.rb', line 9

def create_file file, content
  write_to_file file, content, 'w'
end

#general_includes_contentObject



40
41
42
43
44
# File 'lib/content.rb', line 40

def general_includes_content
<<eos
Ti.include(root_path + "config/application.js");
eos
end

#generate(mvce) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/skeleti.rb', line 42

def generate mvce
  if !mvce
    puts "no VCE name"
    return false
  end
  if File.exists? "Resources/app/controller/#{mvce}_controller.js"
    puts "This VCE has already been generated or at least the controller is present. Aborted!"
    return false
  end
  msg "generating '" + mvce + "'..."
    
  create_file "app/event/#{mvce}_events.js", "// Events for '#{mvce}'"
  create_file "app/view/#{mvce}_view.js", "// View for '#{mvce}'"
  if mvce != "application"
    create_file "app/controller/#{mvce}_controller.js", controller_content(mvce)
  else
    create_file "app/controller/#{mvce}_controller.js", application_controller_content
  end
  
  msg 'done!'
end

#is_ti_app?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/skeleti.rb', line 6

def is_ti_app?
  File.exists? 'tiapp.xml'
end

#mkdir(name) ⇒ Object



1
2
3
4
5
6
7
# File 'lib/file.rb', line 1

def mkdir name
  d = Dir::pwd + "/Resources/" + name
    if FileTest::directory?(d)
      return
    end
  Dir::mkdir(d)
end

#msg(m) ⇒ Object



14
15
16
17
18
# File 'lib/skeleti.rb', line 14

def msg m
  if ARGV[0]!='n' && ARGV[0]!='new'
    puts m
  end
end

#new_appObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/skeleti.rb', line 20

def new_app
  if is_ti_app? && !already_generated?
    puts "generate app skeleton..."
    mkdir 'app'
    mkdir 'app/controller'
    mkdir 'app/event'
    mkdir 'app/helper'
    mkdir 'app/model'
    mkdir 'app/view'
    mkdir 'config'
    create_file 'config/application.js', "// you can put some global variables and settings in here..."
    generate 'application'
    
    FileUtils.mv 'Resources/app.js', 'Resources/app/view/application_view.js'
    create_file 'app.js', app_js_content
    create_file 'app/helper/general_includes.js', general_includes_content
    puts 'done!'
  else
    puts "This either an already genetared app or it is not a Titanium Mobile app at all!"
  end
end

#parse_command_line(a) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/skeleti.rb', line 64

def parse_command_line a
  if a[0]=="g" || a[0]=="generate"
    generate a[1]
  elsif a[0]=="new" || a[0] == "n"
    new_app
  else
    puts usage
  end
end

#usageObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/content.rb', line 47

def usage
<<eos
**********************************************************
You can generate MVCE skeleton app or add a VCE

Usage note: you can use either 'ti' or 'skeleti' at prompt. First parameter should be 'new' (n) or 'generate'(g).

Step by step to do for new project:
  1. cd in your new Titanium Mobile project
  2. To generate app skeleton, at prompt, type:
	    ti new      (or 'skeleti new')
  3. to generate another VCE: 
	    ti g my_controller		(where 'my_controller' is a new VCE you want to generate)


**********************************************************
eos
end

#write_to_file(file, content, mode) ⇒ Object



17
18
19
# File 'lib/file.rb', line 17

def write_to_file file, content, mode
  File.open("Resources/" + file, mode) {|f| f.write(content) }
end