This repository was archived by the owner on Dec 12, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathXSourceNoteFormatter.m
More file actions
96 lines (78 loc) · 3.16 KB
/
Copy pathXSourceNoteFormatter.m
File metadata and controls
96 lines (78 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// XSourceNoteFormatter.m
// XSourceNote
//
// Created by everettjf on 16/3/9.
// Copyright © 2016年 everettjf. All rights reserved.
//
#import "XSourceNoteFormatter.h"
#import "XSourceNoteStorage.h"
#import "XSourceNoteDefaults.h"
@implementation XSourceNoteFormatter
+ (XSourceNoteFormatter *)sharedFormatter{
static XSourceNoteFormatter *inst;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
inst = [[XSourceNoteFormatter alloc]init];
});
return inst;
}
- (BOOL)saveTo:(NSString *)filePath{
XSourceNoteDefaults *def = [XSourceNoteDefaults sharedDefaults];
XSourceNoteStorage *st = [XSourceNoteStorage sharedStorage];
NSMutableString *content = [[NSMutableString alloc]init];
NSString *filePrefix = st.filePrefix;
if(filePrefix && ![filePrefix isEqualToString:@""]){
[content appendString:st.filePrefix];
[content appendString:@"\n\n\n"];
}
[content appendFormat:@"# Basic Information\n"];
[content appendFormat:@" - Name : %@\n", st.projectName];
[content appendFormat:@" - Site : %@\n", st.projectSite];
[content appendFormat:@" - Repo : %@\n", st.projectRepo];
[content appendFormat:@" - Revision : %@\n", st.projectRevision];
[content appendFormat:@" - Description : \n"];
[content appendString: st.projectDescription];
[content appendString:@"\n"];
[content appendString:@"\n\n"];
[content appendFormat:@"# Global Note\n"];
[content appendString:st.projectNote];
[content appendString:@"\n\n"];
[content appendString:@"# File Notes\n"];
NSArray *notes = [st fetchAllLineNotes];
[notes enumerateObjectsUsingBlock:^(XSNote * _Nonnull n, NSUInteger idx, BOOL * _Nonnull stop) {
[content appendFormat:@"\n## %@. %@\n\n",@(idx), [n.source lastPathComponent]];
[content appendFormat:@" - Path : %@\n",n.source];
[content appendFormat:@" - Line : %@ - %@\n", n.begin, n.end];
[content appendFormat:@" - Note : \n"];
// Code block
if(n.code){
[content appendString:@"\n"];
if([def.codeStyle isEqual:@0]){
[content appendString:@"```\n"];
[content appendString:n.code];
[content appendString:@"```\n"];
}else{
[content appendString:@"{% highlight oc %}\n"];
[content appendString:n.code];
[content appendString:@"{% endhighlight %}\n"];
}
[content appendString:@"\n"];
}
[content appendFormat:@"\n%@\n",n.content];
[content appendString:@"\n"];
}];
[content appendString:@"\n\n"];
[content appendFormat:@"# Summarize\n"];
[content appendString:st.projectSummarize];
[content appendString:@"\n\n"];
[content appendString:@"\n\n"];
[content appendFormat:@"---\n"];
[content appendFormat:@"*Generated by [XSourceNote](https://github.com/everettjf/XSourceNote) at %@*\n", [NSDate date]];
NSError *error;
if(![content writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:&error]){
return NO;
}
return YES;
}
@end