vipergen 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4c5b8b00f457e6bc03e1f087d82798bb742184a5
4
+ data.tar.gz: 70cf5782fba713d3f76f9a519323e5e8159e6265
5
+ SHA512:
6
+ metadata.gz: 19277afe77899d8bbdaa179d3969d6a35603d3f392051480bf1ceb98a90fca25f5671352c8c4be006fb33e075aafa9ade28c2a09e3ca0bbd2d255aacc0d765e4
7
+ data.tar.gz: f140b12753d00b2288ca3bfe25875e7e69560a62c5de164c35584c2527f3e67c7b8995146c2d513d77eaf66fa7a66e36f13a37303d0ee17915ddbb464a581970
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Redbooth
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,123 @@
1
+ Viper Module Generator
2
+ ======================
3
+ [![Code Climate](https://codeclimate.com/github/teambox/viper-module-generator/badges/gpa.svg)](https://codeclimate.com/github/teambox/viper-module-generator)
4
+ [![Build Status](https://travis-ci.org/teambox/viper-module-generator.svg?branch=master)](https://travis-ci.org/teambox/viper-module-generator)
5
+ [![Test Coverage](https://codeclimate.com/github/teambox/viper-module-generator/badges/coverage.svg)](https://codeclimate.com/github/teambox/viper-module-generator)
6
+ [![Dependency Status](https://gemnasium.com/teambox/viper-module-generator.svg)](https://gemnasium.com/teambox/viper-module-generator)
7
+
8
+
9
+ ![image](http://www.objc.io/images/issue-13/2014-06-07-viper-intro.jpg)
10
+
11
+ Gem to generate VIPER modules to use them in your Objective-C/Swift projects
12
+ The implementation scheme returned by this generator is hardly inspired in the example and post of Objc.io, http://www.objc.io/issue-13/viper.html .
13
+
14
+ - [Features](#features)
15
+ - [Changelog](#changelog-0.1)
16
+ - [Expected in version 0.2](#expected-in-version-0.2)
17
+ - [Viper files structure](#viper-files-structure)
18
+ - [How to install vipergen](#how-to-install-vipergen)
19
+ - [How to generate a VIPER module with a given name?](#how-to-generate-viper-module-with-a-given-name?)
20
+ - [Developer tips](#developer-tips)
21
+ - [Update the gem](#update-the-gem)
22
+ - [Add a new template](#add-a-new-template)
23
+ - [Resources](#resources)
24
+
25
+ ## Features
26
+ - Generates the module in Swift and Objective-C
27
+ - Ready to be installed as a gem https://rubygems.org/gems/VIPERGen
28
+
29
+ ### Changelog 0.1.6
30
+ - Added `templates` command to know which templates are available
31
+ - YAML file in each template with the information about the template (more scalable)
32
+
33
+ ### Changelog 0.1
34
+ - Added default template
35
+ - Fully components tested
36
+
37
+ ### Expected in version 0.2
38
+ - Example project of Redbooth login with notifications
39
+ - FetchedResultsController template
40
+ - Default template in Swift
41
+ - Login template
42
+ - Integrate with XCode as a plugin (http://nshipster.com/xcode-plugins/)
43
+
44
+ ## Viper files structure
45
+ ```bash
46
+ .objc
47
+ +-- DataManager
48
+ | +-- VIPERDataManager.h
49
+ | +-- VIPERDataManager.m
50
+ +-- Interactor
51
+ | +-- VIPERInteractor.h
52
+ | +-- VIPERInteractor.m
53
+ +-- Presenter
54
+ | +-- VIPERPresenter.h
55
+ | +-- VIPERPresenter.m
56
+ +-- ViewController
57
+ | +-- VIPERViewController.h
58
+ | +-- VIPERViewController.m
59
+ +-- WireFrame
60
+ | +-- VIPERWireFrame.h
61
+ | +-- VIPERWireFrame.m
62
+ +-- Protocols
63
+ | +-- VIPERProtocols.h
64
+ .swift
65
+ +-- DataManager
66
+ | +-- VIPERDataManager.swift
67
+ +-- Interactor
68
+ | +-- VIPERInteractor.swift
69
+ +-- Presenter
70
+ | +-- VIPERPresenter.swift
71
+ +-- ViewController
72
+ | +-- VIPERViewController.swift
73
+ +-- WireFrame
74
+ | +-- VIPERWireFrame.swift
75
+ +-- Protocols
76
+ | +-- VIPERProtocols.swift
77
+ ```
78
+ ## How to install vipergen ?
79
+ You can install it easily as using the gem. With ruby installed in your OSX execute:
80
+ ```bash
81
+ sudo gem install vipergen
82
+ ```
83
+ If everything were right, you should have now the vipergem command available in your system console
84
+
85
+ ## How to generate a VIPER module with a given name?
86
+ You have just to execute the following command
87
+ ```bash
88
+ vipergen generate MyFirstViperModule --path=~/myproject/shared
89
+ ```
90
+ And then the files structure will be automatically created. Don't forget to add this folder to your project dragging it into the XCode/Appcode inspector
91
+
92
+ ## Developer tips
93
+ ### Update the gem
94
+ When the gem is updated it has to be reported to the gem repository. I followed this tutorial http://amaras-tech.co.uk/article/43/Creating_executable_gems that basically says that once you have your gem ready execute:
95
+ ```bash
96
+ gem build vipergen.gemspec
97
+ gem install vipergen-0.1.gem
98
+ gem push vipergen-0.1.gem
99
+ ```
100
+ Then you'll be asked for your credentials in order to make the update in the repo (http://guides.rubygems.org/publishing/)
101
+
102
+ ### Add a new template
103
+ Are you interested in VIPER and you would like to contribute with this gem adding new templates? Feel free to do it. It's pretty easy. You've just to:
104
+ - Create a folder inside `templates` with the name of your template
105
+ - You'll have to create inside the templates in both languages, Swift and Objective-C (get inspired from existing templates)
106
+ - Use the word VIPER where you want the name to be replaced in.
107
+ - Remember to add the file viperspec.yml with the description of your template as below:
108
+ ```yaml
109
+ author: pepi
110
+ author_email: pepibumur@gmail.com
111
+ template_description: Default template with the simplest structure using VIPER
112
+ updated_at: 2014-08-24
113
+ ```
114
+ - Report it as a PR in this repo updating the gem version in Gemspec.
115
+
116
+ ## Resources
117
+ - Rspec documentation: http://rubydoc.info/gems/rspec-expectations/frames
118
+ - XCode Plugins: http://nshipster.com/xcode-plugins/
119
+ - XCodeProj gem (to modify project groups structure): https://github.com/CocoaPods/Xcodeproj
120
+ - Thor, powerful Ruby library for command line: http://whatisthor.com/
121
+
122
+ ## Contact
123
+ If you have any doubt about the gem or even if you want to make any suggestion you can do it directly to my email address, pedro@redbooth.com . You can use the issues Github page too
data/bin/vipergen ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #require 'rubygems'
4
+ require 'vipergen/viperthor'
5
+
6
+ puts "------- VIPER GENERATOR---------\n"
7
+ puts ARGV
8
+ Vipergen::ViperThor.start(ARGV)
9
+ puts "--------------------------------\n"
@@ -0,0 +1,15 @@
1
+ //
2
+ // Created by Pedro Piñera Buendía on 2014.
3
+ // Copyright (c) 2014 Redbooth. All rights reserved.
4
+ //
5
+
6
+ #import <Foundation/Foundation.h>
7
+ #import "VIPERProtocols.h"
8
+
9
+
10
+ @interface VIPERDataManager : NSObject <VIPERDataManagerInputProtocol>
11
+
12
+ // Properties
13
+ @property (nonatomic, weak) id <VIPERDataManagerOutputProtocol> interactor;
14
+
15
+ @end
@@ -0,0 +1,11 @@
1
+ //
2
+ // Created by Pedro Piñera Buendía on 2014.
3
+ // Copyright (c) 2014 Redbooth. All rights reserved.
4
+ //
5
+
6
+ #import "VIPERDataManager.h"
7
+
8
+
9
+ @implementation VIPERDataManager
10
+
11
+ @end
@@ -0,0 +1,16 @@
1
+ //
2
+ // Created by Pedro Piñera Buendía on 2014.
3
+ // Copyright (c) 2014 Redbooth. All rights reserved.
4
+ //
5
+
6
+ #import <Foundation/Foundation.h>
7
+ #import "VIPERProtocols.h"
8
+
9
+
10
+ @interface VIPERInteractor : NSObject <VIPERInteractorInputProtocol, VIPERDataManagerOutputProtocol>
11
+
12
+ // Properties
13
+ @property (nonatomic, weak) id <VIPERInteractorOutputProtocol> presenter;
14
+ @property (nonatomic, strong) id <VIPERDataManagerInputProtocol> dataManager;
15
+
16
+ @end
@@ -0,0 +1,10 @@
1
+ //
2
+ // Created by Pedro Piñera Buendía on 2014.
3
+ // Copyright (c) 2014 Redbooth. All rights reserved.
4
+ //
5
+
6
+ #import "VIPERInteractor.h"
7
+
8
+ @implementation VIPERInteractor
9
+
10
+ @end
@@ -0,0 +1,18 @@
1
+ //
2
+ // Created by Pedro Piñera Buendía on 2014.
3
+ // Copyright (c) 2014 Redbooth. All rights reserved.
4
+ //
5
+
6
+ #import <Foundation/Foundation.h>
7
+ #import "VIPERProtocols.h"
8
+
9
+ @class VIPERWireframe;
10
+
11
+ @interface VIPERPresenter : NSObject <VIPERPresenterProtocol, VIPERInteractorOutputProtocol>
12
+
13
+ // Properties
14
+ @property (nonatomic, strong) UIViewController <VIPERViewControllerProtocol> * viewController;
15
+ @property (nonatomic, strong) id <VIPERInteractorInputProtocol> interactor;
16
+ @property (nonatomic, strong) VIPERWireframe *wireFrame;
17
+
18
+ @end
@@ -0,0 +1,11 @@
1
+ //
2
+ // Created by Pedro Piñera Buendía on 2014.
3
+ // Copyright (c) 2014 Redbooth. All rights reserved.
4
+ //
5
+
6
+ #import "VIPERPresenter.h"
7
+ #import "VIPERWireframe.h"
8
+
9
+ @implementation VIPERPresenter
10
+
11
+ @end
@@ -0,0 +1,49 @@
1
+ //
2
+ // Created by Pedro Piñera Buendía on 2014.
3
+ // Copyright (c) 2014 Redbooth. All rights reserved.
4
+ //
5
+
6
+ #import <Foundation/Foundation.h>
7
+ #import <UIKit/UIKit.h>
8
+
9
+ @protocol VIPERDataManagerOutputProtocol;
10
+ @protocol VIPERViewControllerProtocol;
11
+ @protocol VIPERPresenterProtocol;
12
+ @protocol VIPERDataManagerInputProtocol;
13
+ @class VIPERWireFrame;
14
+
15
+ @protocol VIPERInteractorOutputProtocol
16
+
17
+ @end
18
+
19
+ @protocol VIPERInteractorInputProtocol
20
+ @required
21
+ - (void)setPresenter:(id <VIPERPresenterProtocol>)presenter;
22
+ - (id <VIPERPresenterProtocol>)presenter;
23
+ @end
24
+
25
+ @protocol VIPERPresenterProtocol
26
+ @required
27
+ - (void)setViewController:(id <VIPERViewControllerProtocol>) viewController;
28
+ - (id <VIPERViewControllerProtocol>)viewController;
29
+ - (void)setInteractor:(id <VIPERInteractorInputProtocol, VIPERDataManagerOutputProtocol>)interactor;
30
+ - (id <VIPERInteractorInputProtocol, VIPERDataManagerOutputProtocol>)interactor;
31
+ - (void)setWireFrame:(VIPERWireFrame*)wireFrame;
32
+ - (VIPERWireFrame*)wireFrame;
33
+ @end
34
+
35
+ @protocol VIPERViewControllerProtocol
36
+ @required
37
+ - (void)setPresenter:(id<VIPERPresenterProtocol, VIPERInteractorOutputProtocol>)presenter;
38
+ - (id<VIPERPresenterProtocol, VIPERInteractorOutputProtocol>)presenter;
39
+ @end
40
+
41
+ @protocol VIPERDataManagerInputProtocol
42
+ - (void)setInteractor:(id <VIPERDataManagerOutputProtocol>)interactor;
43
+ - (id <VIPERDataManagerOutputProtocol>)interactor;
44
+ @end
45
+
46
+ @protocol VIPERDataManagerOutputProtocol
47
+ - (void)setDataManager:(id<VIPERDataManagerInputProtocol>)dataManager;
48
+ - (id<VIPERDataManagerInputProtocol>)dataManager;
49
+ @end
@@ -0,0 +1,13 @@
1
+ //
2
+ // Created by Pedro Piñera Buendía on 2014.
3
+ // Copyright (c) 2014 Redbooth. All rights reserved.
4
+ //
5
+
6
+ #import <UIKit/UIKit.h>
7
+ #import "VIPERProtocols.h"
8
+
9
+ @interface VIPERViewController : UIViewController <VIPERViewControllerProtocol>
10
+
11
+ @property (nonatomic, strong) id <VIPERPresenterProtocol> presenter;
12
+
13
+ @end
@@ -0,0 +1,32 @@
1
+ //
2
+ // Created by Pedro Piñera Buendía on 2014.
3
+ // Copyright (c) 2014 Redbooth. All rights reserved.
4
+ //
5
+
6
+ #import "VIPERViewController.h"
7
+
8
+ @implementation VIPERViewController
9
+
10
+ #pragma mark - ViewController Lifecycle
11
+
12
+ - (void)viewDidLoad
13
+ {
14
+ [super viewDidLoad];
15
+ }
16
+
17
+ - (void)viewDidDisappear:(BOOL)animated
18
+ {
19
+ [super viewDidDisappear:animated];
20
+ }
21
+
22
+ - (void)viewWillAppear:(BOOL)animated
23
+ {
24
+ [super viewWillAppear:animated];
25
+ }
26
+
27
+ - (void)viewWillDisappear:(BOOL)animated
28
+ {
29
+ [super viewWillDisappear:animated];
30
+ }
31
+
32
+ @end
@@ -0,0 +1,21 @@
1
+ //
2
+ // Created by Pedro Piñera Buendía on 2014.
3
+ // Copyright (c) 2014 Redbooth. All rights reserved.
4
+ //
5
+
6
+ #import <Foundation/Foundation.h>
7
+ #import "VIPERProtocols.h"
8
+ #import "VIPERViewController.h"
9
+ #import "VIPERDataManager.h"
10
+ #import "VIPERInteractor.h"
11
+ #import "VIPERPresenter.h"
12
+ #import "VIPERWireframe.h"
13
+ #import <UIKit/UIKit.h>
14
+
15
+ @interface VIPERWireFrame : NSObject
16
+
17
+ @property (nonatomic, weak) UIViewController *viewController;
18
+
19
+ + (void)presentVIPERModuleFrom:(UIViewController*)fromViewController;
20
+
21
+ @end
@@ -0,0 +1,25 @@
1
+ //
2
+ // Created by Pedro Piñera Buendía on 2014.
3
+ // Copyright (c) 2014 Redbooth. All rights reserved.
4
+ //
5
+
6
+ #import "VIPERWireFrame.h"
7
+
8
+ @implementation VIPERWireFrame
9
+
10
+ + (void)presentVIPERModuleFrom:(UIViewController*)fromViewController
11
+ {
12
+ UIViewController <VIPERViewControllerProtocol> *viewController;
13
+ viewController = [[VIPERViewController alloc] init];
14
+ viewController.presenter = [VIPERPresenter new];
15
+ viewController.presenter.interactor = [VIPERInteractor new];
16
+ viewController.presenter.interactor.presenter = viewController.presenter;
17
+ viewController.presenter.viewController = viewController;
18
+ viewController.presenter.wireFrame = [VIPERWireFrame new];
19
+ viewController.presenter.interactor.dataManager = [VIPERDataManager new];
20
+ viewController.presenter.interactor.dataManager.interactor = viewController.presenter.interactor;
21
+
22
+ //TOODO - New view controller presentation (present, push, pop, .. )
23
+ }
24
+
25
+ @end
@@ -0,0 +1,17 @@
1
+ //
2
+ // VIPERDataManager.swift
3
+ // VIPERGenDemo
4
+ //
5
+ // Created by Pedro Piñera Buendía on 22/08/14.
6
+ // Copyright (c) 2014 ___Redbooth___. All rights reserved.
7
+ //
8
+
9
+ import Foundation
10
+
11
+
12
+ class VIPERDataManager: VIPERDataManagerInputProtocol {
13
+ init () {
14
+ self.interactor = nil
15
+ }
16
+ var interactor: VIPERDataManagerOutputProtocol?
17
+ }
@@ -0,0 +1,90 @@
1
+ //
2
+ // VIPERProtocols.swift
3
+ // VIPERGenDemo
4
+ //
5
+ // Created by Pedro Piñera Buendía on 22/08/14.
6
+ // Copyright (c) 2014 ___Redbooth___. All rights reserved.
7
+ //
8
+
9
+ import Foundation
10
+
11
+
12
+ protocol VIPERInteractorOutputProtocol
13
+ {
14
+ /* Add your extra communication methods here */
15
+ /* Interactor -> Presenter */
16
+ }
17
+
18
+ protocol VIPERInteractorInputProtocol
19
+ {
20
+ var presenter: VIPERPresenterProtocol { get set }
21
+
22
+ /* Add your extra communication methods here */
23
+ /* Presenter -> Interactor */
24
+ }
25
+
26
+ protocol VIPERPresenterProtocol
27
+ {
28
+ var viewController: VIPERViewControllerProtocol { get set }
29
+ var interactor: VIPERDataManagerOutputProtocol { get set }
30
+
31
+ // /* Add your extra communication methods here */
32
+ // /* Presenter -> ViewController */
33
+ }
34
+
35
+ protocol VIPERViewControllerProtocol
36
+ {
37
+
38
+ }
39
+
40
+ protocol VIPERDataManagerInputProtocol
41
+ {
42
+
43
+ }
44
+
45
+ protocol VIPERDataManagerOutputProtocol {
46
+
47
+ }
48
+
49
+
50
+
51
+
52
+ /*
53
+ @protocol VIPERDataManagerOutputProtocol;
54
+ @protocol VIPERViewControllerProtocol;
55
+ @protocol VIPERPresenterProtocol;
56
+ @protocol VIPERDataManagerInputProtocol;
57
+ @class VIPERWireFrame;
58
+
59
+ @protocol VIPERInteractorOutputProtocol
60
+
61
+ @end
62
+
63
+
64
+
65
+ @protocol VIPERPresenterProtocol
66
+ @required
67
+ - (void)setViewController:(id <VIPERViewControllerProtocol>) viewController;
68
+ - (id <VIPERViewControllerProtocol>)viewController;
69
+ - (void)setInteractor:(id <VIPERInteractorInputProtocol, VIPERDataManagerOutputProtocol>)interactor;
70
+ - (id <VIPERInteractorInputProtocol, VIPERDataManagerOutputProtocol>)interactor;
71
+ - (void)setWireFrame:(VIPERWireFrame*)wireFrame;
72
+ - (VIPERWireFrame*)wireFrame;
73
+ @end
74
+
75
+ @protocol VIPERViewControllerProtocol
76
+ @required
77
+ - (void)setPresenter:(id<VIPERPresenterProtocol, VIPERInteractorOutputProtocol>)presenter;
78
+ - (id<VIPERPresenterProtocol, VIPERInteractorOutputProtocol>)presenter;
79
+ @end
80
+
81
+ @protocol VIPERDataManagerInputProtocol
82
+ - (void)setInteractor:(id <VIPERDataManagerOutputProtocol>)interactor;
83
+ - (id <VIPERDataManagerOutputProtocol>)interactor;
84
+ @end
85
+
86
+ @protocol VIPERDataManagerOutputProtocol
87
+ - (void)setDataManager:(id<VIPERDataManagerInputProtocol>)dataManager;
88
+ - (id<VIPERDataManagerInputProtocol>)dataManager;
89
+ @end
90
+ */
@@ -0,0 +1,13 @@
1
+ //
2
+ // VIPERWireframe.swift
3
+ // VIPERGenDemo
4
+ //
5
+ // Created by Pedro Piñera Buendia on 06/09/14.
6
+ // Copyright (c) 2014 ___Redbooth___. All rights reserved.
7
+ //
8
+
9
+ import Foundation
10
+
11
+ class VIPERWireframe {
12
+
13
+ }
@@ -0,0 +1,4 @@
1
+ author: pepi
2
+ author_email: pepibumur@gmail.com
3
+ template_description: Default template with the simplest structure using VIPER
4
+ updated_at: 2014-08-24
@@ -0,0 +1,17 @@
1
+ module Vipergen
2
+ class DirUtils
3
+ # Return a directory with the project libraries.
4
+ def self.gem_libdir
5
+ t = ["#{File.dirname(File.expand_path($0))}/../lib/#{Vipergen::NAME}",
6
+ "#{Gem.dir}/gems/#{Vipergen::NAME}-#{Vipergen::VERSION}/lib/#{Vipergen::NAME}"]
7
+ t.each {|i| return i if File.readable?(i) }
8
+ raise "both paths are invalid: #{t}"
9
+ end
10
+
11
+ # Returns the directories inside a given one
12
+ def self.directories_in(directory)
13
+ expanded_dir = File.expand_path(directory)
14
+ return Dir.glob(File.join(expanded_dir,'*')).select {|f| File.directory? f}
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,54 @@
1
+ module Vipergen
2
+ # File manager class
3
+ class FileManager
4
+ # Constants
5
+ LANGUAGES = ["swift", "objc"]
6
+ REPLACEMENT_KEY = "VIPER"
7
+
8
+ # Returns if the template is valid by the VIPER generator
9
+ def self.is_template_valid(template)
10
+ return Vipergen::TemplateManager.templates.include? template
11
+ end
12
+
13
+ # Returns if the language is valid by the VIPER generator
14
+ def self.is_language_valid(language)
15
+ return LANGUAGES.include? language
16
+ end
17
+
18
+ # Return the path if valid template and language
19
+ # @return String with valid path
20
+ def self.path_from(template, language)
21
+ return nil if !is_language_valid(language) || !is_template_valid(template)
22
+ return File.join(Vipergen::TemplatesManager.templates_dir, template, language)
23
+ end
24
+
25
+ # Returns an array with files in a given path
26
+ # @return Array with the files in a given path
27
+ def self.files_in_path(path)
28
+ return Dir[File.join("#{path}","/**/*")].select {|f| File.file?(f)}
29
+ end
30
+
31
+ # Returns the destination viper path
32
+ # @return Destination root path
33
+ def self.destination_viper_path(path, name)
34
+ expand_path = File.expand_path(path)
35
+ return File.join(expand_path,name)
36
+ end
37
+
38
+ # Copy a system item to another place
39
+ def self.copy(from, to)
40
+ to_expand_path = File.expand_path(to)
41
+ from_expand_path = File.expand_path(from)
42
+ FileUtils.mkdir_p (to_expand_path)
43
+ FileUtils.copy_entry(from_expand_path, to_expand_path)
44
+ end
45
+
46
+ # Move a system item to another place
47
+ def self.move(from, to)
48
+ to_expand_path = File.expand_path(to)
49
+ from_expand_path = File.expand_path(from)
50
+ FileUtils.move(from_expand_path, to_expand_path)
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,54 @@
1
+ module Vipergen
2
+ # Cosntants
3
+ class Generator
4
+ # Main method that generate the VIPER files structure
5
+ def self.generate_viper(template, language, name, path)
6
+ puts "Generating VIPER-Module"
7
+ puts "Template: #{template}"
8
+ puts "Language: #{language}"
9
+ puts "Name: #{name}"
10
+ puts "Path: #{path}"
11
+ path_from = Vipergen::FileManager.path_from(template, language)
12
+ path_to = Vipergen::FileManager.destination_viper_path(path, name)
13
+ Vipergen::FileManager.copy(path_from, path_to)
14
+ files = Vipergen::FileManager.files_in_path(path_to)
15
+ rename_files(files,name)
16
+ end
17
+
18
+ # Rename all the files in the files array
19
+ # - It renames the name of the file
20
+ # - It renames the content of the file
21
+ def self.rename_files(files, name)
22
+ files.each do |file|
23
+ raise SyntaxError unless file.include? Vipergen::REPLACEMENT_KEY
24
+ rename_file(file, name)
25
+ end
26
+ end
27
+
28
+ # Rename a given file
29
+ # - It renames the name of the file
30
+ # - It renames the content of the file
31
+ def self.rename_file(file, name)
32
+ new_path = file.gsub(Vipergen::REPLACEMENT_KEY, name)
33
+ Vipergen::FileManager.move(file, new_path)
34
+ rename_file_content(new_path, name)
35
+ end
36
+
37
+ # Rename the file content
38
+ # @return: An String with the every VIPER replaced by 'name'
39
+ def self.rename_file_content(filename, name)
40
+ # Reading content
41
+ file = File.open(filename, "rb")
42
+ content = file.read
43
+ file.close
44
+
45
+ # Replacing content
46
+ content = content.gsub(Vipergen::REPLACEMENT_KEY, name)
47
+
48
+ # Saving content with replaced string
49
+ File.open(filename, "w+") do |file|
50
+ file.write(content)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,53 @@
1
+ require 'yaml'
2
+ module Vipergen
3
+ class TemplateManager
4
+
5
+ # Returns the templates dir
6
+ def self.templates_dir
7
+ t = "#{Gem.dir}/gems/#{Vipergen::NAME}-#{Vipergen::VERSION}/lib/templates"
8
+ end
9
+
10
+ # Get the available templates paths
11
+ # @return Array[String] with available templates paths
12
+ def self.templates_paths()
13
+ template_dir = Vipergen::TemplateManager.templates_dir
14
+ return Vipergen::DirUtils.directories_in(template_dir)
15
+ end
16
+
17
+ # Get the templates names
18
+ # @return Array[String] with templates names (got from the folder)
19
+ def self.templates()
20
+ templates_paths.map{|template_path| template_name_from_path(template_path)}
21
+ end
22
+
23
+ # Returns the template name from a given template_path
24
+ # @return String with the template name
25
+ def self.template_name_from_path(template_path)
26
+ return template_path.split("/").last
27
+ end
28
+
29
+ # Returns the description of all the templates available
30
+ # @return String with the entire description
31
+ def self.templates_description()
32
+ description = "\nAvailable templates \n"
33
+ description += "------------------- \n"
34
+ self.templates_paths.each do |template_path|
35
+ description += "> #{template_description(template_path)} \n"
36
+ end
37
+ return description
38
+ end
39
+
40
+ # Returns the description of a given template
41
+ # @param template String with the template path whose description is going to be returned
42
+ # @return String with the template description
43
+ def self.template_description(template_path)
44
+ template_description = ""
45
+
46
+ # Reading yaml
47
+ template_content = YAML.load_file(File.join(template_path,'viperspec.yml'))
48
+
49
+ # Generating string
50
+ template_description+= "| #{template_name_from_path(template_path)} by #{template_content["author"]} |: #{template_content["template_description"]}"
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,4 @@
1
+ module Vipergen
2
+ NAME = "vipergen"
3
+ VERSION = "0.1.8"
4
+ end
@@ -0,0 +1,19 @@
1
+ require 'thor'
2
+ require 'vipergen'
3
+
4
+ module Vipergen
5
+ class ViperThor < Thor
6
+ desc "generate", "Generate a VIPER module"
7
+ option :language, :required => false, :default => 'objc', :type => :string, :desc => "The language of the generated module (swift, objc)"
8
+ option :template, :required => false, :default => 'default', :type => :string , :desc => "Template for the generation"
9
+ option :path, :required => true, :type => :string , :desc => "Path where the output module is going to be saved"
10
+ def generate(name)
11
+ Vipergen::Generator.generate_viper(options[:template], options[:language], name, options[:path])
12
+ end
13
+
14
+ desc "templates", "Get a list of available templates"
15
+ def templates()
16
+ puts Vipergen::TemplateManager.templates_description()
17
+ end
18
+ end
19
+ end
data/lib/vipergen.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'vipergen/generator'
2
+ require 'vipergen/filemanager'
3
+ require 'vipergen/dirutils'
4
+ require 'vipergen/version'
5
+ require 'vipergen/viperthor'
6
+ require 'vipergen/templatemanager'
7
+
8
+ module Vipergen
9
+ # Constants
10
+ LANGUAGES = ["swift", "objc"]
11
+ REPLACEMENT_KEY = "VIPER"
12
+ end
@@ -0,0 +1,4 @@
1
+ require 'vipergen'
2
+ require "codeclimate-test-reporter"
3
+
4
+ CodeClimate::TestReporter.start
@@ -0,0 +1,131 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vipergen do
4
+ context "when generating path" do
5
+ it "should return nil if no valid template" do
6
+ valid_template = Vipergen::FileManager.is_template_valid("asdgas")
7
+ expect(valid_template).to be(false)
8
+ end
9
+ it "should return nil if no valid language" do
10
+ valid_template = Vipergen::FileManager.is_template_valid("asdgas")
11
+ expect(valid_template).to be(false)
12
+ end
13
+ it "should return nil if no valid language when getting path" do
14
+ path = Vipergen::FileManager.path_from("default", "asgass")
15
+ expect(path).to be(nil)
16
+ end
17
+ it "should return nil if no valid template when getting path" do
18
+ path = Vipergen::FileManager.path_from("asga", "swift")
19
+ expect(path).to be(nil)
20
+ end
21
+ it "should append the name to the given user path" do
22
+ to_path = Vipergen::FileManager.destination_viper_path("path/", "pepito")
23
+ expect(to_path).to eq(File.join(File.expand_path("path/"),"pepito"))
24
+ end
25
+ end
26
+ context "copying a folder to a diferent place" do
27
+ before (:each) do
28
+ Dir.mkdir 'foo'
29
+ Dir.mkdir 'foo/subfoo'
30
+ end
31
+
32
+ it "should copy a given folder properly" do
33
+ Vipergen::FileManager.copy('foo','test_foo')
34
+ expect(File.directory?('test_foo/subfoo')).to eq(true)
35
+ end
36
+
37
+ after (:each) do
38
+ FileUtils.rm_rf('foo')
39
+ FileUtils.rm_rf('test_foo')
40
+ end
41
+ end
42
+ end
43
+
44
+ describe Vipergen::Generator do
45
+ context "when renaming file content" do
46
+ before (:each) do
47
+ File.open("test.txt", 'w') {|f| f.write("I'm a #{Vipergen::REPLACEMENT_KEY} file") }
48
+ end
49
+
50
+ it "should rename every VIPER word to the given name" do
51
+ Vipergen::Generator.rename_file_content("test.txt","RENAMED")
52
+ file = File.open("test.txt", "rb")
53
+ content = file.read
54
+ expect(content).to eq("I'm a RENAMED file")
55
+ end
56
+
57
+ after (:each) do
58
+ FileUtils.rm('test.txt')
59
+ end
60
+ end
61
+
62
+ context "when renaming file" do
63
+ before (:each) do
64
+ File.open("#{Vipergen::REPLACEMENT_KEY}test.txt", 'w') {|f| f.write("I'm a #{Vipergen::REPLACEMENT_KEY} file") }
65
+ end
66
+
67
+ it "every file should be renamed in rename_files" do
68
+ expect(Vipergen::Generator).to receive(:rename_file)
69
+ Vipergen::Generator.rename_files(["#{Vipergen::REPLACEMENT_KEY}file.txt"], "pepito")
70
+ end
71
+
72
+ it "should raise a SyntaxError exeption if there's a file in the template without the proper name" do
73
+ expect{Vipergen::Generator.rename_files(["asgasgs.txt"], "pepito")}.to raise_error
74
+ end
75
+
76
+ it "should rename the VIPER in name to the given name" do
77
+ file = "#{Vipergen::REPLACEMENT_KEY}test.txt"
78
+ name = "RENAMED"
79
+ Vipergen::Generator.rename_file(file, name)
80
+ expect(File.exist? "RENAMEDtest.txt").to eq(true)
81
+ end
82
+
83
+ it "should rename the file content after the file name rename" do
84
+ file = "#{Vipergen::REPLACEMENT_KEY}test.txt"
85
+ name = "RENAMED"
86
+ expect(Vipergen::Generator).to receive(:rename_file_content)
87
+ Vipergen::Generator.rename_file(file, name)
88
+ end
89
+
90
+ after (:each) do
91
+ File.delete "#{Vipergen::REPLACEMENT_KEY}test.txt" if File.exist? "#{Vipergen::REPLACEMENT_KEY}test.txt"
92
+ File.delete "RENAMEDtest.txt" if File.exist? "RENAMEDtest.txt"
93
+ end
94
+ end
95
+ end
96
+
97
+ describe Vipergen::DirUtils do
98
+ context "getting directories" do
99
+ before (:each) do
100
+ Dir.mkdir 'foo'
101
+ Dir.mkdir 'foo/subfoo'
102
+ end
103
+
104
+ it "should return the directories inside a given one" do
105
+ expect(Vipergen::DirUtils.directories_in('foo').count).to eq(1)
106
+ end
107
+
108
+ after (:each) do
109
+ FileUtils.rm_rf('foo')
110
+ end
111
+ end
112
+ end
113
+
114
+ describe Vipergen::TemplateManager do
115
+ context "getting templates" do
116
+ before (:each) do
117
+ Dir.mkdir 'foo'
118
+ Dir.mkdir 'foo/subfoo'
119
+ Dir.mkdir 'foo/subfoo2'
120
+ end
121
+
122
+ it "should return the proper templates in templates directory" do
123
+ Vipergen::TemplateManager.stub(:templates_dir).and_return('foo/')
124
+ expect(Vipergen::TemplateManager.templates_paths.count).to eq(2)
125
+ end
126
+
127
+ after (:each) do
128
+ FileUtils.rm_rf('foo')
129
+ end
130
+ end
131
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vipergen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.8
5
+ platform: ruby
6
+ authors:
7
+ - Pedro Piñera
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Based on the objc.io post about VIPER. It saves time in the implementation
84
+ generating the controllers and adding interactions between them (in Swift or Objective-C)
85
+ email: pedro@redbooth.com
86
+ executables:
87
+ - vipergen
88
+ extensions: []
89
+ extra_rdoc_files:
90
+ - README.md
91
+ files:
92
+ - LICENSE
93
+ - README.md
94
+ - bin/vipergen
95
+ - lib/templates/default/objc/DataManager/VIPERDataManager.h
96
+ - lib/templates/default/objc/DataManager/VIPERDataManager.m
97
+ - lib/templates/default/objc/Interactor/VIPERInteractor.h
98
+ - lib/templates/default/objc/Interactor/VIPERInteractor.m
99
+ - lib/templates/default/objc/Presenter/VIPERPresenter.h
100
+ - lib/templates/default/objc/Presenter/VIPERPresenter.m
101
+ - lib/templates/default/objc/Protocols/VIPERProtocols.h
102
+ - lib/templates/default/objc/ViewController/VIPERViewController.h
103
+ - lib/templates/default/objc/ViewController/VIPERViewController.m
104
+ - lib/templates/default/objc/WireFrame/VIPERWireFrame.h
105
+ - lib/templates/default/objc/WireFrame/VIPERWireFrame.m
106
+ - lib/templates/default/swift/DataManager/VIPERDataManager.swift
107
+ - lib/templates/default/swift/Protocols/VIPERProtocols.swift
108
+ - lib/templates/default/swift/WireFrame/VIPERWireframe.swift
109
+ - lib/templates/default/viperspec.yml
110
+ - lib/vipergen.rb
111
+ - lib/vipergen/dirutils.rb
112
+ - lib/vipergen/filemanager.rb
113
+ - lib/vipergen/generator.rb
114
+ - lib/vipergen/templatemanager.rb
115
+ - lib/vipergen/version.rb
116
+ - lib/vipergen/viperthor.rb
117
+ - spec/spec_helper.rb
118
+ - spec/vipergen/vipergen_spec.rb
119
+ homepage: http://github.com/teambox/viper-module-generator
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options:
125
+ - --charset=UTF-8
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.4.1
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Generates XCode VIPER module controllers structure
144
+ test_files:
145
+ - spec/spec_helper.rb
146
+ - spec/vipergen/vipergen_spec.rb