From e4a5f63375897f4fbfc5fdc7fab3d2966ca54451 Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Thu, 23 Apr 2015 21:05:12 -0400 Subject: [PATCH] src/doc: introduce DocComposite HTML rendering services Signed-off-by: Alexandre Terrasa --- src/doc/html_templates/html_templates.nit | 69 +++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/src/doc/html_templates/html_templates.nit b/src/doc/html_templates/html_templates.nit index 53fc0cf..540ec24 100644 --- a/src/doc/html_templates/html_templates.nit +++ b/src/doc/html_templates/html_templates.nit @@ -196,3 +196,72 @@ class DocTopMenu addn "" end end + +redef class DocComposite + super Template + + # HTML anchor id + var html_id: String is noinit + + # Title to display if any. + # + # This title can be decorated with HTML. + var html_title: nullable Writable is noinit, writable + + # Subtitle to display if any. + var html_subtitle: nullable Writable is noinit, writable + + # Render the element title and subtitle. + private fun render_title do + if html_title != null then + addn new Header(hlvl, html_title.write_to_string) + end + if html_subtitle != null then + addn "
" + addn html_subtitle.write_to_string + addn "
" + end + end + + # Render the element body. + private fun render_body do end + + redef fun rendering do + if is_hidden then return + render_title + render_body + end + + # Level for HTML heading. + private fun hlvl: Int do + if parent == null then return 1 + return parent.hlvl + 1 + end + + # Is `self` not displayed in the page. + # + # By default, empty elements are hidden. + fun is_hidden: Bool do return is_empty +end + +redef class DocSection + super BSComponent + + redef fun rendering do + if is_hidden then + addn "" + return + end + render_body + end +end + +redef class DocArticle + super BSComponent + + # Never displays the title for article. + # + # This is to maintain compatibility with old components, this may change + # without notice in further version. + redef fun render_title do end +end -- 1.7.9.5