Skip to content

Commit

Permalink
Merge branch 'develop' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
yurapriv committed Jul 30, 2017
2 parents e7e11a8 + 2f4782f commit 382bfb6
Show file tree
Hide file tree
Showing 37 changed files with 398 additions and 130 deletions.
126 changes: 58 additions & 68 deletions gener/gener.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

53 changes: 38 additions & 15 deletions gener/gener/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions gener/gener/Common/Categories/NSDate+GenerDate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// NSDate+GenerDate.h
// gener
//
// Created by Privezentsev Yury on 28.07.17.
// Copyright © 2017 GNR. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface NSDate (GenerDate)

/**
Formats NSDate to NSString with specified format using NSDateFormatter
@param format NSString date format like in NSDateFormatter
@return formatted NSString representing date
*/
-(NSString *)stringWithFormat:(NSString *)format;

@end
21 changes: 21 additions & 0 deletions gener/gener/Common/Categories/NSDate+GenerDate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// NSDate+GenerDate.m
// gener
//
// Created by Privezentsev Yury on 28.07.17.
// Copyright © 2017 GNR. All rights reserved.
//

#import "NSDate+GenerDate.h"

@implementation NSDate (GenerDate)

-(NSString *)stringWithFormat:(NSString *)format {

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:format];

return [dateFormatter stringFromDate:self];
}

@end
2 changes: 1 addition & 1 deletion gener/gener/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.1.0</string>
<string>0.2.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSApplicationCategoryType</key>
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,24 @@
#import "FileCreator.h"
#import "SourceFile.h"

@interface FileCreator ()

@property (strong, nonatomic) NSFileManager *fileManager;

@end

@implementation FileCreator

#pragma mark - Initializer

- (instancetype)init {
self = [super init];
if (self) {
_fileManager = [NSFileManager defaultManager];
}
return self;
}

#pragma mark - Public

