Skip to content

Commit 0068b98

Browse files
author
zx
committed
更新README.md
1 parent 81a2496 commit 0068b98

File tree

15 files changed

+72
-10
lines changed

15 files changed

+72
-10
lines changed

Diff for: .DS_Store

0 Bytes
Binary file not shown.

Diff for: Application/.DS_Store

6 KB
Binary file not shown.

Diff for: Application/CodeCreater.dmg

-1.33 MB
Binary file not shown.

Diff for: README.md

+30-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,33 @@
1-
# ZXCodeCreater
2-
根据通用模板快速生成目标文件夹及文件
1+
# CodeCreater
2+
##背景:
3+
1. 写代码的时候,可能经常会遇到多个模块中基础内容都是想似的,例如,你可能很多文件中都会懒加载一个UITableView实例对象,遵守UITableViewDelegate、UITableViewDataSource协议并实现方法,或者你在每一个类中都要写一个方法用来统一管理UI,用一个方法统一用来管理Layout,或者各种#pragma mark - ####;
4+
2. 类似的东西,处理大概如下:
5+
1).没有抽离过公用代码,用的时候重新敲一遍吧;
6+
2).没有抽离过公用代码,用的时候把以前的复制过来,多余的删掉吧;
7+
3).抽离过公用代码,用的时候直接复制修改类名拖过来就好啦;
8+
4).抽离过公用代码,用脚本生成需要的文件;
9+
3. 于是乎,我让它进化到了第五种:利用NSFileManager相关知识,封以MacOS外壳;能够通过通用模板生成目标文件夹及文件;
310

4-
思路:真正的快速生成代码文件,其实就是将模板的类名修改;
511

12+
##思路
13+
其实在我最开始打算写这个小工具的时候,我是创建了很多个类的,准备一个一个的类用字符串拼接而成,并且当时想的可能写出来也不会适合大众模板,只会死死的停留在一个模板上;
614

7-
需要说明的几点:
8-
1. dmg软件包在Application目录;
9-
2. 使用之前,需要你们首先为自己定制一套通用模板文件,其中需要注意的是,无论是文件夹还是类名,前缀都要保持一致;这样才能替换成功;
10-
3. 使用之时,直接select选择模板通用文件所在位置,如需测试,可以定位到我准备的ZXCodeCreaterTest目录,然后Class Prefix In Module就是模型文件中的类前缀,如果你使用的是我准备的ZXCodeCreaterTest,那么统一前缀就是ZXCodeCreaterTest,后面的Target Class Prefix你随意填写就好;
15+
之后突然发现,所谓的快速生成代码,对比之前的文件,改变的仅仅就是类名,文件名;然后就建立了模板,直接遍历模板中的文件夹及其文件,将模板中原来的字段替换成新字段就行了;
16+
17+
代码也很简单,想知其所以然的可以去看看;
18+
19+
20+
##贴金
21+
1. 快速生成所需文件夹及其文件代码,节省时间,提升开发效率;
22+
2. 一个模子刻出来的东西,风格统一;
23+
24+
25+
##一图概全
26+
![image](https://github.com/czhen09/ZXCodeCreater/tree/master/ZXCodeCreater/Resource/IntroductionDiagram.png)
27+
28+
29+
##结语
30+
1. 使用之前,你们得为自己准备一份通用模板;
31+
2. 让CodeCreater去接受你们的考验吧!
32+
3. 使用愉快!
33+
4. [简书](http://www.jianshu.com/p/55c0b79b20d5)

Diff for: ZXCodeCreater/.DS_Store

0 Bytes
Binary file not shown.

Diff for: ZXCodeCreater/Base.lproj/Main.storyboard

+1-1
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@
653653
<scene sceneID="R2V-B0-nI4">
654654
<objects>
655655
<windowController id="B8D-0N-5wS" sceneMemberID="viewController">
656-
<window key="window" title="ZXCodeCreater" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="default" id="IQv-IB-iLA">
656+
<window key="window" title="CodeCreater" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="default" id="IQv-IB-iLA">
657657
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
658658
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
659659
<rect key="contentRect" x="196" y="240" width="480" height="270"/>

Diff for: ZXCodeCreater/Resource/.DS_Store

6 KB
Binary file not shown.

Diff for: ZXCodeCreater/Resource/IntroductionDiagram.png

204 KB
Loading

Diff for: ZXCodeCreater/Resource/IntroductionDiagram.sketch

216 KB
Binary file not shown.

Diff for: ZXCodeCreater/Ulits/FileManager.h

+4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010

1111
@interface FileManager : NSObject
1212
+ (FileManager *)sharedInstance;
13+
/**创建文件夹*/
1314
- (void)createFolderAtPath:(NSString *)folder;
15+
/**创建文件*/
1416
- (void)createFileAtPath:(NSString *)FilePath content:(NSString *)content;
17+
/**获取文件内容*/
1518
- (NSString *)getStringWithContentsOfFilePath:(NSString *)filePath;
19+
/**根据目录遍历文件夹*/
1620
- (NSArray *)getFilePathArrWithPath:(NSString *)dirPath;
1721
@end

Diff for: ZXCodeCreater/ViewController.m

+5-2
Original file line numberDiff line numberDiff line change
@@ -171,26 +171,29 @@ - (void)openPanelWithSenderTag:(NSUInteger)tag
171171

172172
- (void)creatFolderAndFileAtModuleFilePath:(NSString *)filePath
173173
{
174-
175174
//所有的文件以及文件夹子目录
176175
NSArray *filePathArr = [[FileManager sharedInstance] getFilePathArrWithPath:filePath];
177176
for (NSString *subPath in filePathArr) {
178177
NSString * wholePath = [filePath stringByAppendingPathComponent:subPath];
178+
//直接修改路径,然后根据路径新建文件夹及其文件,也就相当于修改文件及其文件夹名称;
179179
NSString *newWholePath = [wholePath stringByReplacingOccurrencesOfString:self.moduleClassPrefix withString:self.targetClassPrefix];
180180
//忽略隐藏文件
181181
if ([subPath containsString:@".DS_Store"]) {
182182

183183
continue;
184184
}
185-
//文件夹路径;如果是文件夹的话,就创建文件夹
185+
//文件夹路径;如果是文件夹的话,就创建文件夹(如果后缀是.h或者.m的话,那么就是文件,否则是文件夹)
186186
if (!([subPath containsString:@".h"]||[subPath containsString:@".m"])) {
187187

188188
[[FileManager sharedInstance] createFolderAtPath:newWholePath];
189189
continue;
190190
}
191191
NSString *str = [[FileManager sharedInstance] getStringWithContentsOfFilePath:wholePath];
192+
//将文件中的字段替换成目标字段
192193
NSString *replacedStr = [str stringByReplacingOccurrencesOfString:self.moduleClassPrefix withString:self.targetClassPrefix];
194+
//修改文件顶部注释的模板文件中的日期;
193195
NSString *stringAfterReplaceDate = [self replaceModuleDateWithNowDate:[self getNowDateStr] nowYear:[self getNowYearStr] moduleStr:replacedStr];
196+
//创建文件
194197
[[FileManager sharedInstance] createFileAtPath:newWholePath content:stringAfterReplaceDate];
195198
}
196199
[[NSWorkspace sharedWorkspace] openFile:filePath];
6 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// ZXCodeCreaterTestView.h
3+
// ZXCodeCreater
4+
//
5+
// Created by zx on 17/6/26.
6+
// Copyright © 2017年 zx. All rights reserved.
7+
//
8+
9+
#import <Cocoa/Cocoa.h>
10+
11+
@interface ZXCodeCreaterTestView : NSView
12+
13+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// ZXCodeCreaterTestView.m
3+
// ZXCodeCreater
4+
//
5+
// Created by zx on 17/6/26.
6+
// Copyright © 2017年 zx. All rights reserved.
7+
//
8+
9+
#import "ZXCodeCreaterTestView.h"
10+
11+
@implementation ZXCodeCreaterTestView
12+
13+
- (void)drawRect:(NSRect)dirtyRect {
14+
[super drawRect:dirtyRect];
15+
16+
// Drawing code here.
17+
}
18+
19+
@end

0 commit comments

Comments
 (0)