nitcatalog: implements `package.more_contributors` per specification
[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[MConcern], 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 MModule then
259 var d = ""
260 var mdoc = o.mdoc
261 if mdoc != null then d = ": {mdoc.html_synopsis.write_to_string}"
262 res.add "<strong>{o.name}</strong>{d} ({o.filepath.to_s})"
263 else
264 abort
265 end
266 var subs = ot.sub.get_or_null(o)
267 if subs != null then gen_content_level(ot, subs, res)
268 res.add "</li>\n"
269 end
270 res.add "</ul>\n"
271 end
272
273 # Compute information and generate a full HTML page for a package
274 fun package_page(mpackage: MPackage): Writable
275 do
276 var res = new CatalogPage("..")
277 var score = score[mpackage].to_f
278 var name = mpackage.name.html_escape
279 res.more_head.add """<title>{{{name}}}</title>"""
280
281 res.add """
282 <div class="content">
283 <h1 class="package-name">{{{name}}}</h1>
284 """
285 var mdoc = mpackage.mdoc_or_fallback
286 if mdoc != null then
287 score += 100.0
288 res.add mdoc.html_documentation
289 score += mdoc.content.length.score
290 end
291
292 res.add "<h2>Content</h2>"
293 var ot = new OrderedTree[MConcern]
294 for g in mpackage.mgroups do
295 var pa = g.parent
296 if g.is_interesting then
297 ot.add(pa, g)
298 pa = g
299 end
300 for mp in g.mmodules do
301 ot.add(pa, mp)
302 end
303 end
304 ot.sort_with(alpha_comparator)
305 gen_content_level(ot, ot.roots, res)
306
307
308 res.add """
309 </div>
310 <div class="sidebar">
311 <ul class="box">
312 """
313 var tryit = mpackage.metadata("upstream.tryit")
314 if tryit != null then
315 score += 1.0
316 var e = tryit.html_escape
317 res.add "<li><a href=\"{e}\">Try<span style=\"color:white\">n</span>it!</a></li>\n"
318 end
319 var apk = mpackage.metadata("upstream.apk")
320 if apk != null then
321 score += 1.0
322 var e = apk.html_escape
323 res.add "<li><a href=\"{e}\">Android apk</a></li>\n"
324 end
325
326 res.add """</ul>\n<ul class="box">\n"""
327
328 var homepage = mpackage.metadata("upstream.homepage")
329 if homepage != null then
330 score += 5.0
331 var e = homepage.html_escape
332 res.add "<li><a href=\"{e}\">{e}</a></li>\n"
333 end
334 var maintainer = mpackage.metadata("package.maintainer")
335 if maintainer != null then
336 score += 5.0
337 add_contrib(maintainer, mpackage, res)
338 mpackage.maintainers.add maintainer
339 var projs = maint2proj[maintainer]
340 if not projs.has(mpackage) then projs.add mpackage
341 end
342 var license = mpackage.metadata("package.license")
343 if license != null then
344 score += 5.0
345 var e = license.html_escape
346 res.add "<li><a href=\"http://opensource.org/licenses/{e}\">{e}</a> license</li>\n"
347 end
348 res.add "</ul>\n"
349
350 res.add "<h3>Source Code</h3>\n<ul class=\"box\">\n"
351 var browse = mpackage.metadata("upstream.browse")
352 if browse != null then
353 score += 5.0
354 var e = browse.html_escape
355 res.add "<li><a href=\"{e}\">{e}</a></li>\n"
356 end
357 var git = mpackage.metadata("upstream.git")
358 if git != null then
359 var e = git.html_escape
360 res.add "<li><tt>{e}</tt></li>\n"
361 end
362 var last_date = mpackage.last_date
363 if last_date != null then
364 var e = last_date.html_escape
365 res.add "<li>most recent commit: {e}</li>\n"
366 end
367 var first_date = mpackage.first_date
368 if first_date != null then
369 var e = first_date.html_escape
370 res.add "<li>oldest commit: {e}</li>\n"
371 end
372 var commits = commits[mpackage]
373 if commits != 0 then
374 res.add "<li>{commits} commits</li>\n"
375 end
376 res.add "</ul>\n"
377
378 res.add "<h3>Tags</h3>\n"
379 var tags = mpackage.metadata("package.tags")
380 var ts = new Array[String]
381 if tags != null then
382 for t in tags.split(",") do
383 t = t.trim
384 if t == "" then continue
385 ts.add t
386 end
387 end
388 if ts.is_empty then ts.add "none"
389 if tryit != null then ts.add "tryit"
390 if apk != null then ts.add "apk"
391 var ts2 = new Array[String]
392 for t in ts do
393 tag2proj[t].add mpackage
394 t = t.html_escape
395 ts2.add "<a href=\"../index.html#tag_{t}\">{t}</a>"
396 end
397 res.add_list(ts2, ", ", ", ")
398 var cat = ts.first
399 cat2proj[cat].add mpackage
400 score += ts.length.score
401
402 if deps.has(mpackage) then
403 var reqs = deps[mpackage].greaters.to_a
404 reqs.remove(mpackage)
405 alpha_comparator.sort(reqs)
406 res.add "<h3>Requirements</h3>\n"
407 if reqs.is_empty then
408 res.add "none"
409 else
410 var list = new Array[String]
411 for r in reqs do
412 var direct = deps.has_direct_edge(mpackage, r)
413 var s = "<a href=\"{r}.html\">"
414 if direct then s += "<strong>"
415 s += r.to_s
416 if direct then s += "</strong>"
417 s += "</a>"
418 list.add s
419 end
420 res.add_list(list, ", ", " and ")
421 end
422
423 reqs = deps[mpackage].smallers.to_a
424 reqs.remove(mpackage)
425 alpha_comparator.sort(reqs)
426 res.add "<h3>Clients</h3>\n"
427 if reqs.is_empty then
428 res.add "none"
429 else
430 var list = new Array[String]
431 for r in reqs do
432 var direct = deps.has_direct_edge(r, mpackage)
433 var s = "<a href=\"{r}.html\">"
434 if direct then s += "<strong>"
435 s += r.to_s
436 if direct then s += "</strong>"
437 s += "</a>"
438 list.add s
439 end
440 res.add_list(list, ", ", " and ")
441 end
442
443 score += deps[mpackage].greaters.length.score
444 score += deps[mpackage].direct_greaters.length.score
445 score += deps[mpackage].smallers.length.score
446 score += deps[mpackage].direct_smallers.length.score
447 end
448
449 var contributors = mpackage.contributors
450 var more_contributors = mpackage.metadata("package.more_contributors")
451 if more_contributors != null then
452 for c in more_contributors.split(",") do
453 contributors.add c.trim
454 end
455 end
456 if not contributors.is_empty then
457 res.add "<h3>Contributors</h3>\n<ul class=\"box\">"
458 for c in contributors do
459 add_contrib(c, mpackage, res)
460 end
461 res.add "</ul>"
462 end
463 score += contributors.length.to_f
464
465 var mmodules = 0
466 var mclasses = 0
467 var mmethods = 0
468 var loc = 0
469 for g in mpackage.mgroups do
470 mmodules += g.mmodules.length
471 for m in g.mmodules do
472 var am = modelbuilder.mmodule2node(m)
473 if am != null then
474 var file = am.location.file
475 if file != null then
476 loc += file.line_starts.length - 1
477 end
478 end
479 for cd in m.mclassdefs do
480 mclasses += 1
481 for pd in cd.mpropdefs do
482 if not pd isa MMethodDef then continue
483 mmethods += 1
484 end
485 end
486 end
487 end
488 self.mmodules[mpackage] = mmodules
489 self.mclasses[mpackage] = mclasses
490 self.mmethods[mpackage] = mmethods
491 self.loc[mpackage] = loc
492
493 #score += mmodules.score
494 score += mclasses.score
495 score += mmethods.score
496 score += loc.score
497
498 res.add """
499 <h3>Stats</h3>
500 <ul class="box">
501 <li>{{{mmodules}}} modules</li>
502 <li>{{{mclasses}}} classes</li>
503 <li>{{{mmethods}}} methods</li>
504 <li>{{{loc}}} lines of code</li>
505 </ul>
506 """
507
508 res.add """
509 </div>
510 """
511 self.score[mpackage] = score.to_i
512
513 return res
514 end
515
516 # Return a short HTML sequence for a package
517 #
518 # Intended to use in lists.
519 fun li_package(p: MPackage): String
520 do
521 var res = ""
522 var f = "p/{p.name}.html"
523 res += "<a href=\"{f}\">{p}</a>"
524 var d = p.mdoc_or_fallback
525 if d != null then res += " - {d.html_synopsis.write_to_string}"
526 return res
527 end
528
529 # List packages by group.
530 #
531 # For each key of the `map` a `<h3>` is generated.
532 # Each package is then listed.
533 #
534 # The list of keys is generated first to allow fast access to the correct `<h3>`.
535 # `id_prefix` is used to give an id to the `<h3>` element.
536 fun list_by(map: MultiHashMap[String, MPackage], id_prefix: String): Template
537 do
538 var res = new Template
539 var keys = map.keys.to_a
540 alpha_comparator.sort(keys)
541 var list = [for x in keys do "<a href=\"#{id_prefix}{x.html_escape}\">{x.html_escape}</a>"]
542 res.add_list(list, ", ", " and ")
543
544 for k in keys do
545 var projs = map[k].to_a
546 alpha_comparator.sort(projs)
547 var e = k.html_escape
548 res.add "<h3 id=\"{id_prefix}{e}\">{e} ({projs.length})</h3>\n<ul>\n"
549 for p in projs do
550 res.add "<li>"
551 res.add li_package(p)
552 res.add "</li>"
553 end
554 res.add "</ul>"
555 end
556 return res
557 end
558
559 # List the 10 best packages from `cpt`
560 fun list_best(cpt: Counter[MPackage]): Template
561 do
562 var res = new Template
563 res.add "<ul>"
564 var best = cpt.sort
565 for i in [1..10] do
566 if i > best.length then break
567 var p = best[best.length-i]
568 res.add "<li>"
569 res.add li_package(p)
570 # res.add " ({cpt[p]})"
571 res.add "</li>"
572 end
573 res.add "</ul>"
574 return res
575 end
576
577 # Collect more information on a package using the `git` tool.
578 fun git_info(mpackage: MPackage)
579 do
580 var ini = mpackage.ini
581 if ini == null then return
582
583 # TODO use real git info
584 #var repo = ini.get_or_null("upstream.git")
585 #var branch = ini.get_or_null("upstream.git.branch")
586 #var directory = ini.get_or_null("upstream.git.directory")
587
588 var dirpath = mpackage.root.filepath
589 if dirpath == null then return
590
591 # Collect commits info
592 var res = git_run("log", "--no-merges", "--follow", "--pretty=tformat:%ad;%aN <%aE>", "--", dirpath)
593 var contributors = new Counter[String]
594 var commits = res.split("\n")
595 if commits.not_empty and commits.last == "" then commits.pop
596 self.commits[mpackage] = commits.length
597 for l in commits do
598 var s = l.split_once_on(';')
599 if s.length != 2 or s.last == "" then continue
600
601 # Collect date of last and first commit
602 if mpackage.last_date == null then mpackage.last_date = s.first
603 mpackage.first_date = s.first
604
605 # Count contributors
606 contributors.inc(s.last)
607 end
608 for c in contributors.sort.reverse_iterator do
609 mpackage.contributors.add c
610 end
611
612 end
613
614 # Produce a HTML table containig information on the packages
615 #
616 # `package_page` must have been called before so that information is computed.
617 fun table_packages(mpackages: Array[MPackage]): Template
618 do
619 alpha_comparator.sort(mpackages)
620 var res = new Template
621 res.add "<table data-toggle=\"table\" data-sort-name=\"name\" data-sort-order=\"desc\" width=\"100%\">\n"
622 res.add "<thead><tr>\n"
623 res.add "<th data-field=\"name\" data-sortable=\"true\">name</th>\n"
624 res.add "<th data-field=\"maint\" data-sortable=\"true\">maint</th>\n"
625 res.add "<th data-field=\"contrib\" data-sortable=\"true\">contrib</th>\n"
626 if deps.not_empty then
627 res.add "<th data-field=\"reqs\" data-sortable=\"true\">reqs</th>\n"
628 res.add "<th data-field=\"dreqs\" data-sortable=\"true\">direct<br>reqs</th>\n"
629 res.add "<th data-field=\"cli\" data-sortable=\"true\">clients</th>\n"
630 res.add "<th data-field=\"dcli\" data-sortable=\"true\">direct<br>clients</th>\n"
631 end
632 res.add "<th data-field=\"mod\" data-sortable=\"true\">modules</th>\n"
633 res.add "<th data-field=\"cla\" data-sortable=\"true\">classes</th>\n"
634 res.add "<th data-field=\"met\" data-sortable=\"true\">methods</th>\n"
635 res.add "<th data-field=\"loc\" data-sortable=\"true\">lines</th>\n"
636 res.add "<th data-field=\"score\" data-sortable=\"true\">score</th>\n"
637 res.add "</tr></thead>"
638 for p in mpackages do
639 res.add "<tr>"
640 res.add "<td><a href=\"p/{p.name}.html\">{p.name}</a></td>"
641 var maint = "?"
642 if p.maintainers.not_empty then maint = p.maintainers.first
643 res.add "<td>{maint}</td>"
644 res.add "<td>{p.contributors.length}</td>"
645 if deps.not_empty then
646 res.add "<td>{deps[p].greaters.length-1}</td>"
647 res.add "<td>{deps[p].direct_greaters.length}</td>"
648 res.add "<td>{deps[p].smallers.length-1}</td>"
649 res.add "<td>{deps[p].direct_smallers.length}</td>"
650 end
651 res.add "<td>{mmodules[p]}</td>"
652 res.add "<td>{mclasses[p]}</td>"
653 res.add "<td>{mmethods[p]}</td>"
654 res.add "<td>{loc[p]}</td>"
655 res.add "<td>{score[p]}</td>"
656 res.add "</tr>\n"
657 end
658 res.add "</table>\n"
659 return res
660 end
661 end
662
663 # Execute a git command and return the result
664 fun git_run(command: String...): String
665 do
666 # print "git {command.join(" ")}"
667 var p = new ProcessReader("git", command...)
668 var res = p.read_all
669 p.close
670 p.wait
671 return res
672 end
673
674 var model = new Model
675 var tc = new ToolContext
676
677 var opt_dir = new OptionString("Directory where the HTML files are generated", "-d", "--dir")
678 var opt_no_git = new OptionBool("Do not gather git information from the working directory", "--no-git")
679 var opt_no_parse = new OptionBool("Do not parse nit files (no importation information)", "--no-parse")
680 var opt_no_model = new OptionBool("Do not analyse nit files (no class/method information)", "--no-model")
681
682 tc.option_context.add_option(opt_dir, opt_no_git, opt_no_parse, opt_no_model)
683
684 tc.process_options(sys.args)
685 tc.keep_going = true
686
687 var modelbuilder = new ModelBuilder(model, tc)
688 var catalog = new Catalog(modelbuilder)
689
690 # Get files or groups
691 var args = tc.option_context.rest
692 if opt_no_parse.value then
693 modelbuilder.scan_full(args)
694 else
695 modelbuilder.parse_full(args)
696 end
697
698 # Scan packages and compute information
699 for p in model.mpackages do
700 var g = p.root
701 assert g != null
702 modelbuilder.scan_group(g)
703
704 # Load the module to process importation information
705 if opt_no_parse.value then continue
706
707 catalog.deps.add_node(p)
708 for gg in p.mgroups do for m in gg.mmodules do
709 for im in m.in_importation.direct_greaters do
710 var ip = im.mpackage
711 if ip == null or ip == p then continue
712 catalog.deps.add_edge(p, ip)
713 end
714 end
715 end
716
717 if not opt_no_git.value then for p in model.mpackages do
718 catalog.git_info(p)
719 end
720
721 # Run phases to modelize classes and properties (so we can count them)
722 if not opt_no_model.value then
723 modelbuilder.run_phases
724 end
725
726 var out = opt_dir.value or else "catalog.out"
727 (out/"p").mkdir
728
729 # Generate the css (hard coded)
730 var css = """
731 body {
732 margin-top: 15px;
733 background-color: #f8f8f8;
734 }
735
736 a {
737 color: #0D8921;
738 text-decoration: none;
739 }
740
741 a:hover {
742 color: #333;
743 text-decoration: none;
744 }
745
746 h1 {
747 font-weight: bold;
748 color: #0D8921;
749 font-size: 22px;
750 }
751
752 h2 {
753 color: #6C6C6C;
754 font-size: 18px;
755 border-bottom: solid 3px #CCC;
756 }
757
758 h3 {
759 color: #6C6C6C;
760 font-size: 15px;
761 border-bottom: solid 1px #CCC;
762 }
763
764 ul {
765 list-style-type: square;
766 }
767
768 dd {
769 color: #6C6C6C;
770 margin-top: 1em;
771 margin-bottom: 1em;
772 }
773
774 pre {
775 border: 1px solid #CCC;
776 font-family: Monospace;
777 color: #2d5003;
778 background-color: rgb(250, 250, 250);
779 }
780
781 code {
782 font-family: Monospace;
783 color: #2d5003;
784 }
785
786 footer {
787 margin-top: 20px;
788 }
789
790 .container {
791 margin: 0 auto;
792 padding: 0 20px;
793 }
794
795 .content {
796 float: left;
797 margin-top: 40px;
798 width: 65%;
799 }
800
801 .sidebar {
802 float: right;
803 margin-top: 40px;
804 width: 30%
805 }
806
807 .sidebar h3 {
808 color: #0D8921;
809 font-size: 18px;
810 border-bottom: 0px;
811 }
812
813 .box {
814 margin: 0;
815 padding: 0;
816 }
817
818 .box li {
819 line-height: 2.5;
820 white-space: nowrap;
821 overflow: hidden;
822 text-overflow: ellipsis;
823 padding-right: 10px;
824 border-bottom: 1px solid rgba(0,0,0,0.2);
825 }
826 """
827 css.write_to_file(out/"style.css")
828
829 # PAGES
830
831 for p in model.mpackages do
832 # print p
833 var f = "p/{p.name}.html"
834 catalog.package_page(p).write_to_file(out/f)
835 end
836
837 # INDEX
838
839 var index = new CatalogPage("")
840 index.more_head.add "<title>Packages in Nit</title>"
841
842 index.add """
843 <div class="content">
844 <h1>Packages in Nit</h1>
845 """
846
847 index.add "<h2>Highlighted Packages</h2>\n"
848 index.add catalog.list_best(catalog.score)
849
850 if catalog.deps.not_empty then
851 index.add "<h2>Most Required</h2>\n"
852 var reqs = new Counter[MPackage]
853 for p in model.mpackages do
854 reqs[p] = catalog.deps[p].smallers.length - 1
855 end
856 index.add catalog.list_best(reqs)
857 end
858
859 index.add "<h2>By First Tag</h2>\n"
860 index.add catalog.list_by(catalog.cat2proj, "cat_")
861
862 index.add "<h2>By Any Tag</h2>\n"
863 index.add catalog.list_by(catalog.tag2proj, "tag_")
864
865 index.add """
866 </div>
867 <div class="sidebar">
868 <h3>Stats</h3>
869 <ul class="box">
870 <li>{{{model.mpackages.length}}} packages</li>
871 <li>{{{catalog.maint2proj.length}}} maintainers</li>
872 <li>{{{catalog.contrib2proj.length}}} contributors</li>
873 <li>{{{catalog.tag2proj.length}}} tags</li>
874 <li>{{{catalog.mmodules.sum}}} modules</li>
875 <li>{{{catalog.mclasses.sum}}} classes</li>
876 <li>{{{catalog.mmethods.sum}}} methods</li>
877 <li>{{{catalog.loc.sum}}} lines of code</li>
878 </ul>
879 </div>
880 """
881
882 index.write_to_file(out/"index.html")
883
884 # PEOPLE
885
886 var page = new CatalogPage("")
887 page.more_head.add "<title>People of Nit</title>"
888 page.add """<div class="content">\n<h1>People of Nit</h1>\n"""
889 page.add "<h2>By Maintainer</h2>\n"
890 page.add catalog.list_by(catalog.maint2proj, "maint_")
891 page.add "<h2>By Contributor</h2>\n"
892 page.add catalog.list_by(catalog.contrib2proj, "contrib_")
893 page.add "</div>\n"
894 page.write_to_file(out/"people.html")
895
896 # TABLE
897
898 page = new CatalogPage("")
899 page.more_head.add "<title>Projets of Nit</title>"
900 page.add """<div class="content">\n<h1>People of Nit</h1>\n"""
901 page.add "<h2>Table of Projets</h2>\n"
902 page.add catalog.table_packages(model.mpackages)
903 page.add "</div>\n"
904 page.write_to_file(out/"table.html")