/
App.xojo_code
388 lines (288 loc) · 11.6 KB
/
App.xojo_code
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
#tag Class
Protected Class App
Inherits ConsoleApplication
#tag Event
Function Run(args() as String) As Integer
ParseOptions(args)
Project = New XdocProject(ProjectFile)
Project.ReadManifest
For fIdx As Integer = Project.Files.Ubound DownTo 0
Dim file As XdocFile = Project.Files(fIdx)
If IncludePackages.Ubound > -1 Then
For Each include As String In IncludePackages
If file.FullName.InStr(include) <> 1 Then
Print " Skipping, not on include list: " + file.FullName
Project.Files.Remove fIdx
End If
Next
End If
For Each exclude As String In ExcludePackages
If file.FullName.InStr(exclude) = 1 Then
Print " Skipping, on exclude list: " + file.FullName
Project.Files.Remove fIdx
End If
Next
Next
For fIdx As Integer = 0 To Project.Files.Ubound
Dim file As XdocFile = Project.Files(fIdx)
Print "Processing: " + file.File.Name
file.Parse(Flags)
If Not (OutputFile Is Nil) And file.Name = "App" Then
// Look for a "Project Overview" Note
For nIdx As Integer = 0 To file.Notes.Ubound
Dim n As XdocNote = file.Notes(nIdx)
If n.Name = "Project Overview" Then
n.Name = ProjectFile.Name.Left(ProjectFile.Name.Len - 13)
Project.ProjectNote = n
file.Notes.Remove nIdx
Exit For nIdx
End If
Next
End If
Next
Dim fh As FolderItem
Dim asSingle As Boolean
If Not (OutputFile Is Nil) Then
fh = OutputFile
asSingle = True
Else
fh = OutputFolder
asSingle = False
End If
Dim writer As BaseWriter
Select Case OutputFormat
Case "markdown"
writer = New MarkdownWriter
Case "asciidoc"
writer = New AsciiDocWriter
Case Else
Print "Unknown format: " + OutputFormat
Print "known formats: markdown, asciidoc"
Quit 1
End Select
writer.Project = project
If asSingle Then
writer.StartNewFile(OutputFile)
If Not (Project.ProjectNote Is Nil) Then
writer.WriteProjectOverview(Project.ProjectNote)
End If
End If
Dim files() As XdocFile = Project.Files
Dim fileNames() As String
ReDim fileNames(files.Ubound)
For fileIdx As Integer = 0 To files.Ubound
fileNames(fileIdx) = files(fileIdx).FullName
Next
fileNames.SortWith(files)
For fileIdx As Integer = 0 To files.Ubound
Dim f As XdocFile = files(fileIdx)
If Not asSingle Then
If FlatOutput Then
writer.StartNewFile(OutputFolder, f.FullName)
Else
Dim rootFh As FolderItem = GetRoot(OutputFolder, f)
writer.StartNewFile(rootFh, f.Name)
End If
End If
writer.WriteFile(f)
If Not asSingle Then
writer.EndCurrentFile
End If
Next
If asSingle Then
writer.EndCurrentFile
End If
End Function
#tag EndEvent
#tag Method, Flags = &h21
Private Function GetRoot(root As FolderItem, f As XdocFile) As FolderItem
If f.ParentId = "" Or f.ParentId = "&h0" Then
Return root
End If
Dim current As XdocFolder = Project.Folders.Value(f.ParentId)
Dim parents() As XdocFolder
Do
parents.Append current
current = Project.Folders.Lookup(current.ParentId, Nil)
Loop Until current Is Nil
Dim fh As FolderItem = root
For i As Integer = parents.Ubound DownTo 0
fh = fh.Child(parents(i).Name)
If Not fh.Exists Then
fh.CreateAsFolder
End If
Next
Return fh
End Function
#tag EndMethod
#tag Method, Flags = &h21
Private Sub ParseOptions(args() As String)
Options = New OptionParser
Options.ExtrasRequired = 1
Dim o As Option
o = New Option("", "output-format", "Format of the output, default: asciidoc, others: markdown")
Options.AddOption o
o = New Option("", "flat", "Flatten output directory structure", Option.OptionType.Boolean)
Options.AddOption o
o = New Option("f", "output-file", "Write to a single file", Option.OptionType.File)
Options.AddOption o
o = New Option("o", "output-directory", "Directory to write files to", Option.OptionType.Directory)
Options.AddOption o
o = New Option("", "include-private", "Include items marked private", Option.OptionType.Boolean)
Options.AddOption o
o = New Option("", "include-protected", "Include items marked protected", Option.OptionType.Boolean)
Options.AddOption o
o = New Option("", "include-events", "Include implemented events", Option.OptionType.Boolean)
Options.AddOption o
o = New Option("e", "exclude", "Exclude items beginning with Full Name of")
Options.AddOption o
o = New Option("i", "include", "Include items beginning with Full Name of")
Options.AddOption o
Options.Parse(args)
OutputFolder = Options.FileValue("output-directory")
OutputFile = Options.FileValue("output-file")
If OutputFile Is Nil And OutputFolder Is Nil Then
stderr.WriteLine "When writing multiple files (no -s/--single), you must specify -o/--output-directory"
Options.ShowHelp
Quit 1
ElseIf Not (OutputFolder Is Nil) Then
OutputFolder.CreateAsFolder
ElseIf Not (OutputFile Is Nil) Then
If Not OutputFile.IsWriteable Then
stderr.WriteLine "Output file: " + OutputFile.Name + " is not writable"
Quit 1
End If
End If
#Pragma Warning "How is this affecting all of our other applications, i.e. a symlink"
If Options.Extra(0) = "xojodoc" Then
Options.Extra.Remove 0
End If
Dim projectFileName As String = Options.Extra(0)
ProjectFile = GetRelativeFolderItem(projectFileName)
If ProjectFile Is Nil Or Not ProjectFile.IsReadable Then
stderr.WriteLine "error: '" + projectFileName + "' does not exist or is not readable"
Quit 1
End If
ExcludePackages = Options.StringValue("exclude").Split(",")
IncludePackages = Options.StringValue("include").Split(",")
FlatOutput = Options.BooleanValue("flat")
If options.BooleanValue("include-private") Then
Flags = Flags + kIncludePrivate
End If
If options.BooleanValue("include-protected") Then
Flags = Flags + kIncludeProtected
End If
If options.BooleanValue("include-events") Then
Flags = Flags + kIncludeEvents
End If
OutputFormat = options.StringValue("output-format", "asciidoc")
End Sub
#tag EndMethod
#tag Note, Name = Project Overview
WARNING: `xojodoc` is in its infancy. Just about everything is liable to change.
`xojodoc` needs early adopters to help solidify the application and
process. Thanks!
=== What is XojoDoc?
`xojodoc` is an application that will process a Xojo manifest file and create
source level documentation for the project and all included items.
=== Generating Documentation
`xojodoc` currently produces AsciiDoc or Markdown files.
* AsciiDoc produces nice manuals, books. It can generate html, xhtml,
docbook and LaTeX files.
* AsciiDoc is much more capable.
* Markdown is a little more known, with pandoc one can generate a variety
of files such as HTML, PDF and Microsoft Word.
* Markdown is simpler.
.Examples of AsciiDoc to HTML
----
$ xojodoc -f myproject.adoc myproject.xojo_project
$ asciidoc -a toc -a toclevels=2 -a icons -a source-highlighter=pygments myproject.adoc
----
.Examples of Markdown converting to HTML, Word and PDF
----
$ xojodoc --output-format=markdown -f myproject.md myproject.xojo_project
$ pandoc myproject.md -o myproject.html -s --toc --toc-depth=2
$ pandoc myproject.md -o myproject.docx
$ pandoc myproject.md -o myproject.pdf
----
Documenting Your Code
---------------------
For all element types, you can add a description via the Inspector/Gear "Description"
field. This, however, is currently limited to a single line description (see feature
request #34943).
If you want to provide more documentation you can in various ways.
To document a method, simply include (starting on the first line) a comment. Everything
in the first comment will be included as documentation. `xojodoc` stops processing the
method once the first non-comment line is encountered.
.Example
[source,vbnet]
----
Function SayHello(name As String) As Integer
' Say hello to someone.
'
' .Parameters
' * +name+: person to say hello to
'
' .Returns
' +1+ if the person nice and said hello back, +0+ if the person was mean
' and ignored us.
Print "Hello, " + name
' This comment is not included in the source doc output
Return 1
End Function
----
To document a property, simply type in the editor when the property is selected.
To document constants, create a Note in the Module/Class named "Constants". This
note will be output *instead of* the parsed constant code.
#tag EndNote
#tag Note, Name = TODO
* Unescape constants, for example "first\x2Clast\X2Cage"
#tag EndNote
#tag Property, Flags = &h21
Private ExcludePackages() As String
#tag EndProperty
#tag Property, Flags = &h21
Private Flags As Integer
#tag EndProperty
#tag Property, Flags = &h21
Private FlatOutput As Boolean
#tag EndProperty
#tag Property, Flags = &h21
Private IncludePackages() As String
#tag EndProperty
#tag Property, Flags = &h21
Private Options As OptionParser
#tag EndProperty
#tag Property, Flags = &h21
Private OutputFile As FolderItem
#tag EndProperty
#tag Property, Flags = &h21
Private OutputFolder As FolderItem
#tag EndProperty
#tag Property, Flags = &h21
Private OutputFormat As String
#tag EndProperty
#tag Property, Flags = &h0, Description = 5265666572656E636520746F206F75722063757272656E742050726F6A65637420746F2070726F6475636520646F63756D656E746174696F6E20666F72
Project As XdocProject
#tag EndProperty
#tag Property, Flags = &h21
Private ProjectFile As FolderItem
#tag EndProperty
#tag Constant, Name = BuildDateString, Type = String, Dynamic = False, Default = \"unknown", Scope = Public
#tag EndConstant
#tag Constant, Name = BuildNumber, Type = Double, Dynamic = False, Default = \"1", Scope = Public
#tag EndConstant
#tag Constant, Name = GitRevision, Type = String, Dynamic = False, Default = \"unknown", Scope = Public
#tag EndConstant
#tag Constant, Name = kIncludeEvents, Type = Double, Dynamic = False, Default = \"4", Scope = Public, Description = 42697420666F7220466C61677320746F20696E6469636174652063616C6C65722077616E747320746F20696E636C756465204576656E747320696E2074686520646F63756D656E746174696F6E
#tag EndConstant
#tag Constant, Name = kIncludePrivate, Type = Double, Dynamic = False, Default = \"1", Scope = Public, Description = 42697420666F7220466C61677320746F20696E6469636174652063616C6C65722077616E747320746F20696E636C7564652050726976617465206D656D6265727320696E2074686520646F63756D656E746174696F6E
#tag EndConstant
#tag Constant, Name = kIncludeProtected, Type = Double, Dynamic = False, Default = \"2", Scope = Public, Description = 42697420666F7220466C61677320746F20696E6469636174652063616C6C65722077616E747320746F20696E636C7564652050726F746563746564206D656D6265727320696E2074686520646F63756D656E746174696F6E
#tag EndConstant
#tag Constant, Name = ProductName, Type = String, Dynamic = False, Default = \"xojodoc", Scope = Public
#tag EndConstant
#tag ViewBehavior
#tag EndViewBehavior
End Class
#tag EndClass