forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs_builder.livecodescript
More file actions
2226 lines (1925 loc) · 91.8 KB
/
docs_builder.livecodescript
File metadata and controls
2226 lines (1925 loc) · 91.8 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
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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
script "DocsBuilder"
# The max number allowed
constant kFilesPerClump = 50
# Probably not a good idea to change this...
constant kClumpNamePrefix = "revDocClump_"
private function docsBuilderGetSourceDirectory
return builderDocsFolder()
end docsBuilderGetSourceDirectory
private function docsBuilderGetOutputDirectory
return builderBuiltDocsFolder()
end docsBuilderGetOutputDirectory
command docsBuilderProgressUpdate pProgress, pMessage
builderLog "message", pMessage
end docsBuilderProgressUpdate
command errorShow pError
builderLog "error", pError
throw pError
end errorShow
command docsBuilderRun pEdition, pVersion
set the itemdelimiter to "."
if item 1 of pVersion > 7 then
start using stack (builderRepoFolder() & slash & "ide-support/revdocsparser.livecodescript")
docsBuilderGenerateDocsNew
exit docsBuilderRun
end if
local tSourceDir, tOutputDir
put docsBuilderGetSourceDirectory() into tSourceDir
put docsBuilderGetOutputDirectory() & "/packaged_xml" into tOutputDir
start using stack (builderIdeRepoFolder() & slash & "Toolset/palettes/revdocumentationlibrary.rev")
builderLog "report", "Building docs into" && tOutputDir
buildDocumentation tSourceDir & "/dictionary", tSourceDir & "/glossary", tOutputDir & "/dictionary", tOutputDir & "/glossary", tOutputDir, "docsBuilderProgressUpdate", the long id of me
builderLog "report", "Building docs into" && tOutputDir && "complete"
end docsBuilderRun
command buildDocumentation pDictionaryInputDirectory, pGlossaryInputDirectory, pDictionaryOutputDirectory, pGlossaryOutputDirectory, pManifestOutputDirectory, pCallback, pCallbackTarget
initializeProgress pCallback, pCallbackTarget
reportProgress "Cleaning Directory", 0, "Cleaning Existing Structure"
# Create the subdirectories we need.
pathEnsure (pDictionaryOutputDirectory)
pathEnsure (pGlossaryOutputDirectory)
# Ensure the subDirectories we need were created.
if there is no folder pDictionaryOutputDirectory then
errorShow "libDocumentClumpGenerateAll", "Invalid output directory: " & pDictionaryOutputDirectory
exit buildDocumentation
end if
if there is no folder pGlossaryOutputDirectory then
errorShow "libDocumentClumpGenerateAll", "Invalid output directory: " & pGlossaryOutputDirectory
exit buildDocumentation
end if
# Clean any existing clumps out of memory to prevent interference.
deleteExistingClumpsFromMemory
local tFileToDirectory, tLinkLookup
# Get the the file reference information
libDocumentationListXMLFiles pGlossaryInputDirectory, tFileToDirectory
reportProgress "Glossary", 0, "Listed XML files"
libDocumentationListXMLFiles pDictionaryInputDirectory, tFileToDirectory
reportProgress "Dictionary", 0, "Listed XML files"
#Get the cross reference information for the internal links
libDocumentationCreateDocRefs tFileToDirectory
put libCreateLookupTable (tFileToDirectory) into tLinkLookup
# Build XRef symmetry - create symmetry entries in the lookup array
libDocumentationCreateXRefSymmertry tFileToDirectory, tLinkLookup
# Compile the dictionary and glossary into a collection of stacks with
# compressed custom properties.
compileDictionaryIntoStacks pDictionaryInputDirectory, pDictionaryOutputDirectory, tFileToDirectory, tLinkLookup
compileGlossaryIntoStacks pGlossaryInputDirectory, pGlossaryOutputDirectory, tFileToDirectory, tLinkLookup
# Create a manifest in the packaged_xml directory as the files are dynamic.
createManifest pManifestOutputDirectory
reportProgress empty, 100, "Done"
end buildDocumentation
local sProgress
local sProgressCallback
local sProgressCallbackTarget
local sProgressStepStatus
// HSC - tested - complies with current dictionary format
private command initializeProgress pCallback, pCallbackTarget
put empty into sProgress
put empty into sProgressStepStatus
# The callback is optional.
if pCallback is not empty and pCallbackTarget is not empty then
put pCallback into sProgressCallback
put pCallbackTarget into sProgressCallbackTarget
end if
end initializeProgress
local sLastTime
private command reportProgress pStep, pPercentage, pMessage
# This lets us configure the approximate proportions each step is of the whole process,
# so that the progress is fairly smooth. (These are quite rough...)
local tProportion
switch pStep
case "Dictionary"
put 20 into tProportion
break
case "Glossary"
put 1 into tProportion
break
case "Creating glossary index"
put 4 into tProportion
break
case "Manifest"
put "4" into tProportion
break
case "Cleaning Directory"
put 11 into tProportion
break
case "Creating dictionary index"
put 33 into tProportion
break
case "Verifying dictionary"
put 37 into tProportion
break
end switch
# When a step is complete, add its proportion to the current progress.
# The current progess is the overall progress plus the step percentage.
local tStepPercentage
if pPercentage = 100 then
if sProgressStepStatus[pStep] is not "Complete" then
put "Complete" into sProgressStepStatus[pStep]
add tProportion to sProgress
end if
put 0 into tStepPercentage
else
put ((pPercentage / 100) * tProportion) into tStepPercentage
end if
local tCurrentProgress
put sProgress + tStepPercentage into tCurrentProgress
# Here we can send a message back to the caller to indicate progress
# of the docs building, but for now we just display progress on the card.
if sProgressCallback is not empty and sProgressCallbackTarget is not empty then
send sProgressCallback && "tCurrentProgress, pMessage" to sProgressCallbackTarget
end if
if the mode of me is not 0 and the visible of me then
if the millisecs - sLastTime > 500 then
statusSet pMessage
set the thumbPosition of scrollbar 1 of me to tCurrentProgress
put the millisecs into sLastTime
end if
end if
end reportProgress
private command statusSet pMessage
put pMessage into field "Status" of me
end statusSet
// HSC - tested - complies with current dictionary format
private command deleteExistingClumpsFromMemory
repeat for each line tStack in the mainstacks
if tStack begins with "revDocClump_" then
lock messages
delete stack tStack
unlock messages
end if
end repeat
end deleteExistingClumpsFromMemory
private command compileGlossaryIntoStacks pInputDirectory, pOutputDirectory, @pFileToDirectory, @pLinkLookup
local tArrIndex, tFilePath, tRelFilePath, tKeyNumber
local tOldPath
put the directory into tOldPath
local tPath
put pInputDirectory into tPath
set the directory to tPath
reportProgress "Glossary", 0, "Listed XML files"
-- Now loop through the list of files and add the file data to the relevant clump
local tFileNumber, tClumpNumber, tClumpName, tCount = 1
repeat with tArrIndex = 1 to the number of elements of pFileToDirectory
-- Work out which clump to add the file to from its name (number)
if pFileToDirectory[tArrIndex]["type"] is "glossary" then
put ((tArrIndex - 1) div kFilesPerClump) + 1 into tClumpNumber
put kClumpNamePrefix & tClumpNumber into tClumpName
if there is no stack tClumpName then
libDocumentationClumpCreate tClumpNumber, pOutputDirectory
end if
-- Get the relative file path of the entry
put pFileToDirectory[tArrIndex]["path"] into tFilepath
set the itemDelimiter to slash
put item -3 to -1 of tFilepath into tRelFilepath
put libDocumentationClumpAddTo(tClumpName, tArrIndex, pFileToDirectory, pOutputDirectory, pLinkLookup) into tKeyNumber
reportProgress "Glossary", ((tArrIndex / the number of elements of pFileToDirectory) * 100), "Added glossary entry: " & item -1 of tFilePath
//reportProgress "Glossary", ((tArrIndex / the number of lines of pFileToDirectory) * 100), "Added glossary entry: " & item -1 of tFilePath
set the itemDelimiter to comma
end if
end repeat
-- Clean up
repeat for each line tStack in the mainStacks
if char 1 to (the length of kClumpNamePrefix) of tStack is kClumpNamePrefix then
delete stack tStack
end if
end repeat
reportProgress "Glossary", 100, "Glossary Built"
# Build the index for the xml files
libDocumentationBuildGlossaryIndex pFileToDirectory, pOutputDirectory
end compileGlossaryIntoStacks
// HSC - tested - complies with current dictionary format
private command libDocumentationListXMLFiles pDirectory, @rFileToPath
local tOldDirectory
put the directory into tOldDirectory
set the directory to pDirectory
local tDirectories
put the folders into tDirectories
filter tDirectories without ".."
local tFiles, tItems
put the number of elements of rFileToPath into tItems
repeat for each line tDirectory in tDirectories
set the directory to pDirectory & slash & tDirectory
put the files into tFiles
filter tFiles with "*.xml"
repeat for each line tFile in tFiles
if tFile is not "" then
add 1 to tItems
put pDirectory & slash & tDirectory & slash & tFile into rFileToPath[tItems]["path"]
put tFile into rFileToPath[tItems]["name"]
if the length of tDirectory is 1 then
put "glossary" into rFileToPath[tItems]["type"]
else
put tDirectory into rFileToPath[tItems]["type"]
end if
end if
end repeat
end repeat
set the directory to tOldDirectory
end libDocumentationListXMLFiles
private command libDocumentationCreateDocRefs @rFileToDirectory
local tTree, tName, tArrIndex
repeat with tArrIndex = 1 to the number of elements of rFileToDirectory
open file rFileToDirectory[tArrIndex]["path"] for read
read from file rFileToDirectory[tArrIndex]["path"] until EOF
// extract the <name> or <term> from the files and update the rFileToDirectory information
put revCreateXMLTree(it, false, true, false) into tTree
if tTree is not an integer then
errorShow "Failed to process preferences file with error: " & tTree
return empty
end if
put revXMLNodeContents(tTree, "doc/name") into tName
if matchText(tName,"xmlerr") then
put revXMLNodeContents(tTree, "doc/term") into tName
end if
if matchText(tName,"xmlerr") then
//breakpoint
end if
// Build XRef symmetry - add see also links to the array structure
local tXrefs, tXref, tXrefToReplace, tTextStart, tTextEnd, tOffsetFound
put libGetTextLocation (it, "<references>", "</references>", tTextStart, tTextEnd) into tXrefs
if tTextStart is not 0 and tTextEnd is not 0 then
replace "<references>" with "" in tXrefs
put true into tOffsetFound
set the itemDelimiter to space
repeat while tOffsetFound
// need to include the tStartTags in another repeat loop this will be for the new files.
put libGetTextLocation (tXrefs, "<", ">", tTextStart, tTextEnd) into tXrefToReplace
if tTextStart is 0 and tTextEnd is 0 then
put false into tOffsetFound
else
put tXrefToReplace into tXref
replace "<" with "" in tXref
replace ">" with "" in tXref
replace "tag=" with "" in tXref
replace quote with "" in tXref
replace tXrefToReplace with tXref in tXrefs
if character 1 of tXref is not "/" then
put tXref & return after rFileToDirectory[tArrIndex]["xrefs"]
end if
end if
end repeat
end if
// need the following line as revXMLNodeContents decides to turn "&" into "&"
put escapeEntities (tName) into tName
put tName into rFileToDirectory[tArrIndex]["ref"]
close file rFileToDirectory[tArrIndex]["path"]
end repeat
end libDocumentationCreateDocRefs
command libDocumentationCreateXRefSymmertry @rFileToDirectory, @rLinkLookup
local tArrIndex, tReferenceTo
repeat with tArrIndex = 1 to the number of elements of rFileToDirectory
if "xrefs" is among the keys of rFileToDirectory[tArrIndex] then
repeat for each line tReferenceTo in rFileToDirectory[tArrIndex]["xrefs"]
if rFileToDirectory[tArrIndex]["type"] && rFileToDirectory[tArrIndex]["ref"] is not among the lines of rFileToDirectory[rLinkLookup[tReferenceTo]]["xrefs"] then
put rFileToDirectory[tArrIndex]["type"] && rFileToDirectory[tArrIndex]["ref"] & return after rFileToDirectory[rLinkLookup[tReferenceTo]]["xrefs"]
end if
end repeat
end if
end repeat
end libDocumentationCreateXRefSymmertry
private command createManifest pDirectory
reportProgress "Manifest", 0, "Listing files for manifest"
local tFiles
put utilityEnumerateDirectory(pDirectory) into tFiles
reportProgress "Manifest", 70, "Finished listing manifest files"
local tManifest
repeat for each line tFile in tFiles
if the last char of tFile is slash then
# Don't include directories
next repeat
end if
if tFile ends with "/Manifest" then
next repeat
end if
put "file," & slash & tFile & return after tManifest
end repeat
delete the last char of tManifest
local tResult
put tManifest into url ("file:" & pDirectory & "/Manifest")
put the result into tResult
if tResult is not empty then
errorShow "Failed to write manifest at location: " & pDirectory & "/Manifest" & return & "With error: " & tResult
exit createManifest
end if
reportProgress "Manifest", 100, "Finished creating manifest"
end createManifest
# Stolen from standalone builder.
private function utilityEnumerateDirectory pDirectory, pPrefix
local tOldDirectory, tResult
put the folder into tOldDirectory
set the folder to pDirectory
# OK-2008-09-10 : Bug 7147 - Prevent the possibility of an infinite loop by
# returning empty if the directory cannot be set to pDirectory
if the folder is not pDirectory then
return empty
end if
repeat for each line tSubDirectory in the folders
if tSubDirectory is among the items of ".,.." then
next repeat
end if
# For our purposes we need the directory first, so it can be created ahead of file creation..
put pPrefix & tSubDirectory & "/" & return after tResult
get utilityEnumerateDirectory(pDirectory & "/" & tSubDirectory, pPrefix & tSubDirectory & "/")
if it is not empty then
put it & return after tResult
end if
end repeat
local tFileSize
repeat for each line tFile in the files
put pPrefix & tFile & return after tResult
end repeat
set the folder to tOldDirectory
delete the last char of tResult
return tResult
end utilityEnumerateDirectory
private function extractFileNumberFromPath pPath
set the itemDelimiter to slash
get item -1 of pPath
set the itemDelimiter to "."
return item 1 of it
end extractFileNumberFromPath
private command compileDictionaryIntoStacks pInputDirectory, pOutputDirectory, @pFileToDirectory, @pLinkLookup
local tDocDirectory, tDirectory, tDirectories, tFile, tFiles, tFilepath
local tCurrentClumpNumber, tIndexData, tKeyNumber, tRelFilepath, tOutputDirectory
local tXMLFiles, tFileToPath
local tOldPath
put the directory into tOldPath
local tPath
put pInputDirectory into tPath
set the directory to tPath
reportProgress "Dictionary", 0, "Listed XML files"
-- Now loop through the list of files and add the file data to the relevant clump
local tFileNumber, tClumpNumber, tClumpName, tCount = 1
repeat with tArrIndex = 1 to the number of elements of pFileToDirectory
-- Work out which clump to add the file to from its name (number)
if pFileToDirectory[tArrIndex]["type"] is not "glossary" then
put ((tArrIndex - 1) div kFilesPerClump) + 1 into tClumpNumber
put kClumpNamePrefix & tClumpNumber into tClumpName
if there is no stack tClumpName then
libDocumentationClumpCreate tClumpNumber, pOutputDirectory
end if
-- Get the relative file path of the entry
put pFileToDirectory[tArrIndex]["path"] into tFilepath
set the itemDelimiter to slash
put item -3 to -1 of tFilepath into tRelFilepath
put libDocumentationClumpAddTo(tClumpName, tArrIndex, pFileToDirectory, pOutputDirectory, pLinkLookup) into tKeyNumber
if tArrIndex mod 10 is 0 then
reportProgress "Dictionary", ((tArrIndex / the number of elements of pFileToDirectory) * 100), "Added dictionary entry: " & item -1 of tFilePath
end if
set the itemDelimiter to comma
end if
end repeat
-- Clean up
repeat for each line tStack in the mainStacks
if char 1 to (the length of kClumpNamePrefix) of tStack is kClumpNamePrefix then
delete stack tStack
end if
end repeat
reportProgress "Dictionary", 100, "Dictionary built"
# Build the index for the xml files
libDocumentationBuildDictionaryIndex pFileToDirectory, pOutputDirectory
# Verify that the documentation is complete, we only bother doing this with the dictionary,
# as broken glossary entries don't matter as much.
local tResult
libDocumentationVerifyAll "dictionary/", pOutputDirectory
put the result into tResult
if the result is not empty then
throw "generation_failed - " & "libDocumentationClumpGenerateAll", "The following docs failed to build: " & return & tResult
exit to top
end if
end compileDictionaryIntoStacks
private function getIndexFileName pDirectory
if pDirectory is "dictionary/" then
return "dict.index"
else
return "glos.index"
end if
end getIndexFileName
private command libDocumentationVerifyAll pDocDirectory, pOutputDirectory
reportProgress "Verifying dictionary", 0, "Verifying dictionary"
local tIndexPath
local tIndexFileName
put getIndexFileName(pDocDirectory) into tIndexFileName
set the itemDelimiter to slash
put item 1 to -3 of pOutputDirectory & slash & tIndexFileName into tIndexPath
set the itemDelimiter to comma
local tIndex
put url ("binfile:" & tIndexPath) into tIndex
put arrayDecode(tIndex) into tIndex
local tDocsDirectory
set the itemDelimiter to slash
put item 1 to -3 of pOutputDirectory into tDocsDirectory
set the itemDelimiter to comma
local tResult
local tType, tTag
set the itemDelimiter to tab
local tTotal
put the number of lines of the keys of tIndex into tTotal
local tLineNumber
put 1 into tLineNumber
repeat for each key tLine in tIndex
put "dictionary/" into tType
put tIndex[tLine]["ID"] into tTag
local tData
try
put revDocumentationRetrieve(tType, tTag, tDocsDirectory) into tData
if tData is empty then
put "Failed to load dictionary entry: " & tTag && tType & return after tResult
end if
catch tError
put "Failed to load dictionary entry: " & tTag && tType & return after tResult
end try
if tLineNumber mod 10 = 0 then
reportProgress "Verifying dictionary", ((tLineNumber / tTotal) * 100), "Verified dictionary entry: " & tLine
end if
add 1 to tLineNumber
end repeat
reportProgress "Verifying dictionary", 100, "Dictionary verified"
return tResult
end libDocumentationVerifyAll
private command libDocumentationBuildGlossaryIndex pFileToDirectory, pOutputDirectory
local tStep
put "Creating glossary index" into tStep
reportProgress tStep, 0, tStep
local tIndexFileName
put getIndexFileName("glossary/") into tIndexFileName
local tIndexFile
set the itemDelimiter to slash
put item 1 to -3 of pOutputDirectory & slash & tIndexFileName into tIndexFile
local tIndex, tPath, tLine
local tArrIndex
repeat with tArrIndex = 1 to the number of elements of pFileToDirectory
if pFileToDirectory[tArrIndex]["type"] is "glossary" then
put pFileToDirectory[tArrIndex]["path"] into tPath
put indexGlossaryLine(tPath, tArrIndex) into tLine
put tLine & return after tIndex
end if
reportProgress tStep, ((tArrIndex / the number of elements of pFileToDirectory) * 100), "Indexed glossary file: " & item -1 of tPath
end repeat
set the itemDelimiter to comma
delete the last char of tIndex
local tResult
put tIndex into url ("file:" & tIndexFile)
put the result into tResult
if tResult is not empty then
errorShow "Failed to write to file: " & tIndexFile & " with error : " & tResult
exit libDocumentationBuildGlossaryIndex
end if
reportProgress tStep, 100, "Index creation finished"
end libDocumentationBuildGlossaryIndex
// HSC - tested - complies with current dictionary format
private command libDocumentationBuildDictionaryIndex pFileToDirectory, pOutputDirectory
local tStep
put "Creating dictionary index" into tStep
reportProgress tStep, 0, tStep
local tIndexFileName
put getIndexFileName("dictionary/") into tIndexFileName
local tIndexFile
set the itemDelimiter to slash
put item 1 to -3 of pOutputDirectory & slash & tIndexFileName into tIndexFile
local tIndex, tLine, tArrIndex, tPath
local tLineNumber
put 0 into tLineNumber
repeat with tArrIndex = 1 to the number of elements of pFileToDirectory
if pFileToDirectory[tArrIndex]["type"] is not "glossary" then
add 1 to tLineNumber
put pFileToDirectory[tArrIndex]["path"] into tPath
put indexLine(tPath, tArrIndex) into tLine
put tLine into tIndex[tLineNumber]
local tSynonyms
put expandSynonyms(tPath, tArrIndex) into tSynonyms
if tSynonyms is an array then
repeat for each key tKey in tSynonyms
add 1 to tLineNumber
put tSynonyms[tKey] into tIndex[tLineNumber]
end repeat
end if
end if
reportProgress tStep, ((tArrIndex / the number of elements of pFileToDirectory) * 100), "Indexed dictionary file: " & item -1 of tPath
end repeat
set the itemDelimiter to comma
local tResult
put arrayEncode(tIndex) into url ("binfile:" & tIndexFile)
put the result into tResult
if tResult is not empty then
errorShow "Failed to write to file: " & tIndexFile & " with error: " & tResult
exit libDocumentationBuildDictionaryIndex
end if
reportProgress tStep, 100, "Index creation finished"
end libDocumentationBuildDictionaryIndex
# This function does the following:
# 1. Opens the file pDocument and creates an xml tree of the contents.
# 2. Extract the "synonyms" node and processes it to obtain a list of the synonyms.
# 3. For each synonym, creates an index line linking to pDocument
# 4. Returns the list of index lines
private function expandSynonyms pDocument, pFilename
local tData
put url ("binfile:" & pDocument) into tData
if tData is empty then
errorShow "No data for file: " & pDocument
exit expandSynonyms
end if
local tTree
put revCreateXMLTree(tData, false, true, false) into tTree
local tRoot
put revXMLRootNode(tTree) into tRoot
if tTree is not a number then
errorShow "The document " & pDocument & " cannot be parsed by revXML"
exit expandSynonyms
end if
if tRoot is not "doc" then
errorShow "The document " & pDocument & " is not a valid dictionary entry because its root node is not <doc>"
exit expandSynonyms
end if
# Synonyms are stored as:
# <synonyms>
# <synonym>wd</synonym>
# <synonym>window</synonym>
# revXMLChildNames gives us a return-delimited list of each node containing a synonym.
local tNodes
put revXMLChildNames(tTree, "/doc/synonyms", return, "synonym", true) into tNodes
if tNodes is empty or item 1 of tNodes is "xmlerr" then
# No synonyms found, exit now...
return empty
end if
local tIndexLine
put indexLine(pDocument, pFilename) into tIndexLine
local tName
-- set the itemDelimiter to tab
-- put item 2 of tIndexLine into tName
-- set the itemDelimiter to comma
put tIndexLine["Keyword"] into tName
local tSynonym, tSynonyms, tContent
local tCount
put 0 into tCount
repeat for each line tNode in tNodes
add 1 to tCount
put revXMLNodeContents(tTree, "/doc/synonyms/" & tNode) into tContent
# For each one, copy the index line from the main doc, but replace the doc's name with the synonym.
put tIndexLine into tSynonym
--set the itemDelimiter to tab
# Replace the main name
# put tContent into item 2 of tSynonym
put tContent into tSynonym["Keyword"]
# Replace any references to the name in the syntax (hopefully this won't cause irregular syntax problems...)
--get item 4 of tSynonym
get tSynonym["Syntax"]
replace tName with tContent in it
--put it into item 4 of tSynonym
put it into tSynonym["Syntax"]
--set the itemDelimiter to comma
--put tSynonym & return after tSynonyms
put tSynonym into tSynonyms[tCount]
end repeat
--delete the last char of tSynonyms
revDeleteXMLTree tTree
return tSynonyms
end expandSynonyms
-- Given the path to an xml documentation entry (dictionary only),
-- returns the line of text in the dictionary index that corresponds
-- to the document.
// HSC - tested - complies with current dictionary format
private function indexLine pDoc, pIndex
local tFilename
set the itemDelimiter to slash
put item -1 of pDoc into tFilename
local tData
put url ("file:" & pDoc) into tData
local tArray
put pIndex into tArray["ID"]
local tTree
put revCreateXMLTree(tData, false, true, false) into tTree
if tTree is not a number then
breakpoint
end if
local tName, tCategory
put escapeEntities(revXMLNodeContents(tTree, "doc/name")) into tArray["Keyword"]
put revXMLNodeContents(tTree, "doc/type") into tArray["Type"]
if item 1 of tArray["Keyword"] is "xmlerr" then
errorShow "Could not extract name from the dictionary file : " & pDoc & " with error: " & tName
exit indexLine
end if
if item 1 of tArray["Type"] is "xmlerr" then
errorShow "Could not extract type from the glossary file : " & pDoc & " with error: " & tCategory
exit indexLine
end if
local tSyntax
set the itemDelimiter to comma
put extractNodeXML(tTree, "doc/syntax/example") into tSyntax
if item 1 of tSyntax is "xmlerr" then
put empty into tArray["Syntax"]
else
put auxFormatSyntax(tSyntax) into tArray["Syntax"]
end if
local tSynonymInfo, tSynonyms
put revXMLChildContents(tTree, "doc/synonyms", slash, comma, true, 1) into tSynonymInfo
repeat for each item tChild in tSynonymInfo
set the itemDelimiter to slash
put item 2 to -1 of tChild & comma after tSynonyms
set the itemDelimiter to comma
end repeat
if tSynonyms is not empty then
delete the last char of tSynonyms
end if
put tSynonyms into tArray["Synonyms"]
local tVersion
set the itemDelimiter to comma
put revXMLAttribute(tTree, "doc/history/introduced", "version") into tVersion
if item 1 of tVersion is "xmlerr" then
put empty into tArray["Version"]
else
put tVersion into tArray["Version"]
end if
put revDocumentationVersionDate(tArray["Version"]) into tArray["Date"]
put empty into tArray["Notes"]
local tLibrary
put revXMLNodeContents(tTree, "doc/library") into tLibrary
if item 1 of tLibrary is "xmlerr" then
put empty into tArray["Library"]
else
put tLibrary into tArray["Library"]
end if
local tObjects
put revXMLChildNames(tTree,"doc/objects",return,,false) into tObjects
repeat for each word tObject in "Button Field Graphic Scrollbar Image Player Card Stack Group"
if lower (tObject) is among the lines of tObjects or tObjects is "any object" then
put merge("<img src=[[quote]]201233[[quote]] />") into tArray[tObject]
else
put empty into tArray[tObject]
end if
end repeat
local tClass, tLine
put revXMLChildNames(tTree,"doc/classes",return,,false) into tClass
put empty into tArray["Platforms"]
if "desktop" is among the lines of tClass then
put "Desktop, " after tArray["Platforms"]
end if
if "server" is among the lines of tClass then
put "Server, " after tArray["Platforms"]
end if
if "web" is among the lines of tClass then
put "Web, " after tArray["Platforms"]
end if
if "mobile" is among the lines of tClass then
put "Mobile, " after tArray["Platforms"]
end if
if tArray["Platforms"] is not empty then
put item 1 to -2 of tArray["Platforms"] into tArray["Platforms"]
else
//put "" into tArray["Platforms"]
put "Desktop, Server, Web, Mobile" into tArray["Platforms"]
end if
local tSecurity
put revXMLChildNames(tTree,"doc/security",return,,false) into tSecurity
put empty into tArray["Security"]
local tCapitalEntry
repeat for each line tLine in tSecurity
put tLine into tCapitalEntry
put toUpper (character 1 of tCapitalEntry) into character 1 of tCapitalEntry
put tArray["Security"] & tCapitalEntry & comma & space into tArray["Security"]
end repeat
if tArray["Security"] is not empty then
put item 1 to -2 of tArray["Security"] into tArray["Security"]
else
put "None required" into tArray["Security"]
end if
// We are not supporting Products anymore
put "" into tArray["Products"]
local tPlatforms
put extractPlatformInformation(tTree) into tPlatforms
//HSC-ND put tPlatforms into tArray["Platforms"]
put tPlatforms into tArray["Operating Systems"]
revDeleteXMLTree tTree
return tArray
end indexLine
function indexGlossaryLine pDoc, pIndex
local tFilename
set the itemDelimiter to slash
put item -1 of pDoc into tFilename
local tData
put url ("file:" & pDoc) into tData
local tTree
put revCreateXMLTree(tData, false, true, false) into tTree
if tTree is not a number then
errorShow "Could not parse the glossary file: " & pDoc & " with error: " & tTree
exit indexGlossaryLine
end if
local tName, tCategory
put revXMLNodeContents(tTree, "doc/term") into tName
put revXMLNodeContents(tTree, "doc/categories/category") into tCategory
if item 1 of tName is "xmlerr" then
errorShow "Could not extract name from the glossary file : " & pDoc & " with error: " & tName
exit indexGlossaryLine
end if
if item 1 of tCategory is "xmlerr" then
errorShow "Could not extract category from the glossary file : " & pDoc & " with error: " & tCategory
exit indexGlossaryLine
end if
local tLine
put pIndex & tab & tName & tab & tCategory into tLine
return tLine
end indexGlossaryLine
private function extractPlatformInformation pTree, pMetadata
local tPlatforms
# Information about the 4 desktop platforms is already contained in each document,
# first extract this.
//if revXMLAttribute(pTree, "doc/platforms", "mac/") then
//put "MacOS," after tPlatforms
//end if
local tChildNames
put revXMLChildNames(pTree,"doc/platforms",return,,false) into tChildNames
if "mac" is among the lines of tChildNames then
put "Mac OS X," after tPlatforms
end if
if "windows" is among the lines of tChildNames then
put "Windows," after tPlatforms
end if
if "linux" is among the lines of tChildNames then
put "Linux," after tPlatforms
end if
if "ios" is among the lines of tChildNames then
put "iOS," after tPlatforms
end if
if "android" is among the lines of tChildNames then
put "Android," after tPlatforms
end if
delete the last char of tPlatforms
--delete the last char of tPlatforms
return tPlatforms
end extractPlatformInformation
private function extractNodeXML pTree, pName
local tXML
put revXMLText(pTree, pName, false) into tXML
if item 1 of tXML is "xmlerr" then
return tXML
end if
# Chop off the "<pName>" at the start as we don't want this and also the "</pName>" at the end
local tName
set the itemDelimiter to slash
put item -1 of pName into tName
set the itemDelimiter to comma
delete char 1 to (the length of tName + 2) of tXML
delete char -(the length of tName + 3) to -1 of tXML
return tXML
end extractNodeXML
private function auxFormatSyntax pSyntax
local tSyntax, tOffset
local tReduced = "false"
put pSyntax into tSyntax
if the number of lines of tSyntax > 1 then
put true into tReduced
put line 1 of tSyntax into tSyntax
end if
if the last char of tSyntax is return then delete the last char of tSyntax
put offset("</p>",tSyntax) into tOffset
if tOffset <> 0 then add 4 to tOffset
if (tOffset <> 0) and (tOffset < the length of tSyntax) then
put char 1 to tOffset - 5 of tSyntax & "</p>" into tSyntax
put true into tReduced
end if
replace "<p>" with empty in tSyntax
replace "</p>" with empty in tSyntax
replace tab with space in tSyntax
if tReduced then put " ..." after tSyntax
-- Remove all style tags. This is a workaround for the tabstops bug
-- remove this line to allow the original style information for syntax
-- to reappear in the dictionary.
put replaceText(tSyntax, "(<[/a-zA-Z0-9]+>)", "") into tSyntax
return tSyntax
end auxFormatSyntax
private function escapeEntities pText
replace "&" with "&" in pText
replace quote with """ in pText
replace "<" with "<" in pText
replace ">" with ">" in pText
return pText
end escapeEntities
// HSC - tested - complies with current dictionary format
private command libDocumentationClumpCreate pNumber, pDir
local tClumpName
---------
put kClumpNamePrefix & pNumber into tClumpName
local tResult
create invisible stack tClumpName
save it as pDir & slash & tClumpName & ".rev"
put the result into tResult
if tResult is not empty then
errorShow "Failed to save file to disk at location: " & pDir & slash & tClumpName & ".rev" & " with result: " & tResult
exit libDocumentationClumpCreate
end if
return tClumpName