This PR reorganizes Nitdoc modules importation for HTML templates.
The main objective is to dissociate `doc_model` from html related things.
This is the last step before template migration from old model templates to `DocComposite`.
Pull-Request: #1172
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
module doc_base
import toolcontext
-import doc_model # FIXME maintain compatibility with old templates.
+import model_utils
+import model_ext
# The model of a Nitdoc documentation.
#
# Add a `child` to `self`.
#
# Shortcut for `children.add`.
- fun add(child: DocComposite) do children.add child
+ fun add_child(child: DocComposite) do
+ children.add child
+ end
end
# The `DocComposite` element that contains all the other.
# The title of the group, as displayed to the user.
var title: String
end
+
+redef class MEntity
+ # Name displayed in console for debug and tests.
+ fun nitdoc_name: String do return name.html_escape
+end
+
+redef class MClassDef
+ redef fun nitdoc_name do return mclass.nitdoc_name
+end
+
+redef class MPropDef
+ redef fun nitdoc_name do return mproperty.nitdoc_name
+end
# Adds importation and class hierarchy graphs.
module doc_graphs
+import doc_structure
import doc_poset
+import html_templates::html_model # FIXME maybe this phase should depend on `html_render`
redef class ToolContext
end
end
op.append("\}\n")
- return new GraphArticle(name, op)
+ return new GraphArticle(mentity, name, op)
end
end
end
end
op.append("\}\n")
- return new GraphArticle(name, op)
+ return new GraphArticle(mentity, name, op)
end
end
# The graph is stored in dot format.
# The final output is delayed untill rendering.
class GraphArticle
- super DocComposite
+ super MEntityComposite
# Graph ID (used for outputing file with names).
var id: String
redef class MModulePage
redef fun build_inh_list(v, doc) do
- var section = new ImportationListSection
+ var section = new ImportationListSection(mentity)
var imports = self.imports.to_a
v.name_sorter.sort(imports)
- section.children.add new HierarchyListArticle(mentity, "Imports", imports)
+ section.add_child new HierarchyListArticle(mentity, "Imports", imports)
var clients = self.clients.to_a
v.name_sorter.sort(clients)
- section.children.add new HierarchyListArticle(mentity, "Clients", clients)
+ section.add_child new HierarchyListArticle(mentity, "Clients", clients)
root.children.insert(section, 1)
end
end
redef class MClassPage
redef fun build_inh_list(v, doc) do
- var section = new InheritanceListSection
+ var section = new InheritanceListSection(mentity)
var parents = self.parents.to_a
v.name_sorter.sort(parents)
- section.children.add new HierarchyListArticle(mentity, "Parents", parents)
+ section.add_child new HierarchyListArticle(mentity, "Parents", parents)
var ancestors = self.ancestors.to_a
v.name_sorter.sort(ancestors)
- section.children.add new HierarchyListArticle(mentity, "Ancestors", ancestors)
+ section.add_child new HierarchyListArticle(mentity, "Ancestors", ancestors)
var children = self.children.to_a
v.name_sorter.sort(children)
- section.children.add new HierarchyListArticle(mentity, "Children", children)
+ section.add_child new HierarchyListArticle(mentity, "Children", children)
var descendants = self.descendants.to_a
v.name_sorter.sort(descendants)
- section.children.add new HierarchyListArticle(mentity, "Descendants", descendants)
+ section.add_child new HierarchyListArticle(mentity, "Descendants", descendants)
root.children.insert(section, 1)
end
end
# FIXME diff hack
class ImportationListSection
super DocSection
+ super MEntityComposite
end
# FIXME diff hack
class InheritanceListSection
super DocSection
+ super MEntityComposite
end
# Dislay a hierarchical list of mentities.
import doc_hierarchies
import doc_intros_redefs
import doc_graphs
+import html_templates
redef class ToolContext
redef fun apply do
init_output_dir
for page in doc.pages do
- page.render(self, doc).write_to_file("{ctx.output_dir.to_s}/{page.page_url}")
+ page.render(self, doc).write_to_file("{ctx.output_dir.to_s}/{page.html_url}")
end
end
redef class DocPage
# Render the page as a html template.
- private fun render(v: RenderHTMLPhase, doc: DocModel): TplPage do
+ private fun render(v: RenderHTMLPhase, doc: DocModel): Writable do
var shareurl = "."
if v.ctx.opt_shareurl.value != null then
shareurl = v.ctx.opt_shareurl.value.as(not null)
end
+ # init page options
+ self.shareurl = shareurl
+ self.footer = v.ctx.opt_custom_footer.value
+ self.body_attrs.add(new TagAttribute("data-bootstrap-share", shareurl))
+
# build page
- var tpl = new TplPage
- tpl.title = tpl_title(v, doc)
- tpl.url = page_url
- tpl.shareurl = shareurl
- tpl.topmenu = tpl_topmenu(v, doc)
- tpl.add_section tpl_content(v, doc)
- tpl.footer = v.ctx.opt_custom_footer.value
- tpl.body_attrs.add(new TagAttribute("data-bootstrap-share", shareurl))
- tpl.sidebar = tpl_sidebar(v, doc)
+ init_title(v, doc)
+ init_sidebar(v, doc)
+ init_topmenu(v, doc)
+ init_content(v, doc)
# piwik tracking
var tracker_url = v.ctx.opt_piwik_tracker.value
var site_id = v.ctx.opt_piwik_site_id.value
if tracker_url != null and site_id != null then
- tpl.scripts.add new TplPiwikScript(tracker_url, site_id)
+ self.scripts.add new TplPiwikScript(tracker_url, site_id)
end
- return tpl
+ return self
end
# FIXME diff hack
# all properties below are roughly copied from `doc_pages`
- # URL to this page.
- fun page_url: String is abstract
-
- # Build page sidebar if any
- fun tpl_sidebar(v: RenderHTMLPhase, doc: DocModel): nullable TplSidebar do return null
-
# Build page title string
- fun tpl_title(v: RenderHTMLPhase, doc: DocModel): String do
- if v.ctx.opt_custom_title.value != null then
- return v.ctx.opt_custom_title.value.to_s
- end
- return "Nitdoc"
- end
+ fun init_title(v: RenderHTMLPhase, doc: DocModel) is abstract
- # Build top menu template
- fun tpl_topmenu(v: RenderHTMLPhase, doc: DocModel): TplTopMenu do
- var topmenu = new TplTopMenu(page_url)
+ # Build top menu template if any.
+ fun init_topmenu(v: RenderHTMLPhase, doc: DocModel) do
+ topmenu = new TplTopMenu(html_url)
var brand = v.ctx.opt_custom_brand.value
if brand != null then
var tpl = new Template
end
topmenu.add_link new TplLink("index.html", "Overview")
topmenu.add_link new TplLink("search.html", "Index")
- return topmenu
end
- # Build page content template
- fun tpl_content(v: RenderHTMLPhase, doc: DocModel): TplSection is abstract
+ # Build page sidebar if any.
+ fun init_sidebar(v: RenderHTMLPhase, doc: DocModel) do
+ sidebar = new TplSidebar
+ end
+
+ # Build page content template.
+ fun init_content(v: RenderHTMLPhase, doc: DocModel) do end
end
redef class OverviewPage
- redef fun page_url do return "index.html"
+ redef var html_url = "index.html"
- redef fun tpl_title(v, doc) do
+ redef fun init_title(v, doc) do
+ title = "Overview"
if v.ctx.opt_custom_title.value != null then
- return v.ctx.opt_custom_title.value.to_s
- else
- return "Overview"
+ title = v.ctx.opt_custom_title.value.to_s
end
end
# TODO this should be done in StructurePhase.
- redef fun tpl_content(v, doc) do
+ redef fun init_content(v, doc) do
# intro text
- var section = new TplSection.with_title("overview", tpl_title(v, doc))
+ var section = new TplSection.with_title("overview", title)
var article = new TplArticle("intro")
if v.ctx.opt_custom_intro.value != null then
article.content = v.ctx.opt_custom_intro.value.to_s
ssection.add_child sarticle
end
section.add_child ssection
- return section
+ self.add_section section
end
- redef fun tpl_sidebar(v, doc) do return new TplSidebar
+ redef fun init_sidebar(v, doc) do sidebar = new TplSidebar
end
redef class SearchPage
- redef fun page_url do return "search.html"
- redef fun tpl_title(v, doc) do return "Index"
+ redef var html_url = "search.html"
+ redef fun init_title(v, doc) do title = "Index"
+ redef fun init_sidebar(v, doc) do end
# TODO this should be done in StructurePhase.
- redef fun tpl_content(v, doc) do
+ redef fun init_content(v, doc) do
var tpl = new TplSearchPage("search_all")
var section = new TplSection("search")
# title
tpl.props.add m
end
section.add_child tpl
- return section
+ self.add_section section
end
# Extract mmodule list to display (sorted by name)
end
redef class MEntityPage
- redef fun page_url do return mentity.nitdoc_url
- redef fun tpl_title(v, doc) do return mentity.nitdoc_name
- redef fun tpl_content(v, doc) do return root.start_rendering(v, doc, self)
+ redef var html_url is lazy do return mentity.nitdoc_url
+ redef fun init_title(v, doc) do title = mentity.nitdoc_name
+ redef fun init_content(v, doc) do add_section root.start_rendering(v, doc, self)
end
# FIXME all clases below are roughly copied from `doc_pages` and adapted to new
# `doc_templates` module.
redef class MGroupPage
- redef fun tpl_topmenu(v, doc) do
- var topmenu = super
+ redef fun init_topmenu(v, doc) do
+ super
var mproject = mentity.mproject
if not mentity.is_root then
topmenu.add_link new TplLink(mproject.nitdoc_url, mproject.nitdoc_name)
end
- topmenu.add_link new TplLink(page_url, mproject.nitdoc_name)
- return topmenu
+ topmenu.add_link new TplLink(html_url, mproject.nitdoc_name)
end
- redef fun tpl_sidebar(v, doc) do
- var sidebar = new TplSidebar
+ redef fun init_sidebar(v, doc) do
+ super
var mclasses = new HashSet[MClass]
mclasses.add_all intros
mclasses.add_all redefs
- if mclasses.is_empty then return sidebar
+ if mclasses.is_empty then return
var list = new TplList.with_classes(["list-unstyled", "list-labeled"])
var sorted = mclasses.to_a
list.add_li tpl_sidebar_item(mclass)
end
sidebar.boxes.add new TplSideBox.with_content("All classes", list)
- return sidebar
end
private fun tpl_sidebar_item(def: MClass): TplListItem do
end
redef class MModulePage
- redef fun tpl_topmenu(v, doc) do
- var topmenu = super
+ redef fun init_topmenu(v, doc) do
+ super
var mproject = mentity.mproject
topmenu.add_link new TplLink(mproject.nitdoc_url, mproject.nitdoc_name)
topmenu.add_link new TplLink(mentity.nitdoc_url, mentity.nitdoc_name)
- return topmenu
end
# Class list to display in sidebar
- redef fun tpl_sidebar(v, doc) do
+ redef fun init_sidebar(v, doc) do
# TODO filter here?
- var sidebar = new TplSidebar
+ super
var mclasses = new HashSet[MClass]
mclasses.add_all mentity.filter_intro_mclasses(v.ctx.min_visibility)
mclasses.add_all mentity.filter_redef_mclasses(v.ctx.min_visibility)
- if mclasses.is_empty then return sidebar
+ if mclasses.is_empty then return
var list = new TplList.with_classes(["list-unstyled", "list-labeled"])
var sorted = mclasses.to_a
list.add_li tpl_sidebar_item(mclass)
end
sidebar.boxes.add new TplSideBox.with_content("All classes", list)
- return sidebar
end
private fun tpl_sidebar_item(def: MClass): TplListItem do
redef class MClassPage
- redef fun tpl_title(v, doc) do
- return "{mentity.nitdoc_name}{mentity.tpl_signature.write_to_string}"
+ redef fun init_title(v, doc) do
+ title = "{mentity.nitdoc_name}{mentity.tpl_signature.write_to_string}"
end
- redef fun tpl_topmenu(v, doc) do
- var topmenu = super
+ redef fun init_topmenu(v, doc) do
+ super
var mproject = mentity.intro_mmodule.mgroup.mproject
topmenu.add_link new TplLink("{mproject.nitdoc_url}", "{mproject.nitdoc_name}")
- topmenu.add_link new TplLink(page_url, mentity.nitdoc_name)
- return topmenu
+ topmenu.add_link new TplLink(html_url, mentity.nitdoc_name)
end
- redef fun tpl_sidebar(v, doc) do
- var sidebar = new TplSidebar
+ redef fun init_sidebar(v, doc) do
+ super
var by_kind = new PropertiesByKind.with_elements(mclass_inherited_mprops(v, doc))
var summary = new TplList.with_classes(["list-unstyled"])
by_kind.sort_groups(v.name_sorter)
for g in by_kind.groups do tpl_sidebar_list(g, summary)
sidebar.boxes.add new TplSideBox.with_content("All properties", summary)
- return sidebar
end
private fun tpl_sidebar_list(mprops: PropertyGroup[MProperty], summary: TplList) do
end
redef class MPropertyPage
- redef fun tpl_topmenu(v, doc) do
- var topmenu = super
+ redef fun init_title(v, doc) do
+ title = "{mentity.nitdoc_name}{mentity.tpl_signature.write_to_string}"
+ end
+
+ redef fun init_topmenu(v, doc) do
+ super
var mmodule = mentity.intro_mclassdef.mmodule
var mproject = mmodule.mgroup.mproject
var mclass = mentity.intro_mclassdef.mclass
topmenu.add_link new TplLink("{mproject.nitdoc_url}", "{mproject.nitdoc_name}")
topmenu.add_link new TplLink("{mclass.nitdoc_url}", "{mclass.nitdoc_name}")
- topmenu.add_link new TplLink(page_url, mentity.nitdoc_name)
- return topmenu
+ topmenu.add_link new TplLink(html_url, mentity.nitdoc_name)
end
-
- redef fun tpl_title(v, doc) do
- return "{mentity.nitdoc_name}{mentity.tpl_signature.write_to_string}"
- end
-
- redef fun tpl_sidebar(v, doc) do return new TplSidebar
end
redef class DocComposite
module doc_indexing
import doc_extract
+import html_templates::html_model # FIXME maybe this phase should depend on `html_render`
private import json::static
# Generate the index for then Nitdoc QuickSearch field.
private fun build_mmodule_list(v: IntroRedefListPhase, doc: DocModel, mmodule: MModule) do
var intros = mmodule.intro_mclassdefs(v.ctx.min_visibility).to_a
doc.mainmodule.linearize_mclassdefs(intros)
- children.add new IntrosRedefsListArticle(mentity, "Introduces", intros)
+ add_child new IntrosRedefsListArticle(mentity, "Introduces", intros)
var redefs = mmodule.redef_mclassdefs(v.ctx.min_visibility).to_a
doc.mainmodule.linearize_mclassdefs(redefs)
- children.add new IntrosRedefsListArticle(mentity, "Redefines", redefs)
+ add_child new IntrosRedefsListArticle(mentity, "Redefines", redefs)
end
# TODO this should move to MEntity?
var intros = mclassdef.collect_intro_mpropdefs(v.ctx.min_visibility).to_a
# FIXME avoid diff changes
# v.ctx.mainmodule.linearize_mpropdefs(intros)
- children.add new IntrosRedefsListArticle(mentity, "Introduces", intros)
+ add_child new IntrosRedefsListArticle(mentity, "Introduces", intros)
var redefs = mclassdef.collect_redef_mpropdefs(v.ctx.min_visibility).to_a
# FIXME avoid diff changes
# v.ctx.mainmodule.linearize_mpropdefs(redefs)
- children.add new IntrosRedefsListArticle(mentity, "Redefines", redefs)
+ add_child new IntrosRedefsListArticle(mentity, "Redefines", redefs)
end
end
doc.pages.add new OverviewPage("Overview")
doc.pages.add new SearchPage("Index")
for mgroup in doc.mgroups do
- doc.pages.add new MGroupPage(mgroup.nitdoc_id, mgroup)
+ doc.pages.add new MGroupPage(mgroup.nitdoc_name, mgroup)
end
for mmodule in doc.mmodules do
- doc.pages.add new MModulePage(mmodule.nitdoc_id, mmodule)
+ doc.pages.add new MModulePage(mmodule.nitdoc_name, mmodule)
end
for mclass in doc.mclasses do
- doc.pages.add new MClassPage(mclass.nitdoc_id, mclass)
+ doc.pages.add new MClassPage(mclass.nitdoc_name, mclass)
end
for mproperty in doc.mproperties do
- doc.pages.add new MPropertyPage(mproperty.nitdoc_id, mproperty)
+ doc.pages.add new MPropertyPage(mproperty.nitdoc_name, mproperty)
end
end
end
redef class MGroupPage
redef fun apply_structure(v, doc) do
if mentity.is_root then
- root.add new IntroArticle(mentity.mproject)
+ root.add_child new IntroArticle(mentity.mproject)
else
- root.add new IntroArticle(mentity)
+ root.add_child new IntroArticle(mentity)
end
var concerns = self.concerns
if concerns == null or concerns.is_empty then return
concerns.sort_with(v.concerns_sorter)
mentity.mproject.booster_rank = 0
mentity.booster_rank = 0
- root.add new ConcernsArticle(mentity, concerns)
+ root.add_child new ConcernsArticle(mentity, concerns)
for mentity in concerns do
if mentity isa MModule then
- root.add new DefinitionArticle(mentity)
+ root.add_child new DefinitionArticle(mentity)
else
- root.add new ConcernSection(mentity)
+ root.add_child new ConcernSection(mentity)
end
end
end
redef class MModulePage
redef fun apply_structure(v, doc) do
- root.add new IntroArticle(mentity)
+ root.add_child new IntroArticle(mentity)
var concerns = self.concerns
if concerns == null or concerns.is_empty then return
# FIXME avoid diff
mentity.mgroup.mproject.booster_rank = 0
mentity.mgroup.booster_rank = 0
mentity.booster_rank = 0
- root.add new ConcernsArticle(mentity, concerns)
+ root.add_child new ConcernsArticle(mentity, concerns)
# reference list
for mentity in concerns do
var section = new ConcernSection(mentity)
var article = new DefinitionArticle(mclass)
var mclassdefs = mclassdefs_for(mclass).to_a
if not mclassdefs.has(mclass.intro) then
- article.add(new DefinitionArticle(mclass.intro))
+ article.add_child(new DefinitionArticle(mclass.intro))
end
doc.mainmodule.linearize_mclassdefs(mclassdefs)
for mclassdef in mclassdefs do
- article.add(new DefinitionArticle(mclassdef))
+ article.add_child(new DefinitionArticle(mclassdef))
end
- section.add article
+ section.add_child article
end
end
- root.add section
+ root.add_child section
end
end
redef class MClassPage
redef fun apply_structure(v, doc) do
- root.add new IntroArticle(mentity)
+ root.add_child new IntroArticle(mentity)
var concerns = self.concerns
if concerns == null or concerns.is_empty then return
# FIXME diff hack
mentity.intro_mmodule.mgroup.mproject.booster_rank = 0
mentity.intro_mmodule.mgroup.booster_rank = 0
mentity.intro_mmodule.booster_rank = 0
- root.add new ConcernsArticle(mentity, concerns)
+ root.add_child new ConcernsArticle(mentity, concerns)
for mentity in concerns do
var section = new ConcernSection(mentity)
if mentity isa MModule then
v.name_sorter.sort(group)
for mprop in group do
for mpropdef in mpropdefs_for(mprop, mentity) do
- section.add new DefinitionArticle(mpropdef)
+ section.add_child new DefinitionArticle(mpropdef)
end
end
end
end
- root.add section
+ root.add_child section
end
end
redef class MPropertyPage
redef fun apply_structure(v, doc) do
- root.add new IntroArticle(mentity)
+ root.add_child new IntroArticle(mentity)
var concerns = self.concerns
if concerns == null or concerns.is_empty then return
# FIXME diff hack
mentity.intro.mclassdef.mmodule.mgroup.mproject.booster_rank = 0
mentity.intro.mclassdef.mmodule.mgroup.booster_rank = 0
mentity.intro.mclassdef.mmodule.booster_rank = 0
- root.add new ConcernsArticle(mentity, concerns)
+ root.add_child new ConcernsArticle(mentity, concerns)
for mentity in concerns do
var section = new ConcernSection(mentity)
if mentity isa MModule then
var mpropdefs = mpropdefs_for(mentity).to_a
v.name_sorter.sort(mpropdefs)
for mpropdef in mpropdefs do
- section.add new DefinitionArticle(mpropdef)
+ section.add_child new DefinitionArticle(mpropdef)
end
end
- root.add section
+ root.add_child section
end
end
# HTML templates used by Nitdoc to generate API documentation
# Pages are assembled using `Template`
-module doc_templates
+module html_components
+import doc_base
import template
import json::static
-# A documentation page
-class TplPage
- super Template
-
- # The unescaped page title to put in the HTML header.
- var title: String is writable, noinit
-
- # Page url
- var url: String is writable, noinit
-
- # Directory where css, js and other assets can be found
- var shareurl: String is writable, noinit
-
- # Attributes of the body tag element
- var body_attrs = new Array[TagAttribute]
-
- # Top menu template if any
- var topmenu: TplTopMenu is writable, noinit
-
- # Sidebar template if any
- var sidebar: nullable TplSidebar = null is writable
-
- # Content of the page in form a TplSection
- var sections = new Array[TplSection]
-
- # Footer content if any
- var footer: nullable Writable = null is writable
-
- # JS scripts to append at the end of the body
- var scripts = new Array[TplScript]
-
- # Add a section to this page
- fun add_section(section: TplSection) do
- sections.add section
- end
-
- # Render the html header
- private fun render_head do
- var css = (self.shareurl / "css").html_escape
- var vendors = (self.shareurl / "vendors").html_escape
-
- addn "<!DOCTYPE html>"
- addn "<head>"
- addn " <meta charset='utf-8'/>"
- addn " <!--link rel='stylesheet' href='{css}/Nitdoc.UI.css' type='text/css'/-->"
- addn " <link rel='stylesheet' href='{vendors}/bootstrap/css/bootstrap.min.css'/>"
- addn " <link rel='stylesheet' href='{css}/nitdoc.bootstrap.css'/>"
- addn " <link rel='stylesheet' href='{css}/nitdoc.css'/>"
- addn " <link rel='stylesheet' href='{css}/Nitdoc.QuickSearch.css'/>"
- addn " <link rel='stylesheet' href='{css}/Nitdoc.ModalBox.css'/>"
- addn " <link rel='stylesheet' href='{css}/Nitdoc.GitHub.css'/>"
- addn " <title>{title.html_escape}</title>"
- addn "</head>"
- add "<body"
- for attr in body_attrs do add attr
- addn ">"
- end
-
- # Render the topmenu template
- private fun render_topmenu do
- addn " <div class='row'>"
- add topmenu
- addn " </div>"
- end
-
- # Render the sidebar
- # Sidebar is automatically populated with a summary of all sections
- fun render_sidebar do
- if sidebar == null then return
- var summary = new TplSummary.with_order(0)
- for section in sections do
- section.render_summary summary
- end
- sidebar.boxes.add summary
- add sidebar.as(not null)
- end
- # Render the footer and content
- private fun render_content do
- for section in sections do add section
- if footer != null then
- addn "<div class='well footer'>"
- add footer.as(not null)
- addn "</div>"
- end
- end
-
- # Render JS scripts
- private fun render_footer do
- var vendors = (self.shareurl / "vendors").html_escape
- var js = (self.shareurl / "js").html_escape
-
- addn "<script src='{vendors}/jquery/jquery-1.11.1.min.js'></script>"
- addn "<script src='{vendors}/jquery/jquery-ui-1.10.4.custom.min.js'></script>"
- addn "<script src='{vendors}/bootstrap/js/bootstrap.min.js'></script>"
- addn "<script data-main='{js}/nitdoc' src='{js}/lib/require.js'></script>"
- for script in scripts do add script
- addn """<script>
- $(function () {
- $("[data-toggle='tooltip']").tooltip();
- $("[data-toggle='popover']").popover();
- });
- </script>"""
- addn "</body>"
- addn "</html>"
- end
-
- # Render the whole page
- redef fun rendering do
- render_head
- addn "<div class='container-fluid'>"
- render_topmenu
- addn " <div class='row' id='content'>"
- if sidebar != null then
- addn "<div class='col col-xs-3 col-lg-2'>"
- render_sidebar
- addn "</div>"
- addn "<div class='col col-xs-9 col-lg-10' data-spy='scroll' data-target='.summary'>"
- render_content
- addn "</div>"
- else
- addn "<div class='col col-xs-12'>"
- render_content
- addn "</div>"
- end
- addn " </div>"
- addn "</div>"
- render_footer
- end
-end
-
#########################
# general layout elements
#########################
var tpl = new Template
tpl.add "<li"
if is_active then
- tpl.add " class='active'"
+ tpl.add " class=\"active\""
end
tpl.add ">"
tpl.add content
addn "\})();"
end
end
-
# See the License for the specific language governing permissions and
# limitations under the License.
-# Nitdoc model template parts generation
-module doc_model
+# HTML templates for Nit model MEntities.
+module html_model
-import model_utils
+import doc_base
import doc_down
-import doc_templates
+import html_components
import ordered_tree
-import model_ext
redef class Location
# Github url based on this location
end
redef class MEntity
- # HTML-escaped name.
- fun nitdoc_name: String do return name.html_escape
-
# ID used as a HTML unique ID and in file names.
#
# **Must** match the following (POSIX ERE) regular expression:
end
redef class MClassDef
- redef fun nitdoc_name do return mclass.nitdoc_name
redef var nitdoc_id = "{mmodule.nitdoc_id}__{name.to_cmangle}" is lazy
redef fun nitdoc_url do return "{mclass.nitdoc_url}#{nitdoc_id}"
end
redef class MPropDef
- redef fun nitdoc_name do return mproperty.nitdoc_name
redef var nitdoc_id = "{mclassdef.nitdoc_id}__{name.to_cmangle}" is lazy
redef fun nitdoc_url do return "{mproperty.nitdoc_url}#{nitdoc_id}"
--- /dev/null
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Introduces templates that compose the documentation HTML rendering.
+module html_templates
+
+import html_model
+
+# Renders the page as HTML.
+redef class DocPage
+ super Template
+
+ # Page url.
+ var html_url: String is writable, noinit
+
+ # Directory where css, js and other assets can be found.
+ var shareurl: String is writable, noinit
+
+ # Attributes of the body tag element.
+ var body_attrs = new Array[TagAttribute]
+
+ # Top menu template if any.
+ var topmenu: TplTopMenu is writable, noinit
+
+ # Sidebar template if any.
+ var sidebar: nullable TplSidebar = null is writable
+
+ # Content of the page in form a TplSection.
+ # TODO remove when other templates are migrated.
+ var sections = new Array[TplSection]
+
+ # Footer content if any.
+ var footer: nullable Writable = null is writable
+
+ # JS scripts to append at the end of the body
+ var scripts = new Array[TplScript]
+
+ # Adds a section to this page.
+ # TODO remove when other templates are migrated.
+ fun add_section(section: TplSection) do
+ sections.add section
+ end
+
+ # Renders the html `<head>`.
+ private fun render_head do
+ var css = (self.shareurl / "css").html_escape
+ var vendors = (self.shareurl / "vendors").html_escape
+
+ addn "<!DOCTYPE html>"
+ addn "<head>"
+ addn " <meta charset='utf-8'/>"
+ addn " <!--link rel='stylesheet' href='{css}/Nitdoc.UI.css' type='text/css'/-->"
+ addn " <link rel='stylesheet' href='{vendors}/bootstrap/css/bootstrap.min.css'/>"
+ addn " <link rel='stylesheet' href='{css}/nitdoc.bootstrap.css'/>"
+ addn " <link rel='stylesheet' href='{css}/nitdoc.css'/>"
+ addn " <link rel='stylesheet' href='{css}/Nitdoc.QuickSearch.css'/>"
+ addn " <link rel='stylesheet' href='{css}/Nitdoc.ModalBox.css'/>"
+ addn " <link rel='stylesheet' href='{css}/Nitdoc.GitHub.css'/>"
+ addn " <title>{title.html_escape}</title>"
+ addn "</head>"
+ add "<body"
+ for attr in body_attrs do add attr
+ addn ">"
+ end
+
+ # Renders the topmenu template.
+ private fun render_topmenu do
+ addn " <div class='row'>"
+ add topmenu
+ addn " </div>"
+ end
+
+ # Renders the sidebar template.
+ #
+ # Sidebar is automatically populated with a summary of all sections
+ # TODO remove summary generation when other templates are migrated.
+ private fun render_sidebar do
+ if sidebar == null then return
+ var summary = new TplSummary.with_order(0)
+ for section in sections do
+ section.render_summary summary
+ end
+ sidebar.boxes.add summary
+ add sidebar.as(not null)
+ end
+
+ # Renders the footer and content.
+ private fun render_content do
+ for section in sections do add section
+ if footer != null then
+ addn "<div class='well footer'>"
+ add footer.as(not null)
+ addn "</div>"
+ end
+ end
+
+ # Render JS scripts
+ private fun render_footer do
+ var vendors = (self.shareurl / "vendors").html_escape
+ var js = (self.shareurl / "js").html_escape
+
+ addn "<script src='{vendors}/jquery/jquery-1.11.1.min.js'></script>"
+ addn "<script src='{vendors}/jquery/jquery-ui-1.10.4.custom.min.js'></script>"
+ addn "<script src='{vendors}/bootstrap/js/bootstrap.min.js'></script>"
+ addn "<script data-main='{js}/nitdoc' src='{js}/lib/require.js'></script>"
+ for script in scripts do add script
+ addn """<script>
+ $(function () {
+ $("[data-toggle='tooltip']").tooltip();
+ $("[data-toggle='popover']").popover();
+ });
+ </script>"""
+ addn "</body>"
+ addn "</html>"
+ end
+
+ # Render the whole page
+ redef fun rendering do
+ render_head
+ addn "<div class='container-fluid'>"
+ render_topmenu
+ addn " <div class='row' id='content'>"
+ if sidebar != null then
+ addn "<div class='col col-xs-3 col-lg-2'>"
+ render_sidebar
+ addn "</div>"
+ addn "<div class='col col-xs-9 col-lg-10' data-spy='scroll' data-target='.summary'>"
+ render_content
+ addn "</div>"
+ else
+ addn "<div class='col col-xs-12'>"
+ render_content
+ addn "</div>"
+ end
+ addn " </div>"
+ addn "</div>"
+ render_footer
+ end
+end