boa 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/README.md +13 -1
  2. data/lib/boa/commands.rb +26 -6
  3. data/lib/boa/module/module.rb +26 -5
  4. data/lib/boa/module/templates/{DataManager.h → objc/DataManager.h} +0 -0
  5. data/lib/boa/module/templates/{DataManager.m → objc/DataManager.m} +0 -0
  6. data/lib/boa/module/templates/{DependenciesBody.m → objc/DependenciesBody.m} +0 -0
  7. data/lib/boa/module/templates/{DependenciesHead.m → objc/DependenciesHead.m} +0 -0
  8. data/lib/boa/module/templates/{Interactor.h → objc/Interactor.h} +0 -0
  9. data/lib/boa/module/templates/{Interactor.m → objc/Interactor.m} +0 -0
  10. data/lib/boa/module/templates/{ModuleInterface.h → objc/ModuleInterface.h} +0 -0
  11. data/lib/boa/module/templates/{Presenter.h → objc/Presenter.h} +0 -0
  12. data/lib/boa/module/templates/{Presenter.m → objc/Presenter.m} +0 -0
  13. data/lib/boa/module/templates/{ViewController.h → objc/ViewController.h} +0 -0
  14. data/lib/boa/module/templates/{ViewController.m → objc/ViewController.m} +0 -0
  15. data/lib/boa/module/templates/{ViewInterface.h → objc/ViewInterface.h} +0 -0
  16. data/lib/boa/module/templates/{Wireframe.h → objc/Wireframe.h} +0 -0
  17. data/lib/boa/module/templates/{Wireframe.m → objc/Wireframe.m} +0 -0
  18. data/lib/boa/module/templates/swift/DataManager.swift +14 -0
  19. data/lib/boa/module/templates/swift/DependenciesBody.swift +32 -0
  20. data/lib/boa/module/templates/swift/DependenciesHead.swift +1 -0
  21. data/lib/boa/module/templates/swift/Interactor.swift +15 -0
  22. data/lib/boa/module/templates/swift/ModuleInterface.swift +19 -0
  23. data/lib/boa/module/templates/swift/Presenter.swift +19 -0
  24. data/lib/boa/module/templates/swift/ViewController.swift +40 -0
  25. data/lib/boa/module/templates/swift/ViewInterface.swift +14 -0
  26. data/lib/boa/module/templates/swift/Wireframe.swift +30 -0
  27. data/lib/boa/templates/{AppDelegate.h → objc/AppDelegate.h} +0 -0
  28. data/lib/boa/templates/{AppDelegate.m → objc/AppDelegate.m} +0 -0
  29. data/lib/boa/templates/{AppDependencies.h → objc/AppDependencies.h} +0 -0
  30. data/lib/boa/templates/{AppDependencies.m → objc/AppDependencies.m} +0 -0
  31. data/lib/boa/templates/{RootWireframe.h → objc/RootWireframe.h} +0 -0
  32. data/lib/boa/templates/{RootWireframe.m → objc/RootWireframe.m} +0 -0
  33. data/lib/boa/templates/swift/AppDelegate.swift +33 -0
  34. data/lib/boa/templates/swift/AppDependencies.swift +38 -0
  35. data/lib/boa/templates/swift/RootWireframe.swift +19 -0
  36. data/lib/boa/version.rb +1 -1
  37. metadata +34 -22
data/README.md CHANGED
@@ -18,7 +18,14 @@ Install gem with:
18
18
  boa init
19
19
  ```
20
20
 
21
- 3. Input your project name and the author (these will be used in generated files). You can change these settings in `.boa.yml`
21
+ 3. Input
22
+
23
+ * your project name
24
+ * preferred language
25
+ * author
26
+ # class prefix
27
+
28
+ (these will be used in generated files). You can change these settings in `.boa.yml`
22
29
 
23
30
  4. Create your module with
24
31
 
@@ -26,8 +33,13 @@ boa init
26
33
  boa module create Example
27
34
  ```
28
35
 
