src/doc/templates: add template for the Person class from the nit catalog
authorAlexandre Terrasa <alexandre@moz-code.org>
Sat, 2 Jun 2018 16:11:52 +0000 (12:11 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Sun, 10 Jun 2018 17:25:06 +0000 (13:25 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/doc/templates/templates_html.nit

index ac02f10..4faf0a6 100644 (file)
@@ -18,6 +18,7 @@ module templates_html
 import model::model_collect
 import doc::doc_down
 import html::bootstrap
+import catalog
 
 redef class MEntity
 
@@ -362,3 +363,29 @@ redef class MParameter
                return tpl
        end
 end
+
+redef class Person
+
+       # HTML uniq id
+       fun html_id: String do return name.to_cmangle
+
+       # HTML default URL
+       #
+       # Should be redefined in clients.
+       fun html_url: String do return "person_{html_id}.html"
+
+       # Link to this person `html_url`
+       fun html_link: Link do return new Link(html_url, name)
+
+       redef fun to_html do
+               var tpl = new Template
+               tpl.addn "<span>"
+               var gravatar = self.gravatar
+               if gravatar != null then
+                       tpl.addn "<img class='avatar' src='https://secure.gravatar.com/avatar/{gravatar}?size=14&amp;default=retro' />"
+               end
+               tpl.addn html_link
+               tpl.addn "</span>"
+               return tpl.write_to_string
+       end
+end