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.
@@ -2,6 +2,7 @@
2
2
  class Application < Dynamics::Application
3
3
 
4
4
  def initialize
5
- super('Navigation')
5
+ #super('Navigation')
6
+ super('Tab Bar')
6
7
  end
7
8
  end
@@ -1,4 +1,7 @@
1
1
 
2
2
  class MainController < Dynamics::Controller
3
3
 
4
+ def load
5
+ end
6
+
4
7
  end
@@ -1,4 +1,7 @@
1
1
 
2
2
  class Sub1Controller < Dynamics::Controller
3
3
 
4
+ def load
5
+ end
6
+
4
7
  end
@@ -1,4 +1,7 @@
1
1
 
2
2
  class Sub2Controller < Dynamics::Controller
3
3
 
4
+ def load
5
+ end
6
+
4
7
  end
@@ -1,4 +1,4 @@
1
1
 
2
- class Sub1View < Dynamics::Window
2
+ class Sub1View < Dynamics::View
3
3
 
4
4
  end
@@ -1,4 +1,4 @@
1
1
 
2
- class Sub2View < Dynamics::Window
2
+ class Sub2View < Dynamics::View
3
3
 
4
4
  end
@@ -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
- controller = MainController.alloc.initWithNibName(nil, bundle: nil)
19
- nav_controller = UINavigationController.alloc.initWithRootViewController(controller)
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 on_next
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
- self.title = App.name
45
- self.view.backgroundColor = UIColor.whiteColor
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(/# \@\@.+\@\@.+# \@\@End\@\@/m) do |block|
86
- block.scan(/# \@\@.+\@\@/) do |placeholder|
87
- layout = placeholder.split(' ')[1].gsub('@', '')
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, code_navigation)
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.code_navigation
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 += "controller = MainController.alloc.initWithNibName(nil, bundle: nil)\n"
105
- code += "controller.navigationItem.rightBarButtonItem = UIBarButtonItem.alloc.initWithTitle('Next', style: UIBarButtonItemStyleBordered, target:controller, action:'on_next')\n"
106
- code += "sub1_controller = Sub1Controller.alloc.initWithNibName(nil, bundle: nil)\n"
107
- code += "sub1_controller.navigationItem.rightBarButtonItem = UIBarButtonItem.alloc.initWithTitle('Next', style: UIBarButtonItemStyleBordered, target:sub1_controller, action:'on_next')\n"
108
- code += "controller.next_controller = sub1_controller\n"
109
- code += "sub2_controller = Sub2Controller.alloc.initWithNibName(nil, bundle: nil)\n"
110
- code += "sub1_controller.next_controller = sub2_controller\n"
111
- code += "# @@End@@"
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
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamics
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 9
10
- version: 0.0.9
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ng Say Joe