dynamics 0.0.9 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/base/app/application.rb +2 -1
- data/base/app/controllers/main_controller.rb +3 -0
- data/base/app/controllers/sub1_controller.rb +3 -0
- data/base/app/controllers/sub2_controller.rb +3 -0
- data/base/app/views/sub1_view.rb +1 -1
- data/base/app/views/sub2_view.rb +1 -1
- data/base/templates/dynamics.rb +34 -16
- data/lib/dynamics.rb +64 -13
- metadata +3 -3
data/base/app/application.rb
CHANGED
data/base/app/views/sub1_view.rb
CHANGED
data/base/app/views/sub2_view.rb
CHANGED
data/base/templates/dynamics.rb
CHANGED
@@ -11,17 +11,10 @@ module Dynamics
|
|
11
11
|
@window.makeKeyAndVisible
|
12
12
|
if @layout == 'Navigation'
|
13
13
|
# @@Navigation@@
|
14
|
-
# @@End@@
|
15
|
-
|
16
|
-
@window.rootViewController = UINavigationController.alloc.initWithRootViewController(controller)
|
14
|
+
# @@End@@
|
17
15
|
elsif @layout == 'Tab Bar'
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
tab_controller = UITabBarController.alloc.initWithNibName(nil, bundle: nil)
|
22
|
-
tab_controller.viewControllers = [nav_controller]
|
23
|
-
|
24
|
-
@window.rootViewController = tab_controller
|
16
|
+
# @@Tab Bar@@
|
17
|
+
# @@End@@
|
25
18
|
else
|
26
19
|
@window.rootViewController = MainController.alloc.initWithNibName(nil, bundle: nil)
|
27
20
|
end
|
@@ -30,22 +23,47 @@ module Dynamics
|
|
30
23
|
end
|
31
24
|
|
32
25
|
class Controller < UIViewController
|
33
|
-
attr_accessor :next_controller
|
26
|
+
attr_accessor :next_controller, :next_view
|
27
|
+
|
28
|
+
def load
|
29
|
+
end
|
34
30
|
|
35
|
-
def
|
31
|
+
def name
|
32
|
+
self.class.name.underscore.split('_')[0].capitalize
|
33
|
+
end
|
34
|
+
|
35
|
+
def push
|
36
36
|
self.navigationController.pushViewController(@next_controller, animated: true)
|
37
37
|
end
|
38
38
|
|
39
39
|
private
|
40
|
-
|
40
|
+
|
41
|
+
def loadView
|
42
|
+
if @next_view.nil?
|
43
|
+
super
|
44
|
+
else
|
45
|
+
self.view = @next_view
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
41
49
|
def viewDidLoad
|
42
50
|
super
|
43
51
|
|
44
|
-
|
45
|
-
|
52
|
+
if name == 'Main'
|
53
|
+
self.title = App.name
|
54
|
+
self.view.backgroundColor = UIColor.whiteColor
|
55
|
+
else
|
56
|
+
self.title = name
|
57
|
+
self.view.backgroundColor = UIColor.grayColor
|
58
|
+
end
|
59
|
+
|
60
|
+
load
|
46
61
|
end
|
47
62
|
end
|
48
63
|
|
64
|
+
class View < UIView
|
65
|
+
end
|
66
|
+
|
49
67
|
class Window < UIWindow
|
50
|
-
end
|
68
|
+
end
|
51
69
|
end
|
data/lib/dynamics.rb
CHANGED
@@ -82,11 +82,12 @@ module Dynamics
|
|
82
82
|
lib_dir = File.join(path, 'lib')
|
83
83
|
lib_code = render_code(File.join(lib_dir, 'dynamics.rb'))
|
84
84
|
new_code = lib_code
|
85
|
-
lib_code.scan(/#
|
86
|
-
block.scan(
|
87
|
-
layout = placeholder.
|
85
|
+
lib_code.scan(/# @@.+?@@.+?# @@End@@/m) do |block|
|
86
|
+
block.scan(/^# @@.+?@@/) do |placeholder|
|
87
|
+
layout = placeholder.gsub('# @@', '').gsub('@', '')
|
88
88
|
case layout
|
89
|
-
when 'Navigation' then new_code = new_code.gsub(block,
|
89
|
+
when 'Navigation' then new_code = new_code.gsub(block, navigation_code(path))
|
90
|
+
when 'Tab Bar' then new_code = new_code.gsub(block, tab_bar_code(path))
|
90
91
|
end
|
91
92
|
end
|
92
93
|
end
|
@@ -99,16 +100,47 @@ module Dynamics
|
|
99
100
|
|
100
101
|
private
|
101
102
|
|
102
|
-
def self.
|
103
|
+
def self.camelize(str)
|
104
|
+
ret = ''
|
105
|
+
words = str.split('_')
|
106
|
+
for word in words
|
107
|
+
ret += word.capitalize
|
108
|
+
end
|
109
|
+
ret
|
110
|
+
end
|
111
|
+
|
112
|
+
def self.find_controllers(path)
|
113
|
+
controllers = []
|
114
|
+
for controller in Dir.glob(File.join(path, 'app', 'controllers', '*.rb'))
|
115
|
+
filename = File.basename(controller)
|
116
|
+
if filename != 'main_controller.rb'
|
117
|
+
controllers << {:filename => filename, :class_name => camelize(filename.split('.')[0]), :name => filename.split('_')[0].capitalize}
|
118
|
+
end
|
119
|
+
end
|
120
|
+
controllers
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.navigation_code(path)
|
103
124
|
code = "# @@Navigation@@\n"
|
104
|
-
code += "
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
125
|
+
code += " main_controller = MainController.alloc.initWithNibName(nil, bundle: nil)\n"
|
126
|
+
controllers = find_controllers(path)
|
127
|
+
if controllers.size > 0
|
128
|
+
code += " main_controller.navigationItem.rightBarButtonItem = UIBarButtonItem.alloc.initWithTitle('#{controllers.first[:name]}', style: UIBarButtonItemStyleBordered, target:main_controller, action:'push')\n"
|
129
|
+
end
|
130
|
+
i = 1
|
131
|
+
prev_controller = 'main_controller'
|
132
|
+
for controller in controllers
|
133
|
+
code += " sub#{i}_controller = #{controller[:class_name]}.alloc.initWithNibName(nil, bundle: nil)\n"
|
134
|
+
code += " sub#{i}_controller.next_view = #{controller[:name]}View.alloc.initWithFrame(UIScreen.mainScreen.bounds)\n"
|
135
|
+
code += " #{prev_controller}.next_controller = sub#{i}_controller\n"
|
136
|
+
if controller != controllers.last
|
137
|
+
code += " sub#{i}_controller.navigationItem.rightBarButtonItem = UIBarButtonItem.alloc.initWithTitle('#{controllers[i][:name]}', style: UIBarButtonItemStyleBordered, target:sub#{i}_controller, action:'push')\n"
|
138
|
+
prev_controller = "sub#{i}_controller"
|
139
|
+
i += 1
|
140
|
+
end
|
141
|
+
end
|
142
|
+
code += " @window.rootViewController = UINavigationController.alloc.initWithRootViewController(main_controller)\n"
|
143
|
+
code += " # @@End@@"
|
112
144
|
end
|
113
145
|
|
114
146
|
def self.render_code(name)
|
@@ -117,4 +149,23 @@ private
|
|
117
149
|
f.close
|
118
150
|
content
|
119
151
|
end
|
152
|
+
|
153
|
+
def self.tab_bar_code(path)
|
154
|
+
code = "# @@Tab Bar@@\n"
|
155
|
+
controllers_list = 'main_controller'
|
156
|
+
code += " main_controller = MainController.alloc.initWithNibName(nil, bundle: nil)\n"
|
157
|
+
code += " main_controller.title = main_controller.name\n"
|
158
|
+
i = 1
|
159
|
+
controllers = find_controllers(path)
|
160
|
+
for controller in controllers
|
161
|
+
controllers_list += ", sub#{i}_controller"
|
162
|
+
code += " sub#{i}_controller = #{controller[:class_name]}.alloc.initWithNibName(nil, bundle: nil)\n"
|
163
|
+
code += " sub#{i}_controller.title = sub#{i}_controller.name\n"
|
164
|
+
i += 1
|
165
|
+
end
|
166
|
+
code += " tab_controller = UITabBarController.alloc.initWithNibName(nil, bundle: nil)\n"
|
167
|
+
code += " tab_controller.viewControllers = [#{controllers_list}]\n"
|
168
|
+
code += " @window.rootViewController = tab_controller\n"
|
169
|
+
code += " # @@End@@"
|
170
|
+
end
|
120
171
|
end
|
metadata
CHANGED