dynamics 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,4 @@
1
1
 
2
2
  class MainController < Dynamics::Controller
3
-
4
- def load
5
- end
6
3
 
7
4
  end
@@ -1,7 +1,4 @@
1
1
 
2
2
  class Sub1Controller < Dynamics::Controller
3
-
4
- def load
5
- end
6
3
 
7
4
  end
@@ -1,7 +1,4 @@
1
1
 
2
2
  class Sub2Controller < Dynamics::Controller
3
-
4
- def load
5
- end
6
3
 
7
4
  end
@@ -2,10 +2,13 @@
2
2
  module Dynamics
3
3
 
4
4
  class Application
5
+
6
+ private
7
+
5
8
  def initialize(layout)
6
9
  @layout = layout
7
10
  end
8
-
11
+
9
12
  def application(application, didFinishLaunchingWithOptions:launchOptions)
10
13
  @window = MainView.alloc.initWithFrame(UIScreen.mainScreen.bounds)
11
14
  @window.makeKeyAndVisible
@@ -25,19 +28,12 @@ module Dynamics
25
28
  class Controller < UIViewController
26
29
  attr_accessor :next_controller, :next_view
27
30
 
28
- def load
29
- end
30
-
31
31
  def name
32
32
  self.class.name.underscore.split('_')[0].capitalize
33
33
  end
34
-
35
- def push
36
- self.navigationController.pushViewController(@next_controller, animated: true)
37
- end
38
34
 
39
35
  private
40
-
36
+
41
37
  def loadView
42
38
  if @next_view.nil?
43
39
  super
@@ -48,7 +44,6 @@ module Dynamics
48
44
 
49
45
  def viewDidLoad
50
46
  super
51
-
52
47
  if name == 'Main'
53
48
  self.title = App.name
54
49
  self.view.backgroundColor = UIColor.whiteColor
@@ -56,9 +51,11 @@ module Dynamics
56
51
  self.title = name
57
52
  self.view.backgroundColor = UIColor.grayColor
58
53
  end
59
-
60
- load
61
54
  end
55
+
56
+ def nextScreen
57
+ self.navigationController.pushViewController(@next_controller, animated: true)
58
+ end
62
59
  end
63
60
 
64
61
  class View < UIView
data/lib/dynamics.rb CHANGED
@@ -19,7 +19,7 @@ module Dynamics
19
19
  Dir.mkdir(resources_dir)
20
20
  Dir.mkdir(lib_dir)
21
21
 
22
- base_dir = File.join(File.dirname(__FILE__), '..', 'base')
22
+ base_dir = File.join(path, '..', 'base')
23
23
 
24
24
  f = File.new(File.join(name, 'Rakefile'), 'w+')
25
25
  code = render_code(File.join(base_dir, 'Rakefile'))
@@ -69,30 +69,25 @@ module Dynamics
69
69
  f = File.new(File.join(views_dir, 'sub2_view.rb'), 'w+')
70
70
  f.write(render_code(File.join(base_dir, 'app', 'views', 'sub2_view.rb')))
71
71
  f.close
72
-
73
- # Lib
74
-
75
- f = File.new(File.join(lib_dir, 'dynamics.rb'), 'w+')
76
- f.write(render_code(File.join(base_dir, 'templates', 'dynamics.rb')) )
77
- f.close
78
72
  end
79
73
  end
80
74
 
81
75
  def self.setup_framework(app, path)
82
- lib_dir = File.join(path, 'lib')
83
- lib_code = render_code(File.join(lib_dir, 'dynamics.rb'))
84
- new_code = lib_code
85
- lib_code.scan(/# @@.+?@@.+?# @@End@@/m) do |block|
76
+ lib_dir = File.join(path, 'lib')
77
+ templates_dir = File.join(Gem.bin_path('dynamics', 'dynamics').gsub(File.join('bin', 'dynamics'), ''), 'base', 'templates')
78
+
79
+ template_code = lib_code = render_code(File.join(templates_dir, 'dynamics.rb'))
80
+ template_code.scan(/# @@.+?@@.+?# @@End@@/m) do |block|
86
81
  block.scan(/^# @@.+?@@/) do |placeholder|
87
82
  layout = placeholder.gsub('# @@', '').gsub('@', '')
88
83
  case layout
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))
84
+ when 'Navigation' then lib_code = lib_code.gsub(block, navigation_code(path))
85
+ when 'Tab Bar' then lib_code = lib_code.gsub(block, tab_bar_code(path))
91
86
  end
92
87
  end
93
88
  end
94
89
  f = File.open(File.join(lib_dir, 'dynamics.rb'), 'w+')
95
- f.write(new_code)
90
+ f.write(lib_code)
96
91
  f.close
97
92
 
98
93
  app.files.unshift(File.join(lib_dir, 'dynamics.rb'))
@@ -125,7 +120,7 @@ private
125
120
  code += " main_controller = MainController.alloc.initWithNibName(nil, bundle: nil)\n"
126
121
  controllers = find_controllers(path)
127
122
  if controllers.size > 0
128
- code += " main_controller.navigationItem.rightBarButtonItem = UIBarButtonItem.alloc.initWithTitle('#{controllers.first[:name]}', style: UIBarButtonItemStyleBordered, target:main_controller, action:'push')\n"
123
+ code += " main_controller.navigationItem.rightBarButtonItem = UIBarButtonItem.alloc.initWithTitle('#{controllers.first[:name]}', style: UIBarButtonItemStyleBordered, target:main_controller, action:'nextScreen')\n"
129
124
  end
130
125
  i = 1
131
126
  prev_controller = 'main_controller'
@@ -134,7 +129,7 @@ private
134
129
  code += " sub#{i}_controller.next_view = #{controller[:name]}View.alloc.initWithFrame(UIScreen.mainScreen.bounds)\n"
135
130
  code += " #{prev_controller}.next_controller = sub#{i}_controller\n"
136
131
  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"
132
+ code += " sub#{i}_controller.navigationItem.rightBarButtonItem = UIBarButtonItem.alloc.initWithTitle('#{controllers[i][:name]}', style: UIBarButtonItemStyleBordered, target:sub#{i}_controller, action:'nextScreen')\n"
138
133
  prev_controller = "sub#{i}_controller"
139
134
  i += 1
140
135
  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: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ng Say Joe
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-07-22 00:00:00 Z
18
+ date: 2012-08-01 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: A framework for developing RubyMotion applications quickly.