36
+ You can use saved configuration by just pressing enters.
37
+
29
38
  ## Changes
30
39
 
40
+ #### v0.3
41
+ * Swift syntax added
42
+
31
43
  #### v0.2
32
44
  * added class prefix option
33
45
  * added basic appledoc comments for interfaces and protocols
@@ -12,18 +12,27 @@ module Boa
12
12
 
13
13
  # ----
14
14
  # initialize VIPER hierarchy
15
- BASE_FILES = {
15
+ BASE_FILES_OBJC = {
16
16
  'AppDelegate.h' => 'Classes',
17
17
  'AppDelegate.m' => 'Classes',
18
18
  'AppDependencies.h' => 'Classes',
19
19
  'AppDependencies.m' => 'Classes'
20
20
  }
21
21
 
22
- PROJECT_FILES = {
22
+ BASE_FILES_SWIFT = {
23
+ 'AppDelegate.swift' => 'Classes',
24
+ 'AppDependencies.swift' => 'Classes'
25
+ }
26
+
27
+ PROJECT_FILES_OBJC = {
23
28
  'RootWireframe.h' => 'Classes/Common/Wireframe',
24
29
  'RootWireframe.m' => 'Classes/Common/Wireframe'
25
30
  }
26
31
 
32
+ PROJECT_FILES_SWIFT = {
33
+ 'RootWireframe.swift' => 'Classes/Common/Wireframe'
34
+ }
35
+
27
36
  desc 'init', 'initializes VIPER project'
28
37
  def init
29
38
  config = invoke(:configure, [])
@@ -46,14 +55,23 @@ module Boa
46
55
  @project = config[:project]
47
56
  @author = config[:author]
48
57
  @date = Time.now.strftime('%d/%m/%y')
58
+ lang = config[:language]
49
59
 
50
60
  # Generate files
51
- BASE_FILES.each do |file_name, folder|
52
- template "templates/#{file_name}", "#{folder}/#{@project}#{file_name}"
61
+ base_files = case lang
62
+ when 'objc' then BASE_FILES_OBJC
63
+ when 'swift' then BASE_FILES_SWIFT
64
+ end
65
+ base_files.each do |file_name, folder|
66
+ template "templates/#{lang}/#{file_name}", "#{folder}/#{@project}#{file_name}"
53
67
  end
54
68
 
55
- PROJECT_FILES.each do |file_name, folder|
56
- template "templates/#{file_name}", "#{folder}/#{file_name}"
69
+ project_files = case lang
70
+ when 'objc' then PROJECT_FILES_OBJC
71
+ when 'swift' then PROJECT_FILES_SWIFT
72
+ end
73
+ project_files.each do |file_name, folder|
74
+ template "templates/#{lang}/#{file_name}", "#{folder}/#{file_name}"
57
75
  end
58
76
  end
59
77
 
@@ -66,10 +84,12 @@ module Boa
66
84
  config = File.exists?(CONFIG_FILE) ? YAML.load_file(CONFIG_FILE) : {}
67
85
 
68
86
  project = ask("Project name [#{config[:project]}] ?")
87
+ language = ask("Project language [#{config[:language]}] ?", :limited_to => ["objc", "swift", ""])
69
88
  class_prefix = ask("Class prefix [#{config[:class_prefix]}] ?")
70
89
  author = ask("Author [#{config[:author]}] ?")
71
90
 
72
91
  config[:project] = project.empty? ? config[:project] || '' : project
92
+ config[:language] = language.empty? ? config[:language] || 'objc' : language
73
93
  config[:class_prefix] = class_prefix.empty? ? config[:class_prefix] || '' : class_prefix
74
94
  config[:author] = author.empty? ? config[:author] || '' : author
75
95
 
@@ -6,7 +6,7 @@ module Boa
6
6
 
7
7
  BASE_PATH = 'Classes/Modules'
8
8
 
9
- FILES = {
9
+ FILES_OBJC = {
10
10
  'DataManager.h' => 'DataManager',
11
11
  'DataManager.m' => 'DataManager',
12
12
  'Interactor.h' => 'Interactor',
@@ -21,6 +21,16 @@ module Boa
21
21
  'Wireframe.m' => 'Wireframe'
22
22
  }
23
23
 
24
+ FILES_SWIFT = {
25
+ 'DataManager.swift' => 'DataManager',
26
+ 'Interactor.swift' => 'Interactor',
27
+ 'ModuleInterface.swift' => 'ModuleInterface',
28
+ 'Presenter.swift' => 'Presenter',
29
+ 'ViewInterface.swift' => 'View',
30
+ 'ViewController.swift' => 'View',
31
+ 'Wireframe.swift' => 'Wireframe'
32
+ }
33
+
24
34
  Boa::Module.source_root(File.dirname(__FILE__))
25
35
 
26
36
  desc 'list', 'lists available VIPER modules'
@@ -40,22 +50,33 @@ module Boa
40
50
  @project = config[:project]
41
51
  @author = config[:author]
42
52
  @date = Time.now.strftime('%d/%m/%y')
53
+ lang = config[:language]
43
54
 
44
55
  # copying template files
45
- FILES.each do |file_name, folder|
46
- template "templates/#{file_name}", "#{BASE_PATH}/#{@module}/#{folder}/#{@prefixed_module}#{file_name}"
56
+ files = case lang
57
+ when 'objc' then FILES_OBJC
58
+ when 'swift' then FILES_SWIFT
59
+ end
60
+ files.each do |file_name, folder|
61
+ template "templates/#{lang}/#{file_name}", "#{BASE_PATH}/#{@module}/#{folder}/#{@prefixed_module}#{file_name}"
47
62
  end
48
63
 
49
64
  # rendering dependencies head
50
65
  path = Dir::Tmpname.create('dep') { |path| path }
51
- template 'templates/DependenciesHead.m', path
66
+ case lang
67
+ when 'objc' then template('templates/objc/DependenciesHead.m', path)
68
+ when 'swift' then template('templates/swift/DependenciesHead.swift', path)
69
+ end
52
70
 
53
71
  say "\nAdd these lines to the AppDependencies imports:\n\n", :green
54
72
  say File.open(path).read + "\n", :yellow
55
73
 
56
74
  # rendering dependencies body
57
75
  path = Dir::Tmpname.create('dep') { |path| path }
58
- template 'templates/DependenciesBody.m', path
76
+ case lang
77
+ when 'objc' then template('templates/objc/DependenciesBody.m', path)
78
+ when 'swift' then template('templates/swift/DependenciesBody.swift', path)
79
+ end
59
80
 
60
81
  say "\nAdd these lines to the AppDependencies#configureDependencies:\n\n", :green
61
82
  say File.open(path).read + "\n", :yellow
@@ -0,0 +1,14 @@
1
+ //
2
+ // <%= @prefixed_module %>DataManager.swift
3
+ // <%= @project %>
4
+ //
5
+ // Created by <%= @author %> on <%= @date %>.
6
+ //
7
+ //
8
+
9
+ import Foundation
10
+
11
+ class <%= @prefixed_module %>DataManager: NSObject
12
+ {
13
+
14
+ }
@@ -0,0 +1,32 @@
1
+ // ------------------------------------------------------------------
2
+ // begin <%= @module %> module
3
+
4
+ // instantiate classes
5
+ var <%= @module.downcase %>Wireframe: <%= @prefixed_module %>Wireframe = <%= @prefixed_module %>Wireframe()
6
+ var <%= @module.downcase %>Presenter: <%= @prefixed_module %>Presenter = <%= @prefixed_module %>Presenter()
7
+ var <%= @module.downcase %>DataManager: <%= @prefixed_module %>DataManager = <%= @prefixed_module %>DataManager()
8
+ var <%= @module.downcase %>Interactor: <%= @prefixed_module %>Interactor = <%= @prefixed_module %>Interactor()
9
+
10
+ // presenter <-> wireframe
11
+ <%= @module.downcase %>Presenter.wireframe = <%= @module.downcase %>Wireframe
12
+ <%= @module.downcase %>Wireframe.presenter = <%= @module.downcase %>Presenter
13
+
14
+ // presenter <-> interactor
15
+ <%= @module.downcase %>Presenter.interactor = <%= @module.downcase %>Interactor
16
+ <%= @module.downcase %>Interactor.presenter = <%= @module.downcase %>Presenter
17
+
18
+ // interactor -> data_manager
19
+ <%= @module.downcase %>Interactor.dataManager = <%= @module.downcase %>DataManager
20
+
21
+ // data_manager -> data_store
22
+ // *** connect datastore
23
+
24
+ // connect wireframes
25
+ <%= @module.downcase %>Wireframe.rootWireframe = rootWireframe
26
+ // *** connect more wireframes
27
+
28
+ // configure delegate
29
+ // *** add delegate here if needed
30
+
31
+ // end <%= @module %> module
32
+ // ------------------------------------------------------------------
@@ -0,0 +1 @@
1
+ // no adding needed
@@ -0,0 +1,15 @@
1
+ //
2
+ // <%= @prefixed_module %>Interactor.swift
3
+ // <%= @project %>
4
+ //
5
+ // Created by <%= @author %> on <%= @date %>.
6
+ //
7
+ //
8
+
9
+ import Foundation
10
+
11
+ class <%= @prefixed_module %>Interactor: NSObject
12
+ {
13
+ var presenter: <%= @prefixed_module %>Presenter?
14
+ var dataManager: <%= @prefixed_module %>DataManager?
15
+ }
@@ -0,0 +1,19 @@
1
+ //
2
+ // <%= @prefixed_module %>ModuleInterface.swift
3
+ // <%= @project %>
4
+ //
5
+ // Created by <%= @author %> on <%= @date %>.
6
+ //
7
+ //
8
+
9
+ import Foundation
10
+
11
+ protocol <%= @prefixed_module %>ModuleInterface
12
+ {
13
+
14
+ }
15
+
16
+ protocol <%= @prefixed_module %>ModuleDelegate
17
+ {
18
+
19
+ }
@@ -0,0 +1,19 @@
1
+ //
2
+ // <%= @prefixed_module %>Presenter.swift
3
+ // <%= @project %>
4
+ //
5
+ // Created by <%= @author %> on <%= @date %>.
6
+ //
7
+ //
8
+
9
+ import Foundation
10
+
11
+ class <%= @prefixed_module %>Presenter: NSObject, <%= @prefixed_module %>ModuleInterface
12
+ {
13
+ var interactor: <%= @prefixed_module %>Interactor?
14
+ var wireframe: <%= @prefixed_module %>Wireframe?
15
+ var userInterface: <%= @prefixed_module %>ViewInterface?
16
+
17
+ // MARK: - <%= @prefixed_module %>ModuleInterface methods
18
+ // implement module interface here
19
+ }
@@ -0,0 +1,40 @@
1
+ //
2
+ // <%= @prefixed_module %>ViewController.swift
3
+ // <%= @project %>
4
+ //
5
+ // Created by <%= @author %> on <%= @date %>.
6
+ //
7
+ //
8
+
9
+ import UIKit
10
+
11
+ class <%= @prefixed_module %>ViewController: UIViewController, <%= @prefixed_module %>ViewInterface
12
+ {
13
+ var eventHandler: <%= @prefixed_module %>ModuleInterface?
14
+
15
+ // MARK: - View lifecycle
16
+
17
+ override func viewDidLoad()
18
+ {
19
+ super.viewDidLoad()
20
+ }
21
+
22
+ override func viewWillAppear(animated: Bool)
23
+ {
24
+ super.viewWillAppear(animated)
25
+ }
26
+
27
+ override func viewDidAppear(animated: Bool)
28
+ {
29
+ super.viewDidAppear(animated)
30
+ }
31
+
32
+ // MARK: - <%= @prefixed_module %>ViewInterface methods
33
+
34
+ // *** implement view_interface methods here
35
+
36
+ // MARK: - Button event handlers
37
+
38
+ // ** handle UI events here
39
+
40
+ }
@@ -0,0 +1,14 @@
1
+ //
2
+ // <%= @prefixed_module %>View.h
3
+ // <%= @project %>
4
+ //
5
+ // Created by <%= @author %> on <%= @date %>.
6
+ //
7
+ //
8
+
9
+ import Foundation
10
+
11
+ protocol <%= @prefixed_module %>ViewInterface
12
+ {
13
+
14
+ }
@@ -0,0 +1,30 @@
1
+ //
2
+ // <%= @prefixed_module %>Wireframe.swift
3
+ // <%= @project %>
4
+ //
5
+ // Created by <%= @author %> on <%= @date %>.
6
+ //
7
+ //
8
+
9
+ import Foundation
10
+ import UIKit
11
+
12
+ class <%= @prefixed_module %>Wireframe: NSObject
13
+ {
14
+ var rootWireframe: RootWireframe?
15
+ var presenter: <%= @prefixed_module %>Presenter?
16
+ var viewController: <%= @prefixed_module %>ViewController?
17
+
18
+ func presentSelfFromViewController(viewController: UIViewController)
19
+ {
20
+ // save reference
21
+ self.viewController = <%= @prefixed_module %>ViewController(nibName: "<%= @prefixed_module %>ViewController", bundle: nil)
22
+
23
+ // view <-> presenter
24
+ self.presenter?.userInterface = self.viewController
25
+ self.viewController?.eventHandler = self.presenter
26
+
27
+ // present controller
28
+ // *** present self with RootViewController
29
+ }
30
+ }
@@ -0,0 +1,33 @@
1
+ //
2
+ // <%= @project %>AppDelegate.swift
3
+ // <%= @project %>
4
+ //
5
+ // Created by <%= @author %> on <%= @date %>.
6
+ //
7
+ //
8
+
9
+ import UIKit
10
+
11
+ @UIApplicationMain
12
+ class <%= @project %>AppDelegate: UIResponder, UIApplicationDelegate
13
+ {
14
+ var window: UIWindow?
15
+ var dependencies: <%= @project %>AppDependencies?
16
+
17
+ func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool
18
+ {
19
+ // initialize window
20
+ self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
21
+ self.window?.backgroundColor = UIColor.whiteColor()
22
+
23
+ // initialize dependencies
24
+ self.dependencies = <%= @project %>AppDependencies.initWithWindow(self.window!)
25
+
26
+ // adding RootViewController
27
+ self.dependencies?.installRootViewController()
28
+
29
+ self.window!.makeKeyAndVisible()
30
+
31
+ return true
32
+ }
33
+ }
@@ -0,0 +1,38 @@
1
+ //
2
+ // <%= @project %>AppDependencies.swift
3
+ // <%= @project %>
4
+ //
5
+ // Created by <%= @author %> on <%= @date %>.
6
+ //
7
+ //
8
+
9
+ import Foundation
10
+ import UIKit
11
+
12
+ class <%= @project %>AppDependencies: NSObject
13
+ {
14
+
15
+ class func initWithWindow(window: UIWindow) -> <%= @project %>AppDependencies
16
+ {
17
+
18
+ let obj = <%= @project %>AppDependencies()
19
+ obj.configureDependencies(window)
20
+
21
+ return obj
22
+ }
23
+
24
+ func installRootViewController()
25
+ {
26
+ // *** present first wireframe here
27
+ }
28
+
29
+ func configureDependencies(window: UIWindow)
30
+ {
31
+ // -----
32
+ // root classes
33
+ let rootWireframe = RootWireframe.init(window: window)
34
+ // *** add datastore
35
+
36
+ // *** module initialization
37
+ }
38
+ }
@@ -0,0 +1,19 @@
1
+ //
2
+ // RootWireframe.swift
3
+ // <%= @project %>
4
+ //
5
+ // Created by <%= @author %> on <%= @date %>.
6
+ //
7
+ //
8
+
9
+ import Foundation
10
+ import UIKit
11
+
12
+ class RootWireframe: NSObject
13
+ {
14
+ init(window: UIWindow)
15
+ {
16
+ super.init()
17
+ // custom initialization
18
+ }
19
+ }
@@ -1,3 +1,3 @@
1
1
  module Boa
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-02 00:00:00.000000000 Z
12
+ date: 2014-11-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -77,26 +77,38 @@ files:
77
77
  - lib/boa.rb
78
78
  - lib/boa/commands.rb
79
79
  - lib/boa/module/module.rb
80
- - lib/boa/module/templates/DataManager.h
81
- - lib/boa/module/templates/DataManager.m
82
- - lib/boa/module/templates/DependenciesBody.m
83
- - lib/boa/module/templates/DependenciesHead.m
84
- - lib/boa/module/templates/Interactor.h
85
- - lib/boa/module/templates/Interactor.m
86
- - lib/boa/module/templates/ModuleInterface.h
87
- - lib/boa/module/templates/Presenter.h
88
- - lib/boa/module/templates/Presenter.m
89
- - lib/boa/module/templates/ViewController.h
90
- - lib/boa/module/templates/ViewController.m
91
- - lib/boa/module/templates/ViewInterface.h
92
- - lib/boa/module/templates/Wireframe.h
93
- - lib/boa/module/templates/Wireframe.m
94
- - lib/boa/templates/AppDelegate.h
95
- - lib/boa/templates/AppDelegate.m
96
- - lib/boa/templates/AppDependencies.h
97
- - lib/boa/templates/AppDependencies.m
98
- - lib/boa/templates/RootWireframe.h
99
- - lib/boa/templates/RootWireframe.m
80
+ - lib/boa/module/templates/objc/DataManager.h
81
+ - lib/boa/module/templates/objc/DataManager.m
82
+ - lib/boa/module/templates/objc/DependenciesBody.m
83
+ - lib/boa/module/templates/objc/DependenciesHead.m
84
+ - lib/boa/module/templates/objc/Interactor.h
85
+ - lib/boa/module/templates/objc/Interactor.m
86
+ - lib/boa/module/templates/objc/ModuleInterface.h
87
+ - lib/boa/module/templates/objc/Presenter.h
88
+ - lib/boa/module/templates/objc/Presenter.m
89
+ - lib/boa/module/templates/objc/ViewController.h
90
+ - lib/boa/module/templates/objc/ViewController.m
91
+ - lib/boa/module/templates/objc/ViewInterface.h
92
+ - lib/boa/module/templates/objc/Wireframe.h
93
+ - lib/boa/module/templates/objc/Wireframe.m
94
+ - lib/boa/module/templates/swift/DataManager.swift
95
+ - lib/boa/module/templates/swift/DependenciesBody.swift
96
+ - lib/boa/module/templates/swift/DependenciesHead.swift
97
+ - lib/boa/module/templates/swift/Interactor.swift
98
+ - lib/boa/module/templates/swift/ModuleInterface.swift
99
+ - lib/boa/module/templates/swift/Presenter.swift
100
+ - lib/boa/module/templates/swift/ViewController.swift
101
+ - lib/boa/module/templates/swift/ViewInterface.swift
102
+ - lib/boa/module/templates/swift/Wireframe.swift
103
+ - lib/boa/templates/objc/AppDelegate.h
104
+ - lib/boa/templates/objc/AppDelegate.m
105
+ - lib/boa/templates/objc/AppDependencies.h
106
+ - lib/boa/templates/objc/AppDependencies.m
107
+ - lib/boa/templates/objc/RootWireframe.h
108
+ - lib/boa/templates/objc/RootWireframe.m
109
+ - lib/boa/templates/swift/AppDelegate.swift
110
+ - lib/boa/templates/swift/AppDependencies.swift
111
+ - lib/boa/templates/swift/RootWireframe.swift
100
112
  - lib/boa/version.rb
101
113
  homepage: https://github.com/jbslabs/boa
102
114
  licenses: