From 01bd5abcf98c0c09561186ce0acbeff451b730d7 Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Tue, 29 Aug 2017 19:52:35 -0400 Subject: [PATCH] src/doc_commands: merge Article and Comment commands Signed-off-by: Alexandre Terrasa --- src/doc/doc_commands.nit | 20 +++++--------------- src/doc/doc_phases/doc_console.nit | 32 -------------------------------- src/doc/doc_phases/doc_readme.nit | 2 +- src/doc/test_doc_commands.nit | 16 ++++++++-------- src/web/api_docdown.nit | 30 ++++++++++++------------------ 5 files changed, 26 insertions(+), 74 deletions(-) diff --git a/src/doc/doc_commands.nit b/src/doc/doc_commands.nit index e276057..208738b 100644 --- a/src/doc/doc_commands.nit +++ b/src/doc/doc_commands.nit @@ -23,8 +23,8 @@ module doc_commands class DocCommandParser # List of allowed command names for this parser - var allowed_commands: Array[String] = [ "doc", "comment", "list", "param", - "return", "new", "call", "code", "graph"] is writable + var allowed_commands: Array[String] = [ "doc", "list", "param", "return", + "new", "call", "code", "graph"] is writable # Parse `string` as a DocCommand # @@ -33,7 +33,7 @@ class DocCommandParser # ~~~ # var parser = new DocCommandParser # - # var command = parser.parse("comment: core::Array") + # var command = parser.parse("doc: core::Array") # assert command isa CommentCommand # assert command.arg == "core::Array" # @@ -102,8 +102,7 @@ class DocCommandParser # # You must redefine this method to add new custom commands. fun new_command(name, string: String): nullable DocCommand do - if name == "doc" then return new ArticleCommand(string) - if name == "comment" then return new CommentCommand(string) + if name == "doc" then return new CommentCommand(string) if name == "list" then return new ListCommand(string) if name == "param" then return new ParamCommand(string) if name == "return" then return new ReturnCommand(string) @@ -208,19 +207,10 @@ end # A `DocCommand` that includes the documentation article of a `MEntity`. # # Syntax: `doc: MEntity::name`. -class ArticleCommand - super DocCommand - - redef var name = "doc" -end - -# A `DocCommand` that includes the MDoc of a `MEntity`. -# -# Syntax: `comment: MEntity::name`. class CommentCommand super DocCommand - redef var name = "comment" + redef var name = "doc" end # A `DocCommand` that includes a list of something. diff --git a/src/doc/doc_phases/doc_console.nit b/src/doc/doc_phases/doc_console.nit index 92b1a36..6a5d045 100644 --- a/src/doc/doc_phases/doc_console.nit +++ b/src/doc/doc_phases/doc_console.nit @@ -280,38 +280,6 @@ redef class CallCommand end end -# A query to search a Nitdoc documentation page by its name. -redef class ArticleCommand - redef fun perform(nitx, doc) do - var res = new Array[NitxMatch] - var name = arg - for page in doc.pages.values 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, suggest) do - var len = results.length - # FIXME how to render the pager for one worded namespaces like "core"? - 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 diff --git a/src/doc/doc_phases/doc_readme.nit b/src/doc/doc_phases/doc_readme.nit index f08f64d..a31f107 100644 --- a/src/doc/doc_phases/doc_readme.nit +++ b/src/doc/doc_phases/doc_readme.nit @@ -244,7 +244,7 @@ redef class DocCommand fun render(v: ReadmeMdEmitter, token: TokenWikiLink) is abstract end -redef class ArticleCommand +redef class CommentCommand redef fun render(v, token) do var string = args.first var res = v.find_mentities(string) diff --git a/src/doc/test_doc_commands.nit b/src/doc/test_doc_commands.nit index 712d4cd..82f5e7c 100644 --- a/src/doc/test_doc_commands.nit +++ b/src/doc/test_doc_commands.nit @@ -64,7 +64,7 @@ class TestDocCommandParser fun test_no_opts is test do var command = parser.parse("doc: core::Array") - assert command isa ArticleCommand + assert command isa CommentCommand assert command.name == "doc" assert command.arg == "core::Array" assert parser.errors.is_empty @@ -72,7 +72,7 @@ class TestDocCommandParser fun test_opts_empty is test do var command = parser.parse("doc: core::Array | ") - assert command isa ArticleCommand + assert command isa CommentCommand assert command.name == "doc" assert command.arg == "core::Array" assert parser.errors.is_empty @@ -80,7 +80,7 @@ class TestDocCommandParser fun test_1_opt is test do var command = parser.parse("doc: core::Array | opt1: val1 ") - assert command isa ArticleCommand + assert command isa CommentCommand assert command.name == "doc" assert command.arg == "core::Array" assert command.opts.length == 1 @@ -90,7 +90,7 @@ class TestDocCommandParser fun test_2_opts is test do var command = parser.parse("doc: core::Array | opt1: val1 , opt2: val2, ") - assert command isa ArticleCommand + assert command isa CommentCommand assert command.name == "doc" assert command.arg == "core::Array" assert command.opts.length == 2 @@ -101,7 +101,7 @@ class TestDocCommandParser fun test_empty_opt_name is test do var command = parser.parse("doc: core::Array | opt1: val1 , :") - assert command isa ArticleCommand + assert command isa CommentCommand assert command.name == "doc" assert command.arg == "core::Array" assert command.opts.length == 1 @@ -111,7 +111,7 @@ class TestDocCommandParser fun test_empty_opt_value is test do var command = parser.parse("doc: core::Array | opt1: , opt2: val2, ") - assert command isa ArticleCommand + assert command isa CommentCommand assert command.name == "doc" assert command.arg == "core::Array" assert command.opts.length == 2 @@ -122,7 +122,7 @@ class TestDocCommandParser fun test_empty_opt_value2 is test do var command = parser.parse("doc: core::Array | opt1") - assert command isa ArticleCommand + assert command isa CommentCommand assert command.name == "doc" assert command.arg == "core::Array" assert command.opts.length == 1 @@ -132,7 +132,7 @@ class TestDocCommandParser fun test_empty_opt_value3 is test do var command = parser.parse("doc: core::Array | opt1, opt2: val2") - assert command isa ArticleCommand + assert command isa CommentCommand assert command.name == "doc" assert command.arg == "core::Array" assert command.opts.length == 2 diff --git a/src/web/api_docdown.nit b/src/web/api_docdown.nit index e2721a4..80c50c7 100644 --- a/src/web/api_docdown.nit +++ b/src/web/api_docdown.nit @@ -231,7 +231,7 @@ redef class DocCommand end end -redef class ArticleCommand +redef class CommentCommand redef fun render(v, token, model) do var name = arg var mentity = v.find_mentity(model, name) @@ -242,25 +242,19 @@ redef class ArticleCommand return end v.add "

" - v.write_mentity_link(mentity) - v.add " - " - v.emit_text mdoc.synopsis + if not opts.has_key("no-link") then + v.write_mentity_link(mentity) + end + if not opts.has_key("no-link") and not opts.has_key("no-synopsis") then + v.add " - " + end + if not opts.has_key("no-synopsis") then + v.emit_text mdoc.html_synopsis.write_to_string + end v.add "

" - v.add v.processor.process(mdoc.comment).write_to_string - end -end - -redef class CommentCommand - redef fun render(v, token, model) do - var name = arg - var mentity = v.find_mentity(model, name) - if mentity == null then return - var mdoc = mentity.mdoc_or_fallback - if mdoc == null then - v.write_warning("no MDoc for mentity `{name}`") - return + if not opts.has_key("no-comment") then + v.add v.processor.process(mdoc.comment).write_to_string end - v.add v.processor.process(mdoc.comment).write_to_string end end -- 1.7.9.5