-
Notifications
You must be signed in to change notification settings - Fork 6
/
luapower_website.lua
1760 lines (1591 loc) · 47.3 KB
/
luapower_website.lua
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
--main entry point for all URIs that are not static files.
--dispatches URIs to individual actions.
require'webb'
local ffi = require'ffi'
local lp = require'luapower'
local fs = require'fs'
local tuple = require'tuple'
lp.luapower_dir = config('luapower_dir', '.')
lp.persistent_cache = config('luapower_persistent_cache', false)
--in our current setup, the dependency db must be updated manually.
lp.auto_update_db = config('luapower_allow_update_db_locally', false)
lp.allow_update_db_locally = config('luapower_allow_update_db_locally', false)
local pandoc_cmd = 'bin/'..lp.current_platform()..'/pandoc'
if ffi.abi'win' then pandoc_cmd = pandoc_cmd:gsub('/', '\\') end
local action = {} --{name->handler}
--helpers --------------------------------------------------------------------
--filesystem
local function older(file1, file2)
local mtime1 = fs.attr(file1, 'mtime')
local mtime2 = fs.attr(file2, 'mtime')
if not mtime1 then return true end
if not mtime2 then return false end
return mtime1 < mtime2
end
local function escape_filename(s)
return (s:gsub('[/\\%?%%%*%:|"<> ]', '-'))
end
local function render_main(name, data)
template.content = template(name)
local html = render('main',
glue.merge({
grep_enabled = true,
}, data)
)
template.content = nil
return html
end
--date/time formatting
local function rel_time(s)
if s > 2 * 365 * 24 * 3600 then
return ('%d years'):format(math.floor(s / (365 * 24 * 3600)))
elseif s > 2 * 30.5 * 24 * 3600 then
return ('%d months'):format(math.floor(s / (30.5 * 24 * 3600)))
elseif s > 1.5 * 24 * 3600 then
return ('%d days'):format(math.floor(s / (24 * 3600)))
elseif s > 2 * 3600 then
return ('%d hours'):format(math.floor(s / 3600))
elseif s > 2 * 60 then
return ('%d minutes'):format(math.floor(s / 60))
else
return 'a minute'
end
end
local function timeago(time)
local s = os.difftime(os.time(), time)
return string.format(s > 0 and '%s ago' or 'in %s', rel_time(math.abs(s)))
end
local function format_time(time)
return time and os.date('%b %m \'%y %H:%M', time) or ''
end
local function format_date(time)
return time and os.date('%b %m \'%y', time) or ''
end
--widgets --------------------------------------------------------------------
local widgets = {}
function widgets.module_list(package)
local origin_url = lp.git_origin_url(package)
local t = lp.module_headers(package)
local dt = {}
local function _(...) dt[#dt+1] = string.format(...)..'\n' end
local cat0
_'<table width=100%%>'
for i,t in ipairs(t) do
local path = tostring(lp.modules(package)[t.module])
local docpath = lp.docs(package)[t.module]
local cat = t.name and t.name:match'^(.-)/[^/]+$' or 'other'
if cat ~= cat0 then
_(' <tr><td colspan=2><strong>%s</strong></td>'..
'<td class="gray small" style="vertical-align: bottom">'..
'last updated</td></tr>', cat)
cat0 = cat
end
local mtime = lp.git_file_time(package, path)
if mtime then
t.mtime = format_date(mtime)
t.mtime_ago = timeago(mtime)
end
local tagline = lp.module_tagline(package, t.module)
local doclink = docpath and
string.format(' [<a href="/%s">doc</a>]', t.module) or ''
_' <tr>'
_ ' <td class=nowrap>'
_(' <a href="%s/blob/master/%s?ts=3">%s</a>%s',
origin_url, path, t.module, doclink)
_ ' </td><td>'
_(' %s', tagline or '')
_ ' </td><td class=nowrap>'
_(' <span class=time time="%s" reltime="%s">%s</span>',
t.mtime, t.mtime_ago, t.mtime_ago)
_ ' </td>'
_' </tr>'
end
_'</table>'
return table.concat(dt)
end
--doc rendering --------------------------------------------------------------
local function md_refs()
local t = {}
local refs = {}
local function addref(s)
if refs[s] then return end
table.insert(t, string.format('[%s]: /%s', s, s))
refs[s] = true
end
--add refs in the order in which uris are dispatched.
for pkg in pairs(lp.installed_packages()) do
addref(pkg)
end
for doc in pairs(lp.docs()) do
addref(doc)
end
for file in fs.dir(wwwpath'md') do
if file:find'%.md$' then
addref(file:match'^(.-)%.md$')
end
end
table.insert(t, assert(glue.readfile(wwwpath'ext-links.md')))
return table.concat(t, '\n')
end
local function render_docfile(infile)
local outfile = config('www_dir')..'/.cache/'..escape_filename(infile)..'.html'
if older(outfile, infile) then
local s1 = glue.readfile(infile)
local s2 = md_refs()
local tmpfile = os.tmpname()
assert(glue.writefile(tmpfile, s1..'\n\n'..s2))
local cmd = pandoc_cmd..' --tab-stop=3 -r markdown+definition_lists -w html '..
tmpfile..' > '..outfile
os.execute(cmd)
os.remove(tmpfile)
end
return assert(glue.readfile(outfile))
end
local function render_docheader(pkg, mod, h)
if not h.doc then return end
local url = lp.git_origin_url(pkg)
local path = tostring(lp.modules(pkg)[mod])
return '<pre>'..h.doc..'</pre><p> See the '..
string.format('<a href="%s/blob/master/%s?ts=3">source code</a>', url, path)
..' for more info.</p>'
end
local function www_docfile(doc)
local docfile = wwwpath('md/'..doc..'.md')
if not fs.is(docfile) then return end
return docfile
end
local function action_docfile(doc)
local t = {}
local docfile = www_docfile(doc)
t.doc_html = render_docfile(docfile)
local dtags = lp.docfile_tags(docfile)
t.title = dtags.title
t.tagline = dtags.tagline
local mtime = fs.attr(docfile, 'mtime')
t.doc_mtime = format_date(mtime)
t.doc_mtime_ago = mtime and timeago(mtime)
t.edit_link = string.format('https://github.com/luapower/website/edit/master/luapower-www/md/%s.md', doc)
t.docs = {}
for file in fs.dir(wwwpath'md') do
if not file then break end
local name = file:match'(.-)%.md$'
if name then
table.insert(t.docs, {
shortname = name,
name = name,
source_url = string.format('https://github.com/luapower/website/blob/master/luapower-www/md/%s.md?ts=3', doc),
selected = name == doc,
})
end
end
table.sort(t.docs, function(a, b) return a.name < b.name end)
setmime'html'
out(render_main('doc', t))
end
--package info ---------------------------------------------------------------
local ljsrc = 'https://github.com/LuaJIT/LuaJIT/blob/master/src/'
local module_src_urls = {
string = ljsrc..'lib_string.c',
table = ljsrc..'lib_table.c',
coroutine = ljsrc..'lib_base.c',
package = ljsrc..'lib_package.c',
io = ljsrc..'lib_io.c',
math = ljsrc..'lib_math.c',
os = ljsrc..'lib_os.c',
_G = ljsrc..'lib_base.c',
debug = ljsrc..'lib_debug.c',
ffi = ljsrc..'lib_ffi.c',
bit = ljsrc..'lib_bit.c',
jit = ljsrc..'lib_jit.c',
['jit.util'] = ljsrc..'lib_jit.c',
['jit.profile'] = ljsrc..'lib_jit.c',
}
local function source_url(pkg, path, mod)
local url = module_src_urls[mod]
if url then return url end
if type(path) ~= 'string' then return end
local url = lp.git_origin_url(pkg)
if url:find'github%.com' then
return string.format('%s/blob/master/%s?ts=3', url, path)
else
--NOTE: we don't have non-github browsable URLs yet,
--so this is just a placeholder for now.
return string.format('%s/master/%s', url, path)
end
end
local os_list = lp.supported_os_list
local os_platform_list = lp.supported_os_platform_list
local platform_list = lp.supported_platform_list
--create a custom-ordered list of possible platforms.
local ext_platform_list = {'all', 'common'}
for _,os in ipairs(os_list) do
table.insert(ext_platform_list, os)
glue.extend(ext_platform_list, os_platform_list[os])
end
local platform_icon_titles = {
mingw = 'Windows',
mingw64 = '64bit Windows',
linux = 'Linux',
linux64 = '64bit Linux',
osx = 'OS X',
osx64 = '64bit OS X',
}
--platform icons, in order, given a map of supported platforms. vis_only
--controls whether a missing platform show as disabled or not included at all.
--if both 32bit and 64bit platforms of the same OS are supported,
--the result is a single OS icon without the 32/64 label.
local function platform_icons(platforms, vis_only)
local t = {}
for _,p in ipairs(platform_list) do
if not vis_only or platforms[p] then
table.insert(t, {
name = p,
disabled = not platforms[p] and 'disabled' or nil,
})
end
end
--combine 32bit and 64bit icon pairs into OS icons
local i = 1
while i < #t do
if t[i].name:match'^[^%d]+' == t[i+1].name:match'^[^%d]+' then
if t[i].disabled == t[i+1].disabled then
t[i].name = t[i].name:match'^([^%d]+)'
else
t[i].name = t[i].disabled and t[i+1].name or t[i].name
t[i].disabled = nil
end
table.remove(t, i+1)
end
i = i + 1
end
--set the icon title
for i,pt in ipairs(t) do
pt.title = (pt.disabled and 'doesn\'t work on ' or 'works on ')..
platform_icon_titles[pt.name]
end
return t
end
--given {place1 = {item1 = val1, ...}, ...}, extract items that are
--found in all places into the place indicated by all_key.
local function extract_common_keys(maps, all_key)
--count occurences for each item
local maxn = glue.count(maps)
--if less than two places to group, don't group
if maxn < 2 then return maps end
local nt = {} --{item = n}
local tt = {} --{item = val}
for place, items in pairs(maps) do
for item, val in pairs(items) do
nt[item] = (nt[item] or 0) + 1
--val of 'all' is the val of the first item.
tt[item] = tt[item] or val
end
end
--extract items found in all places
local all = {}
for item, n in pairs(nt) do
if n == maxn then
all[item] = tt[item]
end
end
--add items not found in all places, to their original places
local t = {[all_key] = next(all) and all}
for place, items in pairs(maps) do
for item, val in pairs(items) do
if all[item] == nil then
glue.attr(t, place)[item] = val
end
end
end
return t
end
--same as above, but use an "all-or-nothing strategy" of extraction
local function extract_common_keys_aot(maps, all_key)
--count occurences for each item
local maxn = glue.count(maps)
--if less than two places to group, don't group
if maxn < 2 then return maps end
local nt = {} --{item = n}
local tt = {} --{item = val}
for place, items in pairs(maps) do
for item, val in pairs(items) do
nt[item] = (nt[item] or 0) + 1
--val of 'all' is the val of the first item.
tt[item] = tt[item] or val
end
end
--check to see if all items were extracted
local all_extracted = true
for item, n in pairs(nt) do
if n < maxn then
all_extracted = false
end
end
return all_extracted and {[all_key] = tt} or maps
end
--given {platform1 = {item1 = val1, ...}, ...}, group items that are
--common to the same OS into OS keys, and all-around common items
--into the all_key key, if given.
local function platform_maps(maps, all_key, aot)
local extract = aot and extract_common_keys_aot or extract_common_keys
--extract common items across all places, if all_key given
maps = all_key and extract(maps, all_key) or glue.update({}, maps)
--combine platforms per OS
for _,os in ipairs(os_list) do
local t = {}
for _,platform in ipairs(os_platform_list[os]) do
t[platform] = maps[platform]
maps[platform] = nil
end
glue.update(maps, extract(t, os))
end
return maps
end
--return the identifying icons for a package and a sorting string
local function package_icons(ptype, platforms, small)
local has_lua = ptype:find'Lua'
local has_ffi = ptype:find'ffi'
local t = {}
if ptype == 'Terra' then
table.insert(t, {
name = 'terra',
title = 'written in Terra',
})
elseif ptype == 'Resty' then
table.insert(t, {
name = 'resty',
title = 'written in Lua for OpenResty',
})
elseif has_ffi then
table.insert(t, {
name = 'luajit',
title = 'written in Lua with ffi extension',
})
elseif has_lua then
table.insert(t, {
name = small and 'luas' or 'lua',
title = 'written in Lua',
})
else
table.insert(t, {
name = small and 'luas' or 'lua',
title = ptype .. ' package',
invisible = 'invisible',
})
end
--add platform icons
if next(platforms) then --don't show platform icons for Lua modules
glue.extend(t, platform_icons(platforms))
end
--create a "sorting string" that sorts the packages by platform support
local st = {}
local pt = glue.keys(platforms, true)
table.insert(st, tostring(((has_lua or has_ffi) and #pt == 0)
and 100 or #pt)) --portable vs cross-platform
--Lua vs Lua+ffi vs others
table.insert(st, has_ffi and 1 or has_lua and 2 or 0)
--type, just to sort others predictably too
table.insert(st, ptype)
--platforms, just to group the same combinations together
glue.extend(st, pt)
local ss = table.concat(st, ';')
return t, ss
end
--dependency lists
local function sorted_names(deps) --sort dependency lists by (kind, name)
return glue.keys(deps, function(name1, name2)
local kind1 = deps[name1].kind
local kind2 = deps[name2].kind
if kind1 == kind2 then return name1 < name2 end
return kind1 < kind2
end)
end
local function pdep_list(pdeps) --package dependency list
local packages = {}
local names = sorted_names(pdeps)
for _,pkg in ipairs(names) do
local pdep = pdeps[pkg]
table.insert(packages, glue.update({
dep_package = pkg,
external = pdep and pdep.kind == 'external',
}, pdep))
end
return packages
end
local function mdep_list(mdeps) --module dependency list
local modules = {}
local names = sorted_names(mdeps)
for _,mod in ipairs(names) do
local mt = mdeps[mod]
table.insert(modules, glue.update({
dep_module = mod,
}, mt))
end
return modules
end
local function packages_of(dep_func, mod, pkg, platform)
local t = {}
for mod in pairs(dep_func(mod, pkg, platform)) do
local dpkg = lp.module_package(mod)
if dpkg and dpkg ~= pkg then --exclude self
t[dpkg] = true
end
end
return t
end
local function packages_of_many(dep_func, mod, pkg, platform)
local t = {}
for mod in pairs(mod) do
glue.update(t, packages_of(dep_func, mod, pkg, platform))
end
return t
end
local function packages_of_all(dep_func, _, pkg, platform)
return packages_of_many(dep_func, lp.modules(pkg), pkg, platform)
end
local function package_dep_maps(pkg, platforms)
local pts = {}
for platform in pairs(platforms) do
local pt = {}
pts[platform] = pt
local pext = packages_of_all(lp.module_requires_loadtime_ext,
nil, pkg, platform)
local pall = packages_of_all(lp.module_requires_loadtime_all,
nil, pkg, platform)
local penv = packages_of_all(lp.module_environment,
nil, pkg, platform)
glue.update(pext, lp.bin_deps(pkg, platform))
glue.update(pall, lp.bin_deps_all(pkg, platform))
glue.update(pall, penv)
for p in pairs(pall) do
pt[p] = {kind = pext[p] and 'external' or penv[p] and 'environment' or 'indirect'}
end
end
return pts
end
local function package_bin_dep_maps(pkg, platforms)
local pts = {}
for platform in pairs(platforms) do
local pt = {}
pts[platform] = pt
local pext = lp.bin_deps(pkg, platform)
local pall = lp.bin_deps_all(pkg, platform)
for p in pairs(pall) do
pt[p] = {kind = pext[p] and 'external' or 'indirect'}
end
end
return pts
end
local function package_rev_dep_maps(pkg, platforms)
local pts = {}
for platform in pairs(platforms) do
local pt = {}
pts[platform] = pt
local pext = packages_of_all(
lp.module_required_loadtime, nil, pkg, platform)
local pall = packages_of_all(
lp.module_required_loadtime_all, nil, pkg, platform)
glue.update(pext, lp.rev_bin_deps(pkg, platform))
glue.update(pall, lp.rev_bin_deps_all(pkg, platform))
for p in pairs(pall) do
pt[p] = {kind = pext[p] and 'external' or 'indirect'}
end
end
return pts
end
local function filter(t1, t2)
local dt = {}
for k, v in pairs(t1) do
if t2[k] then
dt[k] = v
end
end
return dt
end
local function module_package_dep_maps(pkg, mod, platforms)
local pts = {}
for platform in pairs(platforms) do
local pext = packages_of(
lp.module_requires_loadtime_ext, mod, pkg, platform)
local pall = packages_of(
lp.module_requires_loadtime_all, mod, pkg, platform)
local penv = packages_of(
lp.module_environment, mod, pkg, platform)
glue.update(pext, filter(lp.bin_deps(pkg, platform),
lp.module_platforms(mod, pkg)))
glue.update(pall, filter(lp.bin_deps_all(pkg, platform),
lp.module_platforms(mod, pkg)))
glue.update(pall, penv)
local pt = {}
for p in pairs(pall) do
pt[p] = {kind = pext[p] and 'direct' or penv[p] and 'environment' or 'indirect'}
end
pts[platform] = pt
end
return pts
end
local function module_runtime_package_dep_maps(pkg, mod, platforms)
local pts = {}
for platform in pairs(platforms) do
local pdeps = packages_of(
lp.module_requires_runtime, mod, pkg, platform)
local pt = {}
for p in pairs(pdeps) do
pt[p] = {kind = 'direct'}
end
pts[platform] = pt
end
return pts
end
local function module_module_dep_maps(pkg, mod, platforms)
local mts = {}
local mint = lp.modules(pkg)
for platform in pairs(platforms) do
local mext = lp.module_requires_loadtime_ext(mod, pkg, platform)
local mall = lp.module_requires_loadtime_all(mod, pkg, platform)
local menv = lp.module_environment(mod, pkg, platform)
glue.update(mall, menv)
local mt = {}
for m in pairs(mall) do
local pkg = lp.module_package(m)
local path = lp.modules(pkg)[m]
mt[m] = {
kind = mext[m] and 'external'
or mint[m] and 'internal' or menv[m] and 'environment' or 'indirect',
dep_package = pkg,
dep_source_url = source_url(pkg, path, m),
}
end
mts[platform] = mt
end
return mts
end
local function module_runtime_module_dep_maps(pkg, mod, platforms)
local mts = {}
local mint = lp.modules(pkg)
for platform in pairs(platforms) do
local mrun = lp.module_requires_runtime(mod, pkg, platform)
local mt = {}
for m in pairs(mrun) do
local pkg = lp.module_package(m)
local path = lp.modules(pkg)[m]
mt[m] = {
kind = 'external',
dep_package = pkg,
dep_source_url = source_url(pkg, path, m),
}
end
mts[platform] = mt
end
return mts
end
local function package_dep_lists(pdeps)
local t = {}
for _,platform in ipairs(ext_platform_list) do
local pdeps = pdeps[platform]
if pdeps then
local icon =
platform ~= 'all'
and platform ~= 'common'
and platform or nil
local text = not icon and platform or nil
table.insert(t, {
icon = icon,
text = text,
packages = pdep_list(pdeps),
})
end
end
return t
end
local function module_dep_lists(mdeps)
local t = {}
for _,platform in ipairs(ext_platform_list) do
local mdeps = mdeps[platform]
if mdeps then
local icon =
platform ~= 'all'
and platform ~= 'common'
and platform or nil
local text = not icon and platform or nil
table.insert(t, {
icon = icon,
text = text,
modules = mdep_list(mdeps),
})
end
end
return t
end
local function package_dep_matrix(pdeps)
local names = {}
local icons = {}
local depmat = {}
for _,platform in ipairs(ext_platform_list) do
local pmap = pdeps[platform]
if pmap then
table.insert(icons, platform)
for pkg in pairs(pmap) do
names[pkg] = true
end
end
end
local depmat_names = glue.keys(names, true)
for i, icon in ipairs(icons) do
depmat[i] = {
pkg = {},
text = icon == 'all' and icon or nil,
icon = icon ~= 'all' and icon or nil,
}
for j, pkg in ipairs(depmat_names) do
local pt = pdeps[icon][pkg]
depmat[i].pkg[j] = {
checked = pt ~= nil,
kind = pt and pt.kind,
}
end
end
return depmat, depmat_names
end
local function package_note(pkg, note)
--nothing to say.
end
local function package_info(pkg, doc)
local t = {package = pkg}
--gather info
local package_type = lp.package_type(pkg)
local platforms = lp.platforms(pkg)
local all_platforms =
next(platforms)
and platforms
or glue.update({}, lp.supported_platforms)
local master_time = lp.git_master_time(pkg)
local author = lp.author(pkg)
local license = lp.license(pkg)
local ctags = lp.what_tags(pkg) or {}
local origin_url = lp.git_origin_url(pkg)
local on_github = origin_url:find'github%.com'
local git_version = lp.git_version(pkg)
local git_tag = lp.git_tag(pkg)
local released =
git_tag
and git_tag ~= ''
and git_tag ~= 'dev' --tag "dev" is not a release
local git_tags = lp.git_tags(pkg)
local doc = doc or pkg
local docs = lp.docs(pkg)
local docheaders = lp.docheaders(pkg)
local doc_path = docs[doc]
if not doc_path and glue.count(docs) == 1 then
doc = next(docs)
doc_path = docs[doc]
end
local title = doc
local tagline = lp.module_tagline(pkg, doc)
if doc_path then
local dtags = lp.doc_tags(pkg, doc)
title = dtags.title
end
local package_cat = lp.package_cat(pkg)
--top bar / github url
t.origin_url = origin_url
t.github_url = on_github and origin_url
t.github_title = on_github and origin_url:gsub('^https://', '')
--download / "Changes since..."
t.git_tag = git_tag
t.changes_url = released and on_github and
string.format('%s/compare/%s...master', origin_url, git_tag)
--download / releases
t.git_tags = {}
if released then
for i,tag in ipairs(git_tags) do
if tag == 'dev' then
table.remove(git_tags, i)
break
end
end
for i=#git_tags,1,-1 do
local tag = git_tags[i]
local prevtag = git_tags[i-1]
local mtime = lp.git_tag_time(pkg, tag)
table.insert(t.git_tags, {
tag = tag,
time = format_date(mtime),
reltime = timeago(mtime),
changes_text = prevtag and 'Changes...' or 'Files...',
changes_url = on_github and (prevtag
and string.format('%s/compare/%s...%s',
origin_url, prevtag, tag)
or string.format('%s/tree/%s', origin_url, tag)),
})
end
end
t.has_git_tags = #t.git_tags > 0
--package info / overview / supported platorms
t.platforms = {}
for i,p in ipairs(platform_list) do
if platforms[p] then
table.insert(t.platforms, {icon = p})
end
end
if not next(t.platforms) then
local runtime = package_type == 'Lua+ffi' and 'LuaJIT' or package_type
table.insert(t.platforms,
{name = runtime and 'all '..runtime..' platforms'})
end
--package info / docs
--menubar / doc list
t.docs = {}
for name, path in glue.sortedpairs(docs) do
table.insert(t.docs, {
shortname = name:gsub('^'..glue.esc(pkg)..'[%._]', ''),
name = name,
path = path,
source_url = source_url(pkg, path),
selected = name == doc,
})
end
--package info / docheaders
for name, h in glue.sortedpairs(docheaders) do
if h.doc then
table.insert(t.docs, {
name = name,
shortname = name:gsub('^'..glue.esc(pkg)..'[%._]', ''),
path = name,
selected = name == doc,
})
end
end
t.has_docs = #t.docs > 0
--doc page
t.title = title or doc
t.doc_path = doc_path
t.tagline = tagline
t.edit_link =
on_github
and doc_path
and origin_url..'/edit/master/'..doc_path
--sidebar
t.icons = package_icons(package_type, platforms)
t.type = package_type
t.version = git_version
t.mtime = format_time(master_time)
t.mtime_ago = timeago(master_time)
t.author = author
t.license = license
t.c_name =
ctags.realname
and ctags.realname ~= pkg
and ctags.realname
or nil
t.c_version = ctags.version
t.c_url = ctags.url
--menubar / other packages in cat
t.cats = {}
for i,cat in ipairs(lp.cats()) do
if cat.name == package_cat then
local ct = {name = cat.name}
table.insert(t.cats, ct)
ct.packages = {}
for i, package in ipairs(cat.packages) do
table.insert(ct.packages, {
package = package.name,
selected = package.name == pkg,
note = package_note(package.name, package.note),
})
end
end
end
--package dependencies ----------------------------------------------------
--combined package dependencies
local pts = package_dep_maps(pkg, all_platforms)
local pdeps = platform_maps(pts, 'common')
t.package_deps = package_dep_lists(pdeps)
t.has_package_deps = #t.package_deps > 0
--combined package dependency matrix
local pdeps_aot = platform_maps(pts, 'all', 'aot')
t.depmat, t.depmat_names = package_dep_matrix(pdeps_aot)
--package clone lists
if not pdeps_aot.all then --make a combined list for all platforms
local all = {}
for platform, pts in pairs(pdeps_aot) do
for package in pairs(pts) do
all[package] = {}
end
end
pdeps_aot.all = all
end
t.clone_lists = {}
for _,platform in ipairs(ext_platform_list) do
local pdeps = pdeps_aot[platform]
if pdeps then
local packages = {{dep_package = pkg}}
local pdeps = pdep_list(pdeps)
glue.extend(packages, pdeps)
table.insert(t.clone_lists, {
platform = platform,
text = platform == 'all' and platform or nil,
icon = platform ~= 'all' and platform or nil,
is_unix = not platform:find'mingw',
hidden = platform ~= 'all' and 'hidden' or nil,
disabled = platform ~= 'all' and 'disabled' or nil,
packages = packages,
})
end
end
--combined package reverse dependencies
local pts = package_rev_dep_maps(pkg, all_platforms)
local rpdeps = platform_maps(pts, 'common')
t.package_rdeps = package_dep_lists(rpdeps)
t.has_package_rdeps = #t.package_rdeps > 0
--binary dependencies
local pts = package_bin_dep_maps(pkg, all_platforms)
local pdeps = platform_maps(pts, 'common')
t.bin_deps = package_dep_lists(pdeps)
t.has_bin_deps = #t.bin_deps > 0
--build order
local pts = {}
for platform in pairs(all_platforms) do
local bo = lp.build_order(pkg, platform)
pts[platform] = {[tuple(unpack(bo))] = bo}
end
local bo = platform_maps(pts, 'all', 'aot')
t.build_order = {}
for _,platform in ipairs(ext_platform_list) do
local bo = bo[platform]
if bo then
table.insert(t.build_order, {
icon = platform ~= 'all' and platform,
text = platform == 'all' and 'all',
packages = {next(bo)()},
})
end
end
--module list -------------------------------------------------------------
t.modules = {}
for mod, path in glue.sortedpairs(lp.modules(pkg)) do
local mt = {module = mod}
table.insert(t.modules, mt)
local mtags = lp.module_tags(pkg, mod)
mt.lang = mtags.lang
if type(path) == 'table' then
mt.source_urls = {}
for plat, path in pairs(path) do
table.insert(mt.source_urls, {
platform = plat,
source_url = source_url(pkg, path, mod),
})
end
else
mt.source_url = source_url(pkg, path, mod)
end
local mplatforms = lp.module_platforms(mod, pkg)
mt.icons = {}
if tuple(unpack(glue.keys(mplatforms, true))) ~=
tuple(unpack(glue.keys(all_platforms, true)))
then
mt.icons = platform_icons(mplatforms, true)
end
--loadtime package deps
local pts = module_package_dep_maps(pkg, mod, all_platforms)
local pdeps = platform_maps(pts, 'all')
mt.package_deps = package_dep_lists(pdeps)
--loadtime module deps
local mts = module_module_dep_maps(pkg, mod, all_platforms)
local mdeps = platform_maps(mts, 'all')
mt.module_deps = module_dep_lists(mdeps)
--runtime package deps
local pts = module_runtime_package_dep_maps(pkg, mod, all_platforms)
local pdeps = platform_maps(pts, 'all')
mt.runtime_package_deps = package_dep_lists(pdeps)
mt.module_has_runtime_deps = #mt.runtime_package_deps > 0
t.has_runtime_deps = t.has_runtime_deps or mt.module_has_runtime_deps