nitcatalog: new package metadata `upstream.tryit`
[nit.git] / src / nitcatalog.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Basic catalog generator for Nit packages
16 #
17 # See: <http://nitlanguage.org/catalog/>
18 #
19 # The tool scans packages and generates the HTML files of a catalog.
20 #
21 # ## Features
22 #
23 # * [X] scan packages and their `.ini`
24 # * [X] generate lists of packages
25 # * [X] generate a page per package with the readme and most metadata
26 # * [ ] link/include/be included in the documentation
27 # * [ ] propose `related packages`
28 # * [X] show directory content (a la nitls)
29 # * [X] gather git information from the working directory
30 # * [ ] gather git information from the repository
31 # * [ ] gather package information from github
32 # * [ ] gather people information from github
33 # * [ ] reify people
34 # * [ ] separate information gathering from rendering
35 # * [ ] move up information gathering in (existing or new) service modules
36 # * [X] add command line options
37 # * [ ] harden HTML (escaping, path injection, etc)
38 # * [ ] nitcorn server with RESTful API
39 #
40 # ## Issues and limitations
41 #
42 # The tool works likee the other tools and expects to find valid Nit source code in the directories
43 #
44 # * cruft and temporary files will be collected
45 # * missing source file (e.g. not yet generated by nitcc) will make information
46 # incomplete (e.g. invalid module thus partial dependency and metrics)
47 #
48 # How to use the tool as the basis of a Nit code archive on the web usable with a package manager is not clear.
49 module nitcatalog
50
51 import loader # Scan&load packages, groups and modules
52 import doc::doc_down # Display mdoc
53 import md5 # To get gravatar images
54 import counter # For statistics
55 import modelize # To process and count classes and methods
56
57 redef class MPackage
58 # Return the associated metadata from the `ini`, if any
59 fun metadata(key: String): nullable String
60 do
61 var ini = self.ini
62 if ini == null then return null
63 return ini[key]
64 end
65
66 # The list of maintainers
67 var maintainers = new Array[String]
68
69 # The list of contributors
70 var contributors = new Array[String]
71
72 # The date of the most recent commit
73 var last_date: nullable String = null
74
75 # The date of the oldest commit
76 var first_date: nullable String = null
77 end
78
79 # A HTML page in a catalog
80 #
81 # This is just a template with the header pre-filled and the footer injected at rendering.
82 # Therefore, once instantiated, the content can just be added to it.
83 class CatalogPage
84 super Template
85
86 # Placeholder to include additional things before the `</head>`.
87 var more_head = new Template
88
89 # Relative path to the root directory (with the index file).
90 #
91 # Use "" for pages in the root directory
92 # Use ".." for pages in a subdirectory
93 var rootpath: String
94
95 redef init
96 do
97 add """
98 <!DOCTYPE html>
99 <html>
100 <head>
101 <meta charset="utf-8">
102 <link rel="stylesheet" media="all" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
103 <link rel="stylesheet" media="all" href="{{{rootpath / "style.css"}}}">
104 """
105 add more_head
106
107 add """
108 </head>
109 <body>
110 <div class='container-fluid'>
111 <div class='row'>
112 <nav id='topmenu' class='navbar navbar-default navbar-fixed-top' role='navigation'>
113 <div class='container-fluid'>
114 <div class='navbar-header'>
115 <button type='button' class='navbar-toggle' data-toggle='collapse' data-target='#topmenu-collapse'>
116 <span class='sr-only'>Toggle menu</span>
117 <span class='icon-bar'></span>
118 <span class='icon-bar'></span>
119 <span class='icon-bar'></span>
120 </button>
121 <span class='navbar-brand'><a href="http://nitlanguage.org/">Nitlanguage.org</a></span>
122 </div>
123 <div class='collapse navbar-collapse' id='topmenu-collapse'>
124 <ul class='nav navbar-nav'>
125 <li><a href="{{{rootpath / "index.html"}}}">Catalog</a></li>
126 </ul>
127 </div>
128 </div>
129 </nav>
130 </div>
131 """
132 end
133
134 redef fun rendering
135 do
136 add """
137 </div> <!-- container-fluid -->
138 <script src='https://code.jquery.com/jquery-latest.min.js'></script>
139 <script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js'></script>
140 <script src='https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.8.1/bootstrap-table-all.min.js'></script>
141 </body>
142 </html>
143 """
144 end
145 end
146
147 redef class Int
148 # Returns `log(self+1)`. Used to compute score of packages
149 fun score: Float do return (self+1).to_f.log
150 end
151
152 # The main class of the calatog generator that has the knowledge
153 class Catalog
154
155 # The modelbuilder
156 # used to access the files and count source lines of code
157 var modelbuilder: ModelBuilder
158
159 # Packages by tag
160 var tag2proj = new MultiHashMap[String, MPackage]
161
162 # Packages by category
163 var cat2proj = new MultiHashMap[String, MPackage]
164
165 # Packages by maintainer
166 var maint2proj = new MultiHashMap[String, MPackage]
167
168 # Packages by contributors
169 var contrib2proj = new MultiHashMap[String, MPackage]
170
171 # Dependency between packages
172 var deps = new POSet[MPackage]
173
174 # Number of modules by package
175 var mmodules = new Counter[MPackage]
176
177 # Number of classes by package
178 var mclasses = new Counter[MPackage]
179
180 # Number of methods by package
181 var mmethods = new Counter[MPackage]
182
183 # Number of line of code by package
184 var loc = new Counter[MPackage]
185
186 # Number of commits by package
187 var commits = new Counter[MPackage]
188
189 # Score by package
190 #
191 # The score is loosely computed using other metrics
192 var score = new Counter[MPackage]
193
194 # Scan, register and add a contributor to a package
195 fun add_contrib(person: String, mpackage: MPackage, res: Template)
196 do
197 var projs = contrib2proj[person]
198 if not projs.has(mpackage) then projs.add mpackage
199 var name = person
200 var email = null
201 var page = null
202
203 # Regular expressions are broken, need to investigate.
204 # So split manually.
205 #
206 #var re = "([^<(]*?)(<([^>]*?)>)?(\\((.*)\\))?".to_re
207 #var m = (person+" ").search(re)
208 #print "{person}: `{m or else "?"}` `{m[1] or else "?"}` `{m[3] or else "?"}` `{m[5] or else "?"}`"
209 do
210 var sp1 = person.split_once_on("<")
211 if sp1.length < 2 then
212 break
213 end
214 var sp2 = sp1.last.split_once_on(">")
215 if sp2.length < 2 then
216 break
217 end
218 name = sp1.first.trim
219 email = sp2.first.trim
220 var sp3 = sp2.last.split_once_on("(")
221 if sp3.length < 2 then
222 break
223 end
224 var sp4 = sp3.last.split_once_on(")")
225 if sp4.length < 2 then
226 break
227 end
228 page = sp4.first.trim
229 end
230
231 var e = name.html_escape
232 res.add "<li>"
233 if page != null then
234 res.add "<a href=\"{page.html_escape}\">"
235 end
236 if email != null then
237 # TODO get more things from github by using the email as a key
238 # "https://api.github.com/search/users?q={email}+in:email"
239 var md5 = email.md5.to_lower
240 res.add "<img src=\"https://secure.gravatar.com/avatar/{md5}?size=20&amp;default=retro\">&nbsp;"
241 end
242 res.add "{e}"
243 if page != null then res.add "</a>"
244 res.add "</li>"
245 end
246
247 # Recursively generate a level in the file tree of the *content* section
248 private fun gen_content_level(ot: OrderedTree[Object], os: Array[Object], res: Template)
249 do
250 res.add "<ul>\n"
251 for o in os do
252 res.add "<li>"
253 if o isa MGroup then
254 var d = ""
255 var mdoc = o.mdoc
256 if mdoc != null then d = ": {mdoc.html_synopsis.write_to_string}"
257 res.add "<strong>{o.name}</strong>{d} ({o.filepath.to_s})"
258 else if o isa ModulePath then
259 var d = ""
260 var m = o.mmodule
261 if m != null then
262 var mdoc = m.mdoc
263 if mdoc != null then d = ": {mdoc.html_synopsis.write_to_string}"
264 end
265 res.add "<strong>{o.name}</strong>{d} ({o.filepath.to_s})"
266 else
267 abort
268 end
269 var subs = ot.sub.get_or_null(o)
270 if subs != null then gen_content_level(ot, subs, res)
271 res.add "</li>\n"
272 end
273 res.add "</ul>\n"
274 end
275
276 # Compute information and generate a full HTML page for a package
277 fun package_page(mpackage: MPackage): Writable
278 do
279 var res = new CatalogPage("..")
280 var score = score[mpackage].to_f
281 var name = mpackage.name.html_escape
282 res.more_head.add """<title>{{{name}}}</title>"""
283
284 res.add """
285 <div class="content">
286 <h1 class="package-name">{{{name}}}</h1>
287 """
288 var mdoc = mpackage.mdoc_or_fallback
289 if mdoc != null then
290 score += 100.0
291 res.add mdoc.html_documentation
292 score += mdoc.content.length.score
293 end
294
295 res.add "<h2>Content</h2>"
296 var ot = new OrderedTree[Object]
297 for g in mpackage.mgroups do
298 var pa = g.parent
299 if g.is_interesting then
300 ot.add(pa, g)
301 pa = g
302 end
303 for mp in g.module_paths do
304 ot.add(pa, mp)
305 end
306 end
307 ot.sort_with(alpha_comparator)
308 gen_content_level(ot, ot.roots, res)
309
310
311 res.add """
312 </div>
313 <div class="sidebar">
314 <ul class="box">
315 """
316 var tryit = mpackage.metadata("upstream.tryit")
317 if tryit != null then
318 score += 1.0
319 var e = tryit.html_escape
320 res.add "<li><a href=\"{e}\">Try<span style=\"color:white\">n</span>it!</a></li>\n"
321 end
322
323 res.add """</ul>\n<ul class="box">\n"""
324
325 var homepage = mpackage.metadata("upstream.homepage")
326 if homepage != null then
327 score += 5.0
328 var e = homepage.html_escape
329 res.add "<li><a href=\"{e}\">{e}</a></li>\n"
330 end
331 var maintainer = mpackage.metadata("package.maintainer")
332 if maintainer != null then
333 score += 5.0
334 add_contrib(maintainer, mpackage, res)
335 mpackage.maintainers.add maintainer
336 var projs = maint2proj[maintainer]
337 if not projs.has(mpackage) then projs.add mpackage
338 end
339 var license = mpackage.metadata("package.license")
340 if license != null then
341 score += 5.0
342 var e = license.html_escape
343 res.add "<li><a href=\"http://opensource.org/licenses/{e}\">{e}</a> license</li>\n"
344 end
345 res.add "</ul>\n"
346
347 res.add "<h3>Source Code</h3>\n<ul class=\"box\">\n"
348 var browse = mpackage.metadata("upstream.browse")
349 if browse != null then
350 score += 5.0
351 var e = browse.html_escape
352 res.add "<li><a href=\"{e}\">{e}</a></li>\n"
353 end
354 var git = mpackage.metadata("upstream.git")
355 if git != null then
356 var e = git.html_escape
357 res.add "<li><tt>{e}</tt></li>\n"
358 end
359 var last_date = mpackage.last_date
360 if last_date != null then
361 var e = last_date.html_escape
362 res.add "<li>most recent commit: {e}</li>\n"
363 end
364 var first_date = mpackage.first_date
365 if first_date != null then
366 var e = first_date.html_escape
367 res.add "<li>oldest commit: {e}</li>\n"
368 end
369 var commits = commits[mpackage]
370 if commits != 0 then
371 res.add "<li>{commits} commits</li>\n"
372 end
373 res.add "</ul>\n"
374
375 res.add "<h3>Tags</h3>\n"
376 var tags = mpackage.metadata("package.tags")
377 var ts = new Array[String]
378 if tags != null then
379 for t in tags.split(",") do
380 t = t.trim
381 if t == "" then continue
382 ts.add t
383 end
384 end
385 if ts.is_empty then ts.add "none"
386 if tryit != null then ts.add "tryit"
387 var ts2 = new Array[String]
388 for t in ts do
389 tag2proj[t].add mpackage
390 t = t.html_escape
391 ts2.add "<a href=\"../index.html#tag_{t}\">{t}</a>"
392 end
393 res.add_list(ts2, ", ", ", ")
394 var cat = ts.first
395 cat2proj[cat].add mpackage
396 score += ts.length.score
397
398 if deps.has(mpackage) then
399 var reqs = deps[mpackage].greaters.to_a
400 reqs.remove(mpackage)
401 alpha_comparator.sort(reqs)
402 res.add "<h3>Requirements</h3>\n"
403 if reqs.is_empty then
404 res.add "none"
405 else
406 var list = new Array[String]
407 for r in reqs do
408 var direct = deps.has_direct_edge(mpackage, r)
409 var s = "<a href=\"{r}.html\">"
410 if direct then s += "<strong>"
411 s += r.to_s
412 if direct then s += "</strong>"
413 s += "</a>"
414 list.add s
415 end
416 res.add_list(list, ", ", " and ")
417 end
418
419 reqs = deps[mpackage].smallers.to_a
420 reqs.remove(mpackage)
421 alpha_comparator.sort(reqs)
422 res.add "<h3>Clients</h3>\n"
423 if reqs.is_empty then
424 res.add "none"
425 else
426 var list = new Array[String]
427 for r in reqs do
428 var direct = deps.has_direct_edge(r, mpackage)
429 var s = "<a href=\"{r}.html\">"
430 if direct then s += "<strong>"
431 s += r.to_s
432 if direct then s += "</strong>"
433 s += "</a>"
434 list.add s
435 end
436 res.add_list(list, ", ", " and ")
437 end
438
439 score += deps[mpackage].greaters.length.score
440 score += deps[mpackage].direct_greaters.length.score
441 score += deps[mpackage].smallers.length.score
442 score += deps[mpackage].direct_smallers.length.score
443 end
444
445 var contributors = mpackage.contributors
446 if not contributors.is_empty then
447 res.add "<h3>Contributors</h3>\n<ul class=\"box\">"
448 for c in contributors do
449 add_contrib(c, mpackage, res)
450 end
451 res.add "</ul>"
452 end
453 score += contributors.length.to_f
454
455 var mmodules = 0
456 var mclasses = 0
457 var mmethods = 0
458 var loc = 0
459 for g in mpackage.mgroups do
460 mmodules += g.module_paths.length
461 for m in g.mmodules do
462 var am = modelbuilder.mmodule2node(m)
463 if am != null then
464 var file = am.location.file
465 if file != null then
466 loc += file.line_starts.length - 1
467 end
468 end
469 for cd in m.mclassdefs do
470 mclasses += 1
471 for pd in cd.mpropdefs do
472 if not pd isa MMethodDef then continue
473 mmethods += 1
474 end
475 end
476 end
477 end
478 self.mmodules[mpackage] = mmodules
479 self.mclasses[mpackage] = mclasses
480 self.mmethods[mpackage] = mmethods
481 self.loc[mpackage] = loc
482
483 #score += mmodules.score
484 score += mclasses.score
485 score += mmethods.score
486 score += loc.score
487
488 res.add """
489 <h3>Stats</h3>
490 <ul class="box">
491 <li>{{{mmodules}}} modules</li>
492 <li>{{{mclasses}}} classes</li>
493 <li>{{{mmethods}}} methods</li>
494 <li>{{{loc}}} lines of code</li>
495 </ul>
496 """
497
498 res.add """
499 </div>
500 """
501 self.score[mpackage] = score.to_i
502
503 return res
504 end
505
506 # Return a short HTML sequence for a package
507 #
508 # Intended to use in lists.
509 fun li_package(p: MPackage): String
510 do
511 var res = ""
512 var f = "p/{p.name}.html"
513 res += "<a href=\"{f}\">{p}</a>"
514 var d = p.mdoc_or_fallback
515 if d != null then res += " - {d.html_synopsis.write_to_string}"
516 return res
517 end
518
519 # List packages by group.
520 #
521 # For each key of the `map` a `<h3>` is generated.
522 # Each package is then listed.
523 #
524 # The list of keys is generated first to allow fast access to the correct `<h3>`.
525 # `id_prefix` is used to give an id to the `<h3>` element.
526 fun list_by(map: MultiHashMap[String, MPackage], id_prefix: String): Template
527 do
528 var res = new Template
529 var keys = map.keys.to_a
530 alpha_comparator.sort(keys)
531 var list = [for x in keys do "<a href=\"#{id_prefix}{x.html_escape}\">{x.html_escape}</a>"]
532 res.add_list(list, ", ", " and ")
533
534 for k in keys do
535 var projs = map[k].to_a
536 alpha_comparator.sort(projs)
537 var e = k.html_escape
538 res.add "<h3 id=\"{id_prefix}{e}\">{e} ({projs.length})</h3>\n<ul>\n"
539 for p in projs do
540 res.add "<li>"
541 res.add li_package(p)
542 res.add "</li>"
543 end
544 res.add "</ul>"
545 end
546 return res
547 end
548
549 # List the 10 best packages from `cpt`
550 fun list_best(cpt: Counter[MPackage]): Template
551 do
552 var res = new Template
553 res.add "<ul>"
554 var best = cpt.sort
555 for i in [1..10] do
556 if i > best.length then break
557 var p = best[best.length-i]
558 res.add "<li>"
559 res.add li_package(p)
560 # res.add " ({cpt[p]})"
561 res.add "</li>"
562 end
563 res.add "</ul>"
564 return res
565 end
566
567 # Collect more information on a package using the `git` tool.
568 fun git_info(mpackage: MPackage)
569 do
570 var ini = mpackage.ini
571 if ini == null then return
572
573 # TODO use real git info
574 #var repo = ini.get_or_null("upstream.git")
575 #var branch = ini.get_or_null("upstream.git.branch")
576 #var directory = ini.get_or_null("upstream.git.directory")
577
578 var dirpath = mpackage.root.filepath
579 if dirpath == null then return
580
581 # Collect commits info
582 var res = git_run("log", "--no-merges", "--follow", "--pretty=tformat:%ad;%aN <%aE>", "--", dirpath)
583 var contributors = new Counter[String]
584 var commits = res.split("\n")
585 if commits.not_empty and commits.last == "" then commits.pop
586 self.commits[mpackage] = commits.length
587 for l in commits do
588 var s = l.split_once_on(';')
589 if s.length != 2 or s.last == "" then continue
590
591 # Collect date of last and first commit
592 if mpackage.last_date == null then mpackage.last_date = s.first
593 mpackage.first_date = s.first
594
595 # Count contributors
596 contributors.inc(s.last)
597 end
598 for c in contributors.sort.reverse_iterator do
599 mpackage.contributors.add c
600 end
601
602 end
603
604 # Produce a HTML table containig information on the packages
605 #
606 # `package_page` must have been called before so that information is computed.
607 fun table_packages(mpackages: Array[MPackage]): Template
608 do
609 alpha_comparator.sort(mpackages)
610 var res = new Template
611 res.add "<table data-toggle=\"table\" data-sort-name=\"name\" data-sort-order=\"desc\" width=\"100%\">\n"
612 res.add "<thead><tr>\n"
613 res.add "<th data-field=\"name\" data-sortable=\"true\">name</th>\n"
614 res.add "<th data-field=\"maint\" data-sortable=\"true\">maint</th>\n"
615 res.add "<th data-field=\"contrib\" data-sortable=\"true\">contrib</th>\n"
616 if deps.not_empty then
617 res.add "<th data-field=\"reqs\" data-sortable=\"true\">reqs</th>\n"
618 res.add "<th data-field=\"dreqs\" data-sortable=\"true\">direct<br>reqs</th>\n"
619 res.add "<th data-field=\"cli\" data-sortable=\"true\">clients</th>\n"
620 res.add "<th data-field=\"dcli\" data-sortable=\"true\">direct<br>clients</th>\n"
621 end
622 res.add "<th data-field=\"mod\" data-sortable=\"true\">modules</th>\n"
623 res.add "<th data-field=\"cla\" data-sortable=\"true\">classes</th>\n"
624 res.add "<th data-field=\"met\" data-sortable=\"true\">methods</th>\n"
625 res.add "<th data-field=\"loc\" data-sortable=\"true\">lines</th>\n"
626 res.add "<th data-field=\"score\" data-sortable=\"true\">score</th>\n"
627 res.add "</tr></thead>"
628 for p in mpackages do
629 res.add "<tr>"
630 res.add "<td><a href=\"p/{p.name}.html\">{p.name}</a></td>"
631 var maint = "?"
632 if p.maintainers.not_empty then maint = p.maintainers.first
633 res.add "<td>{maint}</td>"
634 res.add "<td>{p.contributors.length}</td>"
635 if deps.not_empty then
636 res.add "<td>{deps[p].greaters.length-1}</td>"
637 res.add "<td>{deps[p].direct_greaters.length}</td>"
638 res.add "<td>{deps[p].smallers.length-1}</td>"
639 res.add "<td>{deps[p].direct_smallers.length}</td>"
640 end
641 res.add "<td>{mmodules[p]}</td>"
642 res.add "<td>{mclasses[p]}</td>"
643 res.add "<td>{mmethods[p]}</td>"
644 res.add "<td>{loc[p]}</td>"
645 res.add "<td>{score[p]}</td>"
646 res.add "</tr>\n"
647 end
648 res.add "</table>\n"
649 return res
650 end
651 end
652
653 # Execute a git command and return the result
654 fun git_run(command: String...): String
655 do
656 # print "git {command.join(" ")}"
657 var p = new ProcessReader("git", command...)
658 var res = p.read_all
659 p.close
660 p.wait
661 return res
662 end
663
664 var model = new Model
665 var tc = new ToolContext
666
667 var opt_dir = new OptionString("Directory where the HTML files are generated", "-d", "--dir")
668 var opt_no_git = new OptionBool("Do not gather git information from the working directory", "--no-git")
669 var opt_no_parse = new OptionBool("Do not parse nit files (no importation information)", "--no-parse")
670 var opt_no_model = new OptionBool("Do not analyse nit files (no class/method information)", "--no-model")
671
672 tc.option_context.add_option(opt_dir, opt_no_git, opt_no_parse, opt_no_model)
673
674 tc.process_options(sys.args)
675 tc.keep_going = true
676
677 var modelbuilder = new ModelBuilder(model, tc)
678 var catalog = new Catalog(modelbuilder)
679
680 # Get files or groups
681 for a in tc.option_context.rest do
682 modelbuilder.get_mgroup(a)
683 modelbuilder.identify_file(a)
684 end
685
686 # Scan packages and compute information
687 for p in model.mpackages do
688 var g = p.root
689 assert g != null
690 modelbuilder.scan_group(g)
691
692 # Load the module to process importation information
693 if opt_no_parse.value then continue
694 modelbuilder.parse_group(g)
695
696 catalog.deps.add_node(p)
697 for gg in p.mgroups do for m in gg.mmodules do
698 for im in m.in_importation.direct_greaters do
699 var ip = im.mpackage
700 if ip == null or ip == p then continue
701 catalog.deps.add_edge(p, ip)
702 end
703 end
704 end
705
706 if not opt_no_git.value then for p in model.mpackages do
707 catalog.git_info(p)
708 end
709
710 # Run phases to modelize classes and properties (so we can count them)
711 if not opt_no_model.value then
712 modelbuilder.run_phases
713 end
714
715 var out = opt_dir.value or else "catalog.out"
716 (out/"p").mkdir
717
718 # Generate the css (hard coded)
719 var css = """
720 body {
721 margin-top: 15px;
722 background-color: #f8f8f8;
723 }
724
725 a {
726 color: #0D8921;
727 text-decoration: none;
728 }
729
730 a:hover {
731 color: #333;
732 text-decoration: none;
733 }
734
735 h1 {
736 font-weight: bold;
737 color: #0D8921;
738 font-size: 22px;
739 }
740
741 h2 {
742 color: #6C6C6C;
743 font-size: 18px;
744 border-bottom: solid 3px #CCC;
745 }
746
747 h3 {
748 color: #6C6C6C;
749 font-size: 15px;
750 border-bottom: solid 1px #CCC;
751 }
752
753 ul {
754 list-style-type: square;
755 }
756
757 dd {
758 color: #6C6C6C;
759 margin-top: 1em;
760 margin-bottom: 1em;
761 }
762
763 pre {
764 border: 1px solid #CCC;
765 font-family: Monospace;
766 color: #2d5003;
767 background-color: rgb(250, 250, 250);
768 }
769
770 code {
771 font-family: Monospace;
772 color: #2d5003;
773 }
774
775 footer {
776 margin-top: 20px;
777 }
778
779 .container {
780 margin: 0 auto;
781 padding: 0 20px;
782 }
783
784 .content {
785 float: left;
786 margin-top: 40px;
787 width: 65%;
788 }
789
790 .sidebar {
791 float: right;
792 margin-top: 40px;
793 width: 30%
794 }
795
796 .sidebar h3 {
797 color: #0D8921;
798 font-size: 18px;
799 border-bottom: 0px;
800 }
801
802 .box {
803 margin: 0;
804 padding: 0;
805 }
806
807 .box li {
808 line-height: 2.5;
809 white-space: nowrap;
810 overflow: hidden;
811 text-overflow: ellipsis;
812 padding-right: 10px;
813 border-bottom: 1px solid rgba(0,0,0,0.2);
814 }
815 """
816 css.write_to_file(out/"style.css")
817
818 # PAGES
819
820 for p in model.mpackages do
821 # print p
822 var f = "p/{p.name}.html"
823 catalog.package_page(p).write_to_file(out/f)
824 end
825
826 # INDEX
827
828 var index = new CatalogPage("")
829 index.more_head.add "<title>Packages in Nit</title>"
830
831 index.add """
832 <div class="content">
833 <h1>Packages in Nit</h1>
834 """
835
836 index.add "<h2>Highlighted Packages</h2>\n"
837 index.add catalog.list_best(catalog.score)
838
839 if catalog.deps.not_empty then
840 index.add "<h2>Most Required</h2>\n"
841 var reqs = new Counter[MPackage]
842 for p in model.mpackages do
843 reqs[p] = catalog.deps[p].smallers.length - 1
844 end
845 index.add catalog.list_best(reqs)
846 end
847
848 index.add "<h2>By First Tag</h2>\n"
849 index.add catalog.list_by(catalog.cat2proj, "cat_")
850
851 index.add "<h2>By Any Tag</h2>\n"
852 index.add catalog.list_by(catalog.tag2proj, "tag_")
853
854 index.add """
855 </div>
856 <div class="sidebar">
857 <h3>Stats</h3>
858 <ul class="box">
859 <li>{{{model.mpackages.length}}} packages</li>
860 <li>{{{catalog.maint2proj.length}}} maintainers</li>
861 <li>{{{catalog.contrib2proj.length}}} contributors</li>
862 <li>{{{catalog.tag2proj.length}}} tags</li>
863 <li>{{{catalog.mmodules.sum}}} modules</li>
864 <li>{{{catalog.mclasses.sum}}} classes</li>
865 <li>{{{catalog.mmethods.sum}}} methods</li>
866 <li>{{{catalog.loc.sum}}} lines of code</li>
867 </ul>
868 </div>
869 """
870
871 index.write_to_file(out/"index.html")
872
873 # PEOPLE
874
875 var page = new CatalogPage("")
876 page.more_head.add "<title>People of Nit</title>"
877 page.add """<div class="content">\n<h1>People of Nit</h1>\n"""
878 page.add "<h2>By Maintainer</h2>\n"
879 page.add catalog.list_by(catalog.maint2proj, "maint_")
880 page.add "<h2>By Contributor</h2>\n"
881 page.add catalog.list_by(catalog.contrib2proj, "contrib_")
882 page.add "</div>\n"
883 page.write_to_file(out/"people.html")
884
885 # TABLE
886
887 page = new CatalogPage("")
888 page.more_head.add "<title>Projets of Nit</title>"
889 page.add """<div class="content">\n<h1>People of Nit</h1>\n"""
890 page.add "<h2>Table of Projets</h2>\n"
891 page.add catalog.table_packages(model.mpackages)
892 page.add "</div>\n"
893 page.write_to_file(out/"table.html")