- (void)createFilesFromArray:(NSArray *)templates error:(NSError **)error {
Expand All @@ -24,18 +40,18 @@ - (void)createFilesFromArray:(NSArray *)templates error:(NSError **)error {

- (void)createFile:(SourceFile *)file error:(NSError *)error {

if (![[NSFileManager defaultManager] fileExistsAtPath:[file destinationPath]]) {
if (![self.fileManager fileExistsAtPath:[file destinationPath]]) {

NSError *folderCreationError;

[[NSFileManager defaultManager] createDirectoryAtPath:[file destinationPath] withIntermediateDirectories:YES attributes:nil error:&folderCreationError];
[self.fileManager createDirectoryAtPath:[file destinationPath] withIntermediateDirectories:YES attributes:nil error:&folderCreationError];
}

NSString *filePath = [NSString stringWithFormat:@"%@/%@%@", [file destinationPath], [file name], [file extention]];
NSString *fileContent = [file content];
NSData *content = [fileContent dataUsingEncoding:NSUTF8StringEncoding];

[[NSFileManager defaultManager] createFileAtPath:filePath contents:content attributes:nil];
[self.fileManager createFileAtPath:filePath contents:content attributes:nil];

}

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@

#import <Foundation/Foundation.h>

typedef NS_ENUM(NSInteger, Language) {
LanguageObjectiveC = 0,
LanguageSwift = 1
};

@interface ModuleSettings : NSObject

@property (strong, nonatomic) NSString *path;
@property (strong, nonatomic) NSString *name;
@property (strong, nonatomic) NSString *project;
@property (strong, nonatomic) NSString *author;
@property (strong, nonatomic) NSString *company;
@property (assign, nonatomic) Language language;

- (instancetype)initWithPath:(NSString *)path name:(NSString *)name project:(NSString *)project author:(NSString *)author company:(NSString *)company;
- (instancetype)initWithPath:(NSString *)path name:(NSString *)name project:(NSString *)project author:(NSString *)author company:(NSString *)company language:(Language)language;

+ (instancetype)settingsWithPath:(NSString *)path name:(NSString *)name project:(NSString *)project author:(NSString *)author company:(NSString *)company;
+ (instancetype)settingsWithPath:(NSString *)path name:(NSString *)name project:(NSString *)project author:(NSString *)author company:(NSString *)company language:(Language)language;


@end
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,24 @@ @implementation ModuleSettings

#pragma mark - Initializer

- (instancetype)initWithPath:(NSString *)path name:(NSString *)name project:(NSString *)project author:(NSString *)author company:(NSString *)company {
- (instancetype)initWithPath:(NSString *)path name:(NSString *)name project:(NSString *)project author:(NSString *)author company:(NSString *)company language:(Language)language {
self = [super init];
if (self) {
_path = path;
_name = name;
_project = project;
_author = author;
_company = company;
_language = language;
}

return self;
}

#pragma mark - Factory method

+ (instancetype)settingsWithPath:(NSString *)path name:(NSString *)name project:(NSString *)project author:(NSString *)author company:(NSString *)company {
return [[self alloc] initWithPath:path name:name project:project author:author company:company];
+ (instancetype)settingsWithPath:(NSString *)path name:(NSString *)name project:(NSString *)project author:(NSString *)author company:(NSString *)company language:(Language)language {
return [[self alloc] initWithPath:path name:name project:project author:author company:company language:language];
}


Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#import "FIleTemplate.h"
#import "ModuleSettings.h"

#import "NSDate+GenerDate.h"

@interface SourceFile ()

@property (strong, nonatomic) FIleTemplate *template;
Expand Down Expand Up @@ -77,25 +79,14 @@ - (NSString *)name {
- (NSString *)replacePlaceholdersInString:(NSString *)contentsString {

NSString *resultString = [contentsString copy];

NSDate *currentDate = [NSDate date];

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd.MM.yyyy"];

NSString *fullDateString = [dateFormatter stringFromDate:currentDate];

[dateFormatter setDateFormat:@"yyyy"];

NSString *yearString = [dateFormatter stringFromDate:currentDate];


NSDictionary *dictionary = @{
@"$moduleName$": self.settings.name,
@"$projectName$": self.settings.project,
@"$author$": self.settings.author,
@"$date$": fullDateString,
@"$year$": yearString,
@"$date$": [currentDate stringWithFormat:@"dd.MM.yyyy"],
@"$year$": [currentDate stringWithFormat:@"yyyy"],
@"$company$": self.settings.company
};

Expand Down
24 changes: 16 additions & 8 deletions gener/gener/Modules/Generation/Presenter/GenerationPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
// Copyright © 2017 GNR. All rights reserved.
//

#import "GenerationPresenter.h"
#import <Cocoa/Cocoa.h>
#import "GenerationPresenter.h"

#import "GenerationViewInput.h"

#import "GenerationModuleRouting.h"

#import "Generator.h"

#import "NSURL+GenerURL.h"
#import "ModuleSettings.h"

@interface GenerationPresenter ()

Expand All @@ -31,12 +31,6 @@ - (void)didTriggerViewReadyEvent {

self.generator = [[Generator alloc] init];

NSString *pathString = [[NSBundle mainBundle] pathForResource:@"template" ofType:@"json"];

NSError *generatorSetupError;

[self.generator setupWithTemplatePath:[NSURL URLWithString:pathString] error:&generatorSetupError];

[self.view setupInitialState];
}

Expand All @@ -59,6 +53,20 @@ - (void)didTriggerChooseButtonTappedEvent {

- (void)didTriggerGenerateButtonTappedEventWithModuleSettings:(ModuleSettings *)settings {

NSString *pathString;

switch (settings.language) {
case LanguageObjectiveC:
pathString = [[NSBundle mainBundle] pathForResource:@"template" ofType:@"json"];
break;
case LanguageSwift:
pathString = [[NSBundle mainBundle] pathForResource:@"swift-template" ofType:@"json"];
break;
}

NSError *generatorSetupError;
[self.generator setupWithTemplatePath:[NSURL URLWithString:pathString] error:&generatorSetupError];

[self.generator setupWithModuleSettings:settings];

[self.generator generate];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ @interface GenerationViewController ()
@property (weak) IBOutlet NSTextField *pathTextField;
@property (weak) IBOutlet NSButton *choosePathButton;

@property (weak) IBOutlet NSSegmentedControl *languageSegmentedControl;

@property (weak) IBOutlet NSTextField *moduleNameTextField;
@property (weak) IBOutlet NSTextField *projectNameTextField;
@property (weak) IBOutlet NSTextField *authorFullNameTextField;
Expand All @@ -41,19 +43,22 @@ - (IBAction)chooseButtonTapped:(NSButton *)sender {

- (IBAction)generateButtonTapped:(NSButton *)sender {

Language language = (Language)self.languageSegmentedControl.selectedSegment;

ModuleSettings *moduleSettings = [[ModuleSettings alloc] initWithPath:self.pathTextField.stringValue
name:self.moduleNameTextField.stringValue
project:self.projectNameTextField.stringValue
author:self.authorFullNameTextField.stringValue
company:self.companyNameTextField.stringValue];
company:self.companyNameTextField.stringValue
language:language];

[self.output didTriggerGenerateButtonTappedEventWithModuleSettings:moduleSettings];
}

#pragma mark - GenerationViewInput

- (void)setupInitialState {

self.languageSegmentedControl.selectedSegment = 0;
}

- (void)updateViewWithNewModulePathString:(NSString *)modulePathString {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@

@interface $moduleName$ModuleAssembly : NSObject

- (void)build$moduleName$ModuleWithCompletion:(void(^)(id<$moduleName$ModuleInput> moduleInput,UIViewController *viewController))completion;
- (void)build$moduleName$ModuleWithCompletion:(void(^)(id<$moduleName$ModuleInput> moduleInput, UIViewController *viewController))completion;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@implementation $moduleName$ModuleAssembly

- (void)build$moduleName$ModuleWithCompletion:(void(^)(id<$moduleName$ModuleInput> moduleInput,UIViewController *viewController))completion {
- (void)build$moduleName$ModuleWithCompletion:(void(^)(id<$moduleName$ModuleInput> moduleInput, UIViewController *viewController))completion {

//Creating module components
$moduleName$ViewController *viewController = [[UIStoryboard storyboardWithName:@"<#$moduleName$ storyboard name#>" bundle:nil] instantiateViewControllerWithIdentifier:@"<#$moduleName$ view controller identifier #>"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@protocol $moduleName$ViewInput;
@protocol $moduleName$ModuleRouting;

@interface $moduleName$Presenter : NSObject <$moduleName$ModuleInput ,$moduleName$ViewOutput>
@interface $moduleName$Presenter : NSObject <$moduleName$ModuleInput, $moduleName$ViewOutput>

@property (weak, nonatomic) id<$moduleName$ViewInput> view;
@property (weak, nonatomic) id<$moduleName$ModuleRouting> router;
Expand Down
File renamed without changes.
File renamed without changes.
33 changes: 33 additions & 0 deletions gener/gener/Templates/swift/Assembly/ModuleAssembly.gentemp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// $moduleName$Assembly.swift
// $projectName$
//
// Created by $author$ on $date$.
// Copyright © $year$ $company$. All rights reserved.
//

import UIKit

class $moduleName$Assembly {

func build$moduleName$Module(_ completion: (UIViewController?) -> Void) {

// Creating module components
let viewController = UIStoryboard(name: <#Storyboard Name#>, bundle: nil).instantiateViewController(withIdentifier: <#Identifier#>)
let presenter = $moduleName$Presenter()

guard let moduleViewController = viewController as? $moduleName$ViewController else {
completion(nil)
return
}

// Inject properties
moduleViewController.output = presenter
presenter.view = moduleViewController
presenter.router = moduleViewController

completion(moduleViewController)

}

}
27 changes: 27 additions & 0 deletions gener/gener/Templates/swift/Presenter/ModulePresenter.gentemp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// $moduleName$Presenter.swift
// $projectName$
//
// Created by $author$ on $date$.
// Copyright © $year$ $company$. All rights reserved.
//

import Foundation

class $moduleName$Presenter {

var view: $moduleName$ViewInput?

var router: $moduleName$ModuleRouting?

}

// MARK: - $moduleName$ViewOutput
extension $moduleName$Presenter: $moduleName$ViewOutput {

func didTriggerViewReadyEvent() {

self.view?.setupInitialState()
}

}
13 changes: 13 additions & 0 deletions gener/gener/Templates/swift/View/ModuleRouting.gentemp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// $moduleName$ModuleRouting.swift
// $projectName$
//
// Created by $author$ on $date$.
// Copyright © $year$ $company$. All rights reserved.
//

import Foundation

protocol $moduleName$ModuleRouting {

}
Loading

0 comments on commit 382bfb6

Please sign in to comment.