From: Alexandre Terrasa Date: Mon, 4 May 2015 14:43:59 +0000 (-0400) Subject: nitx: introduce doc page search X-Git-Tag: v0.7.5~29^2~7 X-Git-Url: http://nitlanguage.org nitx: introduce doc page search Signed-off-by: Alexandre Terrasa --- diff --git a/src/doc/doc_phases/doc_console.nit b/src/doc/doc_phases/doc_console.nit index a7ef6b1..c304dab 100644 --- a/src/doc/doc_phases/doc_console.nit +++ b/src/doc/doc_phases/doc_console.nit @@ -59,6 +59,7 @@ class Nitx fun help do print "\nCommands:" print "\tname\t\tlookup module, class and property with the corresponding 'name'" + print "\tdoc: \tdisplay the documentation page of 'namespace'" print "\t:h\t\tdisplay this help message" print "\t:q\t\tquit interactive mode" print "" @@ -110,6 +111,8 @@ interface NitxQuery return new NitxHelp else if query_string.has_prefix("comment:") then return new CommentQuery(query_string) + else if query_string.has_prefix("doc:") then + return new DocQuery(query_string) end return new CommentQuery("comment: {query_string}") end @@ -207,6 +210,56 @@ class CommentQuery end end +# A query to search a Nitdoc documentation page by its name. +class DocQuery + super MetaQuery + + redef fun perform(nitx, doc) do + var res = new Array[NitxMatch] + var name = args.first + for page in doc.pages do + if name == "*" then # FIXME dev only + res.add new PageMatch(self, page) + else if page.title == name then + res.add new PageMatch(self, page) + else if page isa MEntityPage and page.mentity.cs_namespace == name then + res.add new PageMatch(self, page) + end + end + return res + end + + redef fun make_results(nitx, results) do + var len = results.length + # FIXME how to render the pager for one worded namespaces like "standard"? + if len == 1 then + var page = results.first.as(PageMatch).page + var pager = new Pager + pager.add page.write_to_string + pager.render + return page + else + return super + end + end +end + +# A match between a `DocPage` and a `MEntity`. +class PageMatch + super NitxMatch + + # `DocPage` matched. + var page: DocPage + + redef fun make_list_item do + var page = self.page + if page isa MEntityPage then + return page.mentity.cs_list_item + end + return " * {page.title}" + end +end + # A query that contains a nitx command. # # These commands are prefixed with `:` and are used to control the execution of diff --git a/src/nitx.nit b/src/nitx.nit index c1ce189..4c08b29 100644 --- a/src/nitx.nit +++ b/src/nitx.nit @@ -17,6 +17,7 @@ # Features: # # * Display comment from name/namespace +# * Display documentation page from Nitdoc in console module nitx import modelbuilder