iosgen 1.0.0 → 1.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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/Demo/iOSCleanArchitectureGenerator/iOSCleanArchitectureGenerator.xcodeproj/project.pbxproj +501 -0
  3. data/Demo/iOSCleanArchitectureGenerator/iOSCleanArchitectureGenerator.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  4. data/Demo/iOSCleanArchitectureGenerator/iOSCleanArchitectureGenerator.xcodeproj/xcuserdata/fran_dev.xcuserdatad/xcschemes/iOSCleanArchitectureGenerator.xcscheme +110 -0
  5. data/Demo/iOSCleanArchitectureGenerator/iOSCleanArchitectureGenerator.xcodeproj/xcuserdata/fran_dev.xcuserdatad/xcschemes/xcschememanagement.plist +27 -0
  6. data/Demo/iOSCleanArchitectureGenerator/iOSCleanArchitectureGenerator/AppDelegate.h +17 -0
  7. data/Demo/iOSCleanArchitectureGenerator/iOSCleanArchitectureGenerator/AppDelegate.m +45 -0
  8. data/Demo/iOSCleanArchitectureGenerator/iOSCleanArchitectureGenerator/Base.lproj/LaunchScreen.xib +41 -0
  9. data/Demo/iOSCleanArchitectureGenerator/iOSCleanArchitectureGenerator/Base.lproj/Main.storyboard +25 -0
  10. data/Demo/iOSCleanArchitectureGenerator/iOSCleanArchitectureGenerator/Images.xcassets/AppIcon.appiconset/Contents.json +68 -0
  11. data/Demo/iOSCleanArchitectureGenerator/iOSCleanArchitectureGenerator/Info.plist +47 -0
  12. data/Demo/iOSCleanArchitectureGenerator/iOSCleanArchitectureGenerator/Interactors/FJBNotificationsApiInteractor.h +9 -0
  13. data/Demo/iOSCleanArchitectureGenerator/iOSCleanArchitectureGenerator/Interactors/FJBNotificationsApiInteractor.m +15 -0
  14. data/Demo/iOSCleanArchitectureGenerator/iOSCleanArchitectureGenerator/Interactors/FJBNotificationsApiInteractorProtocol.h +9 -0
  15. data/Demo/iOSCleanArchitectureGenerator/iOSCleanArchitectureGenerator/ViewController.h +15 -0
  16. data/Demo/iOSCleanArchitectureGenerator/iOSCleanArchitectureGenerator/ViewController.m +27 -0
  17. data/Demo/iOSCleanArchitectureGenerator/iOSCleanArchitectureGenerator/ViewControllers/FJBNotificationsViewController.h +8 -0
  18. data/Demo/iOSCleanArchitectureGenerator/iOSCleanArchitectureGenerator/ViewControllers/FJBNotificationsViewController.m +31 -0
  19. data/Demo/iOSCleanArchitectureGenerator/iOSCleanArchitectureGenerator/ViewModels/FJBNotificationsViewModel.h +9 -0
  20. data/Demo/iOSCleanArchitectureGenerator/iOSCleanArchitectureGenerator/ViewModels/FJBNotificationsViewModel.m +18 -0
  21. data/Demo/iOSCleanArchitectureGenerator/iOSCleanArchitectureGenerator/ViewModels/FJBNotificationsViewModelProtocol.h +17 -0
  22. data/Demo/iOSCleanArchitectureGenerator/iOSCleanArchitectureGenerator/main.m +16 -0
  23. data/Demo/iOSCleanArchitectureGenerator/iOSCleanArchitectureGeneratorTests/Info.plist +24 -0
  24. data/Demo/iOSCleanArchitectureGenerator/iOSCleanArchitectureGeneratorTests/Interactors/FJBNotificationsApiInteractorTests.m +40 -0
  25. data/Demo/iOSCleanArchitectureGenerator/iOSCleanArchitectureGeneratorTests/ViewModels/FJBNotificationsViewModelTests.m +50 -0
  26. data/Demo/iOSCleanArchitectureGenerator/iOSCleanArchitectureGeneratorTests/iOSCleanArchitectureGeneratorTests.m +40 -0
  27. data/README.md +37 -20
  28. data/bin/iosgen +1 -1
  29. data/iosgen.gemspec +1 -1
  30. data/lib/ios_gen/generator/base_generator.rb +21 -9
  31. data/lib/ios_gen/generator/objc/action_formatter.rb +15 -2
  32. data/lib/ios_gen/generator/objc/interactor_formatter.rb +16 -11
  33. data/lib/ios_gen/generator/objc/objc_formatter.rb +4 -0
  34. data/lib/ios_gen/generator/objc/view_model_formatter.rb +18 -10
  35. data/lib/ios_gen/generator/objc/xctestcase_formatter.rb +45 -0
  36. data/lib/ios_gen/ios_gen_thor.rb +2 -1
  37. data/spec/ios_gen/generator/base_generator_spec.rb +38 -3
  38. data/spec/ios_gen/generator/objc/action_formatter_spec.rb +16 -1
  39. data/spec/ios_gen/generator/objc/interactor_formatter_spec.rb +1 -1
  40. data/spec/ios_gen/generator/objc/objc_formatter_spec.rb +0 -1
  41. data/spec/ios_gen/generator/objc/view_model_formatter_spec.rb +0 -1
  42. data/spec/ios_gen/generator/objc/xctestcase_formatter_spec.rb +91 -0
  43. data/templates/objc/Interactor.h.erb +1 -1
  44. data/templates/objc/InteractorProtocol.h.erb +2 -0
  45. data/templates/objc/ViewModel.h.erb +1 -1
  46. data/templates/objc/ViewModelProtocol.h.erb +1 -0
  47. data/templates/objc/XCTestCase.m.erb +32 -0
  48. metadata +31 -2
@@ -0,0 +1,27 @@
1
+ //
2
+ // ViewController.m
3
+ // iOSCleanArchitectureGenerator
4
+ //
5
+ // Created by Francisco J. Belchi on 29/12/14.
6
+ // Copyright (c) 2014 fjbelchi. All rights reserved.
7
+ //
8
+
9
+ #import "ViewController.h"
10
+
11
+ @interface ViewController ()
12
+
13
+ @end
14
+
15
+ @implementation ViewController
16
+
17
+ - (void)viewDidLoad {
18
+ [super viewDidLoad];
19
+ // Do any additional setup after loading the view, typically from a nib.
20
+ }
21
+
22
+ - (void)didReceiveMemoryWarning {
23
+ [super didReceiveMemoryWarning];
24
+ // Dispose of any resources that can be recreated.
25
+ }
26
+
27
+ @end
@@ -0,0 +1,8 @@
1
+ #import <UIKit/UIKit.h>
2
+ #import "FJBNotificationsViewModelProtocol.h"
3
+
4
+ @interface FJBNotificationsViewController : UIViewController
5
+
6
+ - (instancetype)initWithViewModel:(id<FJBNotificationsViewModelProtocol>)viewModel;
7
+
8
+ @end
@@ -0,0 +1,31 @@
1
+ #import "FJBNotificationsViewController.h"
2
+
3
+ @interface FJBNotificationsViewController () <FJBNotificationsViewModelProtocolDelegate>
4
+
5
+ @property (nonatomic, strong) id<FJBNotificationsViewModelProtocol> viewModel;
6
+
7
+ @end
8
+
9
+ @implementation FJBNotificationsViewController
10
+
11
+ - (instancetype)init
12
+ {
13
+ self = [super init];
14
+ if (self) {
15
+ }
16
+ return self;
17
+ }
18
+
19
+ - (instancetype)initWithViewModel:(id<FJBNotificationsViewModelProtocol>)viewModel
20
+ {
21
+ self = [self init];
22
+ if (self) {
23
+ _viewModel = viewModel;
24
+ _viewModel.delegate = self;
25
+ }
26
+ return self;
27
+ }
28
+
29
+ #pragma mark - FJBNotificationsViewModelProtocolDelegate
30
+
31
+ @end
@@ -0,0 +1,9 @@
1
+ #import "FJBNotificationsViewModelProtocol.h"
2
+
3
+ @interface FJBNotificationsViewModel : NSObject <FJBNotificationsViewModelProtocol>
4
+
5
+ // -- Properties
6
+ @property (nonatomic, strong) NSIndexPath *selectedIndexPath;
7
+ @property (nonatomic, weak) id<FJBNotificationsViewModelProtocolDelegate> delegate;
8
+
9
+ @end
@@ -0,0 +1,18 @@
1
+ #import "FJBNotificationsViewModel.h"
2
+
3
+ @interface FJBNotificationsViewModel ()
4
+
5
+ @end
6
+
7
+ @implementation FJBNotificationsViewModel
8
+
9
+ #pragma mark - Actions
10
+
11
+ - (void)didTapOnCloseButton
12
+ {
13
+ }
14
+ - (void)didTapAtIndexPath:(NSIndexPath *)indexPath
15
+ {
16
+ }
17
+
18
+ @end
@@ -0,0 +1,17 @@
1
+ #import <Foundation/Foundation.h>
2
+
3
+ @protocol FJBNotificationsViewModelProtocol;
4
+ @protocol FJBNotificationsViewModelProtocolDelegate <NSObject>
5
+ @end
6
+
7
+ @protocol FJBNotificationsViewModelProtocol <NSObject>
8
+
9
+ @property (nonatomic, weak) id<FJBNotificationsViewModelProtocolDelegate> delegate;
10
+
11
+ // -- Actions
12
+ // Dismiss the ViewController when the button is tapped
13
+ - (void)didTapOnCloseButton;
14
+ // Mark notification as read when the notification is selected
15
+ - (void)didTapAtIndexPath:(NSIndexPath *)indexPath;
16
+
17
+ @end
@@ -0,0 +1,16 @@
1
+ //
2
+ // main.m
3
+ // iOSCleanArchitectureGenerator
4
+ //
5
+ // Created by Fran_DEV on 29/12/14.
6
+ // Copyright (c) 2014 fjbelchi. All rights reserved.
7
+ //
8
+
9
+ #import <UIKit/UIKit.h>
10
+ #import "AppDelegate.h"
11
+
12
+ int main(int argc, char * argv[]) {
13
+ @autoreleasepool {
14
+ return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15
+ }
16
+ }
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleDevelopmentRegion</key>
6
+ <string>en</string>
7
+ <key>CFBundleExecutable</key>
8
+ <string>$(EXECUTABLE_NAME)</string>
9
+ <key>CFBundleIdentifier</key>
10
+ <string>com.fjbelchi.$(PRODUCT_NAME:rfc1034identifier)</string>
11
+ <key>CFBundleInfoDictionaryVersion</key>
12
+ <string>6.0</string>
13
+ <key>CFBundleName</key>
14
+ <string>$(PRODUCT_NAME)</string>
15
+ <key>CFBundlePackageType</key>
16
+ <string>BNDL</string>
17
+ <key>CFBundleShortVersionString</key>
18
+ <string>1.0</string>
19
+ <key>CFBundleSignature</key>
20
+ <string>????</string>
21
+ <key>CFBundleVersion</key>
22
+ <string>1</string>
23
+ </dict>
24
+ </plist>
@@ -0,0 +1,40 @@
1
+ //
2
+ // FJBNotificationsApiInteractorTests.m
3
+ // FJBNotificationsApiInteractorTests
4
+ //
5
+ // Created by fran_dev on 30/12/2014.
6
+ // Copyright (c) 2014. All rights reserved.
7
+ //
8
+
9
+ #import <XCTest/XCTest.h>
10
+
11
+ @interface FJBNotificationsApiInteractorTests : XCTestCase
12
+
13
+ @end
14
+
15
+ @implementation FJBNotificationsApiInteractorTests
16
+
17
+ - (void)setUp {
18
+ [super setUp];
19
+ // Put setup code here. This method is called before the invocation of each test method in the class.
20
+ }
21
+
22
+ - (void)tearDown {
23
+ // Put teardown code here. This method is called after the invocation of each test method in the class.
24
+ [super tearDown];
25
+ }
26
+
27
+ #pragma mark - Actions
28
+
29
+ // Perform API request to mark a notification as read
30
+
31
+ - (void)testmarkNotificationAsReadonCompletionBlockShouldPass
32
+ {
33
+ // given
34
+ // when
35
+ // then
36
+ XCTFail(@"No implemented test");
37
+ }
38
+
39
+
40
+ @end
@@ -0,0 +1,50 @@
1
+ //
2
+ // FJBNotificationsViewModelTests.m
3
+ // FJBNotificationsViewModelTests
4
+ //
5
+ // Created by fran_dev on 30/12/2014.
6
+ // Copyright (c) 2014. All rights reserved.
7
+ //
8
+
9
+ #import <XCTest/XCTest.h>
10
+
11
+ @interface FJBNotificationsViewModelTests : XCTestCase
12
+
13
+ @end
14
+
15
+ @implementation FJBNotificationsViewModelTests
16
+
17
+ - (void)setUp {
18
+ [super setUp];
19
+ // Put setup code here. This method is called before the invocation of each test method in the class.
20
+ }
21
+
22
+ - (void)tearDown {
23
+ // Put teardown code here. This method is called after the invocation of each test method in the class.
24
+ [super tearDown];
25
+ }
26
+
27
+ #pragma mark - Actions
28
+
29
+ // Dismiss the ViewController when the button is tapped
30
+
31
+ - (void)testdidTapOnCloseButtonShouldPass
32
+ {
33
+ // given
34
+ // when
35
+ // then
36
+ XCTFail(@"No implemented test");
37
+ }
38
+
39
+ // Mark notification as read when the notification is selected
40
+
41
+ - (void)testdidTapAtIndexPathShouldPass
42
+ {
43
+ // given
44
+ // when
45
+ // then
46
+ XCTFail(@"No implemented test");
47
+ }
48
+
49
+
50
+ @end
@@ -0,0 +1,40 @@
1
+ //
2
+ // iOSCleanArchitectureGeneratorTests.m
3
+ // iOSCleanArchitectureGeneratorTests
4
+ //
5
+ // Created by Fran_DEV on 29/12/14.
6
+ // Copyright (c) 2014 fjbelchi. All rights reserved.
7
+ //
8
+
9
+ #import <UIKit/UIKit.h>
10
+ #import <XCTest/XCTest.h>
11
+
12
+ @interface iOSCleanArchitectureGeneratorTests : XCTestCase
13
+
14
+ @end
15
+
16
+ @implementation iOSCleanArchitectureGeneratorTests
17
+
18
+ - (void)setUp {
19
+ [super setUp];
20
+ // Put setup code here. This method is called before the invocation of each test method in the class.
21
+ }
22
+
23
+ - (void)tearDown {
24
+ // Put teardown code here. This method is called after the invocation of each test method in the class.
25
+ [super tearDown];
26
+ }
27
+
28
+ - (void)testExample {
29
+ // This is an example of a functional test case.
30
+ XCTAssert(YES, @"Pass");
31
+ }
32
+
33
+ - (void)testPerformanceExample {
34
+ // This is an example of a performance test case.
35
+ [self measureBlock:^{
36
+ // Put the code you want to measure the time of here.
37
+ }];
38
+ }
39
+
40
+ @end
data/README.md CHANGED
@@ -3,25 +3,51 @@ Clean iOS architecture generator
3
3
  [![Build Status](https://travis-ci.org/fjbelchi/clean-iOS-architecture-generator.svg)](https://travis-ci.org/fjbelchi/clean-iOS-architecture-generator)
4
4
  [![Coverage Status](https://coveralls.io/repos/fjbelchi/clean-iOS-architecture-generator/badge.png)](https://coveralls.io/r/fjbelchi/clean-iOS-architecture-generator)
5
5
  [![Code Climate](https://codeclimate.com/github/fjbelchi/clean-iOS-architecture-generator/badges/gpa.svg)](https://codeclimate.com/github/fjbelchi/clean-iOS-architecture-generator)
6
+ [![Gem Version](https://badge.fury.io/rb/iosgen.svg)](http://badge.fury.io/rb/iosgen)
6
7
 
7
- Ruby script to generate a clean iOS architecture based on a spec file written in json format.
8
- Having the following components, the script will generate files according and it will add some logic in order to save development time.
8
+ Ruby gem to generate a clean iOS architecture based on a spec file written in json format.
9
+ Having the following components, the gem will generate files according and it will add some logic in order to save development time.
9
10
 
10
11
  In the [roadmap](https://github.com/fjbelchi/clean-iOS-architecture-generator/issues) there are features like estimations and creation of tickets in Github Issues and others management tools.
11
12
 
12
- Working in progress project
13
+ ## Install
13
14
 
15
+ ```shell
16
+ gem install iosgen
17
+ ```
18
+
19
+ #### Execute
20
+
21
+ ```shell
22
+ $ iosgen generate spec.json
23
+ spec.json
24
+ [+] Created FJBNotificationsViewController.h
25
+ [+] Created FJBNotificationsViewController.m
26
+ [+] Created FJBNotificationsViewModelProtocol.h
27
+ [+] Created FJBNotificationsViewModel.h
28
+ [+] Created FJBNotificationsViewModel.m
29
+ [+] Created FJBNotificationsApiInteractorProtocol.h
30
+ [+] Created FJBNotificationsApiInteractor.h
31
+ [+] Created FJBNotificationsApiInteractor.m
32
+ ```
14
33
  ## Components
15
34
 
16
35
  #### Property
36
+
37
+ The property object is composited of two strings, type and name, which repesent variables.
38
+ * type : Any Object type
39
+ * name : name of the object
40
+
17
41
  ```json
18
42
  {
19
- "Type": "NSIndexPath *",
20
- "Name": "selectedIndexPath"
43
+ "type": "NSIndexPath *",
44
+ "name": "selectedIndexPath"
21
45
  }
22
46
  ```
23
47
 
24
48
  #### Action
49
+
50
+
25
51
  ```json
26
52
  {
27
53
  "description": "Dismiss the ViewController when the button is tapped",
@@ -35,6 +61,10 @@ Working in progress project
35
61
  ```
36
62
 
37
63
  #### Interactor
64
+
65
+ Interactor is an object which perform actions for other components.
66
+ In this example the ViewModel needs to comunicate to the server which notification has been mark as read.
67
+
38
68
  ```json
39
69
  {
40
70
  "description" : "Api Interactions required by Notification ViewModel",
@@ -61,6 +91,7 @@ Working in progress project
61
91
  ```
62
92
 
63
93
  #### ViewModel
94
+
64
95
  ```json
65
96
  {
66
97
  "description" : "State of NotificationViewController and perform bussiness logic",
@@ -72,6 +103,7 @@ Working in progress project
72
103
  ```
73
104
 
74
105
  #### UIViewController
106
+
75
107
  ```json
76
108
  "view_controller": {
77
109
  "description": "ViewController to show the list of notifications",
@@ -141,18 +173,3 @@ Working in progress project
141
173
  }
142
174
  }
143
175
  ```
144
-
145
- #### Output
146
- ```shell
147
- $ ./iosgen.rb spec ../spec/ios_gen/generator/spec.json
148
- ../spec/ios_gen/generator/spec.json
149
- [+] Created FJBNotificationsViewController.h
150
- [+] Created FJBNotificationsViewController.m
151
- [+] Created FJBNotificationsViewModelProtocol.h
152
- [+] Created FJBNotificationsViewModel.h
153
- [+] Created FJBNotificationsViewModel.m
154
- [+] Created FJBNotificationsApiInteractorProtocol.h
155
- [+] Created FJBNotificationsApiInteractor.h
156
- [+] Created FJBNotificationsApiInteractor.m
157
-
158
- ```
data/bin/iosgen CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'iosgen'
4
- #require '../lib/iosgen'
4
+ # require '../lib/iosgen'
5
5
 
6
6
  IOSGenThor.start(ARGV)
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'iosgen'
5
- s.version = '1.0.0'
5
+ s.version = '1.1.0'
6
6
  s.summary = 'Clean iOS architecture generator'
7
7
  s.description = 'Code generator to build a clean iOS architecture'
8
8
  s.authors = ['Francisco J. Belchi']
@@ -11,7 +11,7 @@ module IOSGen
11
11
 
12
12
  attr_reader :type, :file_spec, :destination
13
13
  attr_reader :view_model, :view_controller
14
- attr_reader :factory, :formatter
14
+ attr_reader :factory, :formatter, :test_formatter
15
15
 
16
16
  def initialize(hash = {})
17
17
  @type = hash[:type]
@@ -22,11 +22,22 @@ module IOSGen
22
22
  view_model_formatter = Objc::ViewModelFormatter.new(interactor_formatter)
23
23
  view_controller_formatter = Objc::ViewControllerFormatter.new(view_model_formatter)
24
24
  @formatter = Objc::Formatter.new(view_controller_formatter, view_model_formatter, interactor_formatter)
25
+ @test_formatter = Objc::XctestcaseFormatter.new
25
26
  parse
26
27
  end
27
28
 
28
29
  def generate
29
- generate_view_model
30
+ @formatter.generate do |file_name, template|
31
+ generate_template(file_name, template, @destination)
32
+ puts "[+] Created Source File: #{file_name}".green
33
+ end
34
+ end
35
+
36
+ def generate_test
37
+ generate_test_object(@view_model)
38
+ @view_model.interactors.each do |interactor|
39
+ generate_test_object(interactor)
40
+ end
30
41
  end
31
42
 
32
43
  private
@@ -41,13 +52,6 @@ module IOSGen
41
52
  @formatter.view_controller = @view_controller unless @view_controller.nil?
42
53
  end
43
54
 
44
- def generate_view_model
45
- @formatter.generate do |file_name, template|
46
- generate_template(file_name, template, @destination)
47
- puts "[+] Created #{file_name}".green
48
- end
49
- end
50
-
51
55
  def generate_template(name, template, destination = '.')
52
56
  path_template = File.expand_path("../../../#{template}", File.dirname(__FILE__))
53
57
  renderer = ERB.new(File.read(path_template))
@@ -56,6 +60,14 @@ module IOSGen
56
60
  f.write renderer.result(binding)
57
61
  end
58
62
  end
63
+
64
+ def generate_test_object(object)
65
+ @test_formatter.object = object
66
+ @test_formatter.generate do |file_name, template|
67
+ generate_template(file_name, template, @destination)
68
+ puts "[+] Created Test File: #{file_name}".green
69
+ end
70
+ end
59
71
  end
60
72
  end
61
73
  end