mvcgen 0.1.2
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.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +115 -0
- data/bin/mvcgen +9 -0
- data/lib/mvcgen.rb +6 -0
- data/lib/mvcgen/dirutils.rb +17 -0
- data/lib/mvcgen/filemanager.rb +51 -0
- data/lib/mvcgen/generator.rb +58 -0
- data/lib/mvcgen/mvcthor.rb +19 -0
- data/lib/mvcgen/templatemanager.rb +53 -0
- data/lib/mvcgen/version.rb +4 -0
- data/lib/templates/default/mvcspec.yml +4 -0
- data/lib/templates/default/objc/DataManager/VIPERDataManager.h +15 -0
- data/lib/templates/default/objc/DataManager/VIPERDataManager.m +11 -0
- data/lib/templates/default/objc/Interactor/VIPERInteractor.h +16 -0
- data/lib/templates/default/objc/Interactor/VIPERInteractor.m +10 -0
- data/lib/templates/default/objc/Presenter/VIPERPresenter.h +18 -0
- data/lib/templates/default/objc/Presenter/VIPERPresenter.m +11 -0
- data/lib/templates/default/objc/Protocols/VIPERProtocols.h +64 -0
- data/lib/templates/default/objc/ViewController/VIPERViewController.h +13 -0
- data/lib/templates/default/objc/ViewController/VIPERViewController.m +32 -0
- data/lib/templates/default/objc/WireFrame/VIPERWireFrame.h +19 -0
- data/lib/templates/default/objc/WireFrame/VIPERWireFrame.m +31 -0
- data/lib/templates/default/swift/Config/Config.plist +58 -0
- data/lib/templates/default/swift/Config/Config.swift +50 -0
- data/lib/templates/default/swift/Extensions/Buttons.swift +110 -0
- data/lib/templates/default/swift/Extensions/ColorHex.swift +32 -0
- data/lib/templates/default/swift/Helper/APIHelper.swift +98 -0
- data/lib/templates/default/swift/Helper/APIManager.swift +217 -0
- data/lib/templates/default/swift/Helper/APIRequestBody.swift +81 -0
- data/lib/templates/default/swift/Helper/AWSManager.swift +29 -0
- data/lib/templates/default/swift/Helper/FilesManager.swift +97 -0
- data/lib/templates/default/swift/Helper/S3Manager.swift +113 -0
- data/lib/templates/default/swift/Helper/Utils.swift +69 -0
- data/lib/templates/default/swift/Models/Managers/UserManager.swift +56 -0
- data/lib/templates/default/swift/Models/Responses/BaseResponse.swift +75 -0
- data/lib/templates/default/swift/Models/Responses/UserResponse.swift +30 -0
- data/lib/templates/default/swift/Models/Responses/UserSingupResponse.swift +27 -0
- data/lib/templates/default/swift/Models/User.swift +92 -0
- data/spec/mvcgen/mvcgen_spec.rb +131 -0
- data/spec/spec_helper.rb +4 -0
- metadata +159 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 171c12fa910bd62024c0a177a336b7a2a2817045
|
4
|
+
data.tar.gz: 6a3e967271ab52b634c8704691783e7b237d1141
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9b8ef45ef1a1b94816abde42829e607f402a70be323e35fb9191deea1c78c538d9501ca939cb17956f34346367163b9d1cf903f9e417ca043d59510e603c3bcf
|
7
|
+
data.tar.gz: 69fa37c0dc1bc63aeb2f5ddc845679716c0986868f1bb8ac13bd1717f24e8660399b08ee327b0537dfa7e05d6710a173aa6d05a460e9a2d53cb33be2a188f6ee
|
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,115 @@
|
|
1
|
+
MVC Module Generator
|
2
|
+
======================
|
3
|
+
|
4
|
+
<!-- ## :warning: This project is no longer maintained.
|
5
|
+
|
6
|
+
Gem to generate MVC modules to use them in your Swift projects
|
7
|
+
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 .
|
8
|
+
|
9
|
+
- [Features](#features)
|
10
|
+
- [Changelog](#changelog-0.1)
|
11
|
+
- [Expected in version 0.2](#expected-in-version-0.2)
|
12
|
+
- [MVC files structure](#mvc-files-structure)
|
13
|
+
- [How to install mvcgen](#how-to-install-vipergen)
|
14
|
+
- [How to generate a MVC module with a given name?](#how-to-generate-viper-module-with-a-given-name?)
|
15
|
+
- [Developer tips](#developer-tips)
|
16
|
+
- [Update the gem](#update-the-gem)
|
17
|
+
- [Add a new template](#add-a-new-template)
|
18
|
+
- [Resources](#resources)
|
19
|
+
|
20
|
+
## Features
|
21
|
+
- Generates the module in Swift and Objective-C
|
22
|
+
- Ready to be installed as a gem https://rubygems.org/gems/VIPERGen
|
23
|
+
|
24
|
+
### Changelog 0.1.6
|
25
|
+
- Added `templates` command to know which templates are available
|
26
|
+
- YAML file in each template with the information about the template (more scalable)
|
27
|
+
|
28
|
+
### Changelog 0.1
|
29
|
+
- Added default template
|
30
|
+
- Fully components tested
|
31
|
+
|
32
|
+
### Expected in version 0.2
|
33
|
+
- Example project of Redbooth login with notifications
|
34
|
+
- FetchedResultsController template
|
35
|
+
- Default template in Swift
|
36
|
+
- Login template
|
37
|
+
- Integrate with XCode as a plugin (http://nshipster.com/xcode-plugins/)
|
38
|
+
|
39
|
+
## Viper files structure
|
40
|
+
```bash
|
41
|
+
.objc
|
42
|
+
+-- DataManager
|
43
|
+
| +-- VIPERDataManager.h
|
44
|
+
| +-- VIPERDataManager.m
|
45
|
+
+-- Interactor
|
46
|
+
| +-- VIPERInteractor.h
|
47
|
+
| +-- VIPERInteractor.m
|
48
|
+
+-- Presenter
|
49
|
+
| +-- VIPERPresenter.h
|
50
|
+
| +-- VIPERPresenter.m
|
51
|
+
+-- ViewController
|
52
|
+
| +-- VIPERViewController.h
|
53
|
+
| +-- VIPERViewController.m
|
54
|
+
+-- WireFrame
|
55
|
+
| +-- VIPERWireFrame.h
|
56
|
+
| +-- VIPERWireFrame.m
|
57
|
+
+-- Protocols
|
58
|
+
| +-- VIPERProtocols.h
|
59
|
+
.swift
|
60
|
+
+-- DataManager
|
61
|
+
| +-- VIPERDataManager.swift
|
62
|
+
+-- Interactor
|
63
|
+
| +-- VIPERInteractor.swift
|
64
|
+
+-- Presenter
|
65
|
+
| +-- VIPERPresenter.swift
|
66
|
+
+-- ViewController
|
67
|
+
| +-- VIPERViewController.swift
|
68
|
+
+-- WireFrame
|
69
|
+
| +-- VIPERWireFrame.swift
|
70
|
+
+-- Protocols
|
71
|
+
| +-- VIPERProtocols.swift
|
72
|
+
```
|
73
|
+
## How to install vipergen ?
|
74
|
+
You can install it easily as using the gem. With ruby installed in your OSX execute:
|
75
|
+
```bash
|
76
|
+
sudo gem install vipergen
|
77
|
+
```
|
78
|
+
If everything were right, you should have now the vipergem command available in your system console
|
79
|
+
|
80
|
+
## How to generate a VIPER module with a given name?
|
81
|
+
You have just to execute the following command
|
82
|
+
```bash
|
83
|
+
vipergen generate MyFirstViperModule --path=~/myproject/shared
|
84
|
+
```
|
85
|
+
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
|
86
|
+
|
87
|
+
## Developer tips
|
88
|
+
### Update the gem
|
89
|
+
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:
|
90
|
+
```bash
|
91
|
+
gem build vipergen.gemspec
|
92
|
+
gem install vipergen-0.1.gem
|
93
|
+
gem push vipergen-0.1.gem
|
94
|
+
```
|
95
|
+
Then you'll be asked for your credentials in order to make the update in the repo (http://guides.rubygems.org/publishing/)
|
96
|
+
|
97
|
+
### Add a new template
|
98
|
+
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:
|
99
|
+
- Create a folder inside `templates` with the name of your template
|
100
|
+
- You'll have to create inside the templates in both languages, Swift and Objective-C (get inspired from existing templates)
|
101
|
+
- Use the word VIPER where you want the name to be replaced in.
|
102
|
+
- Remember to add the file viperspec.yml with the description of your template as below:
|
103
|
+
```yaml
|
104
|
+
author: pepi
|
105
|
+
author_email: pepibumur@gmail.com
|
106
|
+
template_description: Default template with the simplest structure using VIPER
|
107
|
+
updated_at: 2014-08-24
|
108
|
+
```
|
109
|
+
- Report it as a PR in this repo updating the gem version in Gemspec.
|
110
|
+
|
111
|
+
## Resources
|
112
|
+
- Rspec documentation: http://rubydoc.info/gems/rspec-expectations/frames
|
113
|
+
- XCode Plugins: http://nshipster.com/xcode-plugins/
|
114
|
+
- XCodeProj gem (to modify project groups structure): https://github.com/CocoaPods/Xcodeproj
|
115
|
+
- Thor, powerful Ruby library for command line: http://whatisthor.com/ -->
|
data/bin/mvcgen
ADDED
data/lib/mvcgen.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module MVCgen
|
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/#{MVCgen::NAME}",
|
6
|
+
"#{Gem.dir}/gems/#{MVCgen::NAME}-#{MVCgen::VERSION}/lib/#{MVCgen::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,51 @@
|
|
1
|
+
module MVCgen
|
2
|
+
# File manager class
|
3
|
+
class FileManager
|
4
|
+
|
5
|
+
# Returns if the template is valid by the MVC generator
|
6
|
+
def self.is_template_valid(template)
|
7
|
+
return MVCgen::TemplateManager.templates.include? template
|
8
|
+
end
|
9
|
+
|
10
|
+
# Returns if the language is valid by the MVC generator
|
11
|
+
def self.is_language_valid(language)
|
12
|
+
return (MVCgen::Generator::LANGUAGES).include? language
|
13
|
+
end
|
14
|
+
|
15
|
+
# Return the path if valid template and language
|
16
|
+
# @return String with valid path
|
17
|
+
def self.path_from(template, language)
|
18
|
+
return nil if !is_language_valid(language) || !is_template_valid(template)
|
19
|
+
return File.join(MVCgen::TemplateManager.templates_dir, template, language)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Returns an array with files in a given path
|
23
|
+
# @return Array with the files in a given path
|
24
|
+
def self.files_in_path(path)
|
25
|
+
return Dir[File.join("#{path}","/**/*")].select {|f| File.file?(f)}
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns the destination mvc path
|
29
|
+
# @return Destination root path
|
30
|
+
def self.destination_mvc_path(path, name)
|
31
|
+
expand_path = File.expand_path(path)
|
32
|
+
return File.join(expand_path,name)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Copy a system item to another place
|
36
|
+
def self.copy(from, to)
|
37
|
+
to_expand_path = File.expand_path(to)
|
38
|
+
from_expand_path = File.expand_path(from)
|
39
|
+
FileUtils.mkdir_p (to_expand_path)
|
40
|
+
FileUtils.copy_entry(from_expand_path, to_expand_path)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Move a system item to another place
|
44
|
+
def self.move(from, to)
|
45
|
+
to_expand_path = File.expand_path(to)
|
46
|
+
from_expand_path = File.expand_path(from)
|
47
|
+
FileUtils.move(from_expand_path, to_expand_path)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module MVCgen
|
2
|
+
# Cosntants
|
3
|
+
class Generator
|
4
|
+
# Constants
|
5
|
+
LANGUAGES = ["swift"]
|
6
|
+
REPLACEMENT_KEY = "MVC"
|
7
|
+
|
8
|
+
# Main method that generate the MVC files structure
|
9
|
+
def self.generate_mvc(template, language, name, path)
|
10
|
+
puts "Generating MVC-Module"
|
11
|
+
puts "Template: #{template}"
|
12
|
+
puts "Language: #{language}"
|
13
|
+
puts "Name: #{name}"
|
14
|
+
puts "Path: #{path}"
|
15
|
+
path_from = MVCgen::FileManager.path_from(template, language)
|
16
|
+
path_to = MVCgen::FileManager.destination_mvc_path(path, name)
|
17
|
+
MVCgen::FileManager.copy(path_from, path_to)
|
18
|
+
files = MVCgen::FileManager.files_in_path(path_to)
|
19
|
+
rename_files(files,name)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Rename all the files in the files array
|
23
|
+
# - It renames the name of the file
|
24
|
+
# - It renames the content of the file
|
25
|
+
def self.rename_files(files, name)
|
26
|
+
files.each do |file|
|
27
|
+
raise SyntaxError unless file.include? (MVCgen::Generator::REPLACEMENT_KEY)
|
28
|
+
rename_file(file, name)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Rename a given file
|
33
|
+
# - It renames the name of the file
|
34
|
+
# - It renames the content of the file
|
35
|
+
def self.rename_file(file, name)
|
36
|
+
new_path = file.gsub((MVCgen::Generator::REPLACEMENT_KEY), name)
|
37
|
+
MVCgen::FileManager.move(file, new_path)
|
38
|
+
rename_file_content(new_path, name)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Rename the file content
|
42
|
+
# @return: An String with the every MVC replaced by 'name'
|
43
|
+
def self.rename_file_content(filename, name)
|
44
|
+
# Reading content
|
45
|
+
file = File.open(filename, "rb")
|
46
|
+
content = file.read
|
47
|
+
file.close
|
48
|
+
|
49
|
+
# Replacing content
|
50
|
+
content = content.gsub((MVCgen::Generator::REPLACEMENT_KEY), name)
|
51
|
+
|
52
|
+
# Saving content with replaced string
|
53
|
+
File.open(filename, "w+") do |file|
|
54
|
+
file.write(content)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'mvcgen'
|
3
|
+
|
4
|
+
module MVCgen
|
5
|
+
class MVCThor < Thor
|
6
|
+
desc "generate", "Generate a MVC module"
|
7
|
+
option :language, :required => false, :default => 'swift', :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
|
+
MVCgen::Generator.generate_mvc(options[:template], options[:language], name, options[:path])
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "templates", "Get a list of available templates"
|
15
|
+
def templates()
|
16
|
+
puts MVCgen::TemplateManager.templates_description()
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
module MVCgen
|
3
|
+
class TemplateManager
|
4
|
+
|
5
|
+
# Returns the templates dir
|
6
|
+
def self.templates_dir
|
7
|
+
t = "#{Gem.dir}/gems/#{MVCgen::NAME}-#{MVCgen::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 = MVCgen::TemplateManager.templates_dir
|
14
|
+
return MVCgen::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,'mvcspec.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,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,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,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, weak) id <VIPERViewProtocol> view;
|
15
|
+
@property (nonatomic, strong) id <VIPERInteractorInputProtocol> interactor;
|
16
|
+
@property (nonatomic, strong) VIPERWireFrame *wireFrame;
|
17
|
+
|
18
|
+
@end
|