FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
OneScript/src/OneScriptDocumenter/Program.cs at develop · ivtroitskiy/OneScript · GitHub
ivtroitskiy
/
OneScript
Public
forked from
EvilBeaver/OneScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
OneScript
/
src
/
OneScriptDocumenter
/
Program.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
313 lines (248 loc) · 9.83 KB
Breadcrumbs
OneScript
/
src
/
OneScriptDocumenter
/
Program.cs
Copy path
File metadata and controls
313 lines (248 loc) · 9.83 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/*----------------------------------------------------------
This Source Code Form is subject to the terms of the
Mozilla Public License, v.2.0. If a copy of the MPL
was not distributed with this file, You can obtain one
at http://mozilla.org/MPL/2.0/.
----------------------------------------------------------*/
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
IO
;
using
System
.
Text
;
using
System
.
Text
.
RegularExpressions
;
using
System
.
Xml
;
using
System
.
Xml
.
Linq
;
using
System
.
Xml
.
XPath
;
using
System
.
Xml
.
Xsl
;
using
System
.
Linq
;
namespace
OneScriptDocumenter
{
static
class
Program
{
static
int
Main
(
string
[
]
args
)
{
int
retCode
=
0
;
try
{
if
(
args
.
Length
>
0
&&
args
[
0
]
==
"markdown"
)
{
retCode
=
GenerateMarkdown
(
args
)
;
}
else
if
(
args
.
Length
>
0
&&
args
[
0
]
==
"html"
)
{
retCode
=
GenerateHtml
(
args
)
;
}
else
if
(
args
.
Length
>
0
&&
args
[
0
]
==
"json"
)
{
retCode
=
GenerateJSON
(
args
)
;
}
else
{
retCode
=
GenerateXml
(
args
)
;
}
}
catch
(
Exception
e
)
{
Console
.
WriteLine
(
e
.
ToString
(
)
)
;
retCode
=
128
;
}
if
(
System
.
Diagnostics
.
Debugger
.
IsAttached
)
Console
.
ReadKey
(
)
;
return
retCode
;
}
private
static
int
GenerateHtml
(
string
[
]
args
)
{
var
cmdLineArgs
=
new
CommandLineArgs
(
args
)
;
cmdLineArgs
.
Next
(
)
;
// пропуск ключевого слова
var
xmlDoc
=
cmdLineArgs
.
Next
(
)
;
if
(
xmlDoc
==
null
)
{
ShowUsage
(
)
;
return
1
;
}
var
outputDir
=
cmdLineArgs
.
Next
(
)
;
if
(
outputDir
==
null
)
outputDir
=
Directory
.
GetCurrentDirectory
(
)
;
var
baseUrl
=
cmdLineArgs
.
Next
(
)
;
var
inputDir
=
Path
.
Combine
(
Environment
.
GetEnvironmentVariable
(
"TMP"
)
,
Path
.
GetRandomFileName
(
)
)
;
Directory
.
CreateDirectory
(
inputDir
)
;
CreateDocumentation
(
xmlDoc
,
inputDir
,
baseUrl
)
;
var
files
=
Directory
.
EnumerateFiles
(
inputDir
,
"*.md"
,
SearchOption
.
AllDirectories
)
.
Select
(
x
=>
new
{
FullPath
=
x
,
RelativePath
=
x
.
Substring
(
inputDir
.
Length
+
1
)
}
)
;
Directory
.
CreateDirectory
(
outputDir
)
;
var
mdGen
=
new
MarkdownGen
(
)
;
mdGen
.
ExtraMode
=
true
;
mdGen
.
UrlBaseLocation
=
"stdlib"
;
var
layout
=
ReadHTMLLayout
(
)
;
foreach
(
var
file
in
files
)
{
Console
.
WriteLine
(
"Processing {0}"
,
file
.
RelativePath
)
;
using
(
var
inputFile
=
new
StreamReader
(
file
.
FullPath
)
)
{
var
content
=
inputFile
.
ReadToEnd
(
)
;
var
outputFile
=
Path
.
Combine
(
outputDir
,
file
.
RelativePath
.
Substring
(
0
,
file
.
RelativePath
.
Length
-
2
)
+
"htm"
)
;
var
html
=
mdGen
.
Transform
(
content
)
;
Directory
.
CreateDirectory
(
Path
.
GetDirectoryName
(
outputFile
)
)
;
using
(
var
outStream
=
new
StreamWriter
(
outputFile
,
false
,
Encoding
.
UTF8
)
)
{
var
full_html
=
layout
.
Replace
(
"$title$"
,
Path
.
GetFileNameWithoutExtension
(
outputFile
)
)
.
Replace
(
"$body$"
,
html
)
;
outStream
.
Write
(
full_html
)
;
}
}
}
Directory
.
Delete
(
inputDir
,
true
)
;
Console
.
WriteLine
(
"Done"
)
;
return
0
;
}
private
static
string
ReadHTMLLayout
(
)
{
using
(
var
sr
=
new
StreamReader
(
ExtFiles
.
Get
(
"html_layout.htm"
)
)
)
{
return
sr
.
ReadToEnd
(
)
;
}
}
private
static
int
GenerateJSON
(
string
[
]
args
)
{
var
cmdLineArgs
=
new
CommandLineArgs
(
args
)
;
cmdLineArgs
.
Next
(
)
;
// пропуск ключевого слова
var
outputFile
=
cmdLineArgs
.
Next
(
)
;
if
(
outputFile
==
null
)
{
ShowUsage
(
)
;
return
1
;
}
List
<
string
>
assemblies
=
new
List
<
string
>
(
)
;
while
(
true
)
{
var
arg
=
cmdLineArgs
.
Next
(
)
;
if
(
arg
==
null
)
break
;
assemblies
.
Add
(
arg
)
;
}
if
(
assemblies
.
Count
==
0
)
{
ShowUsage
(
)
;
return
1
;
}
return
CreateDocumentationJSON
(
outputFile
,
assemblies
)
;
}
private
static
int
GenerateXml
(
string
[
]
args
)
{
var
cmdLineArgs
=
new
CommandLineArgs
(
args
)
;
var
outputFile
=
cmdLineArgs
.
Next
(
)
;
if
(
outputFile
==
null
)
{
ShowUsage
(
)
;
return
1
;
}
List
<
string
>
assemblies
=
new
List
<
string
>
(
)
;
while
(
true
)
{
var
arg
=
cmdLineArgs
.
Next
(
)
;
if
(
arg
==
null
)
break
;
assemblies
.
Add
(
arg
)
;
}
if
(
assemblies
.
Count
==
0
)
{
ShowUsage
(
)
;
return
1
;
}
return
CreateDocumentation
(
outputFile
,
assemblies
)
;
}
private
static
int
GenerateMarkdown
(
string
[
]
args
)
{
var
cmdLineArgs
=
new
CommandLineArgs
(
args
)
;
cmdLineArgs
.
Next
(
)
;
// пропуск ключевого слова
var
xmlDoc
=
cmdLineArgs
.
Next
(
)
;
if
(
xmlDoc
==
null
)
{
ShowUsage
(
)
;
return
1
;
}
var
outputDir
=
cmdLineArgs
.
Next
(
)
;
if
(
outputDir
==
null
)
outputDir
=
Directory
.
GetCurrentDirectory
(
)
;
var
baseUrl
=
cmdLineArgs
.
Next
(
)
;
return
CreateDocumentation
(
xmlDoc
,
outputDir
,
baseUrl
)
;
}
private
static
int
CreateDocumentation
(
string
outputFile
,
List
<
string
>
assemblies
)
{
var
documenter
=
new
Documenter
(
)
;
var
doc
=
documenter
.
CreateDocumentation
(
assemblies
)
;
doc
.
Save
(
outputFile
)
;
return
0
;
}
private
static
int
CreateDocumentationJSON
(
string
outputFile
,
List
<
string
>
assemblies
)
{
var
documenter
=
new
Documenter
(
)
;
documenter
.
CreateDocumentationJSON
(
outputFile
,
assemblies
)
;
return
0
;
}
private
static
int
CreateDocumentation
(
string
xmlDocPath
,
string
pathOutput
,
string
baseUrl
)
{
XDocument
doc
;
using
(
var
fs
=
new
FileStream
(
xmlDocPath
,
FileMode
.
Open
,
FileAccess
.
Read
)
)
{
doc
=
XDocument
.
Load
(
fs
)
;
}
string
docContent
=
doc
.
ToString
(
)
;
XslCompiledTransform
xslt
=
new
XslCompiledTransform
(
)
;
xslt
.
Load
(
ExtFiles
.
Get
(
"markdown.xslt"
)
)
;
XPathDocument
xpathdocument
=
new
XPathDocument
(
new
StringReader
(
docContent
)
)
;
var
stream
=
new
MemoryStream
(
)
;
XmlTextWriter
writer
=
new
XmlTextWriter
(
stream
,
Encoding
.
UTF8
)
;
xslt
.
Transform
(
xpathdocument
,
null
,
writer
,
null
)
;
stream
.
Position
=
0
;
XDocument
xdoc
=
XDocument
.
Load
(
stream
)
;
writer
.
Close
(
)
;
if
(
!
Directory
.
Exists
(
pathOutput
)
)
Directory
.
CreateDirectory
(
pathOutput
)
;
var
contentStdlibPath
=
Path
.
Combine
(
pathOutput
,
"stdlib"
)
;
Directory
.
CreateDirectory
(
contentStdlibPath
)
;
var
tocBuilder
=
new
StringBuilder
(
)
;
var
knownNodes
=
new
HashSet
<
string
>
(
)
;
if
(
baseUrl
==
null
)
baseUrl
=
""
;
using
(
var
layout
=
new
StreamReader
(
ExtFiles
.
Get
(
"toc_layout.md"
)
)
)
{
var
content
=
layout
.
ReadToEnd
(
)
;
tocBuilder
.
Append
(
content
)
;
tocBuilder
.
Replace
(
"$base_url$"
,
baseUrl
)
;
var
matches
=
Regex
.
Matches
(
content
,
@"(?=\S)\[(.*)\]\S"
)
;
foreach
(
Match
match
in
matches
)
{
var
uri
=
match
.
Groups
[
1
]
.
Value
;
knownNodes
.
Add
(
uri
)
;
}
}
using
(
var
tocWriter
=
new
StreamWriter
(
Path
.
Combine
(
pathOutput
,
"stdlib.md"
)
)
)
{
tocWriter
.
Write
(
tocBuilder
.
ToString
(
)
)
;
tocBuilder
.
Clear
(
)
;
foreach
(
var
fileNode
in
xdoc
.
Root
.
Elements
(
"document"
)
)
{
string
name
=
fileNode
.
Attribute
(
"href"
)
.
Value
.
Replace
(
".md"
,
""
)
;
string
link
=
name
.
Replace
(
" "
,
"%20"
)
;
string
path
=
Path
.
Combine
(
contentStdlibPath
,
fileNode
.
Attribute
(
"href"
)
.
Value
)
;
var
file
=
new
FileStream
(
path
,
FileMode
.
Create
)
;
using
(
var
fileWriter
=
new
StreamWriter
(
file
)
)
{
fileWriter
.
Write
(
fileNode
.
Value
)
;
}
if
(
!
knownNodes
.
Contains
(
name
)
)
tocWriter
.
WriteLine
(
"* [{0}]({1}/{2})"
,
name
,
baseUrl
,
link
)
;
}
}
return
0
;
}
static
void
ShowUsage
(
)
{
Console
.
WriteLine
(
"Usage:"
)
;
Console
.
WriteLine
(
"OneScriptDocumenter.exe <output-file> <path-to-dll> [<path-to-dll>...]"
)
;
Console
.
WriteLine
(
"OneScriptDocumenter.exe json <output-file> <path-to-dll> [<path-to-dll>...]"
)
;
Console
.
WriteLine
(
"OneScriptDocumenter.exe markdown <path-to-xml> <output-dir> [baseurl]"
)
;
Console
.
WriteLine
(
"OneScriptDocumenter.exe html <path-to-xml> <output-dir> [baseurl]"
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL