Merge: src/doc/commands: clean commands hierarchy
authorJean Privat <jean@pryen.org>
Tue, 26 Jun 2018 13:30:47 +0000 (09:30 -0400)
committerJean Privat <jean@pryen.org>
Tue, 26 Jun 2018 13:30:47 +0000 (09:30 -0400)
This PR does some cleaning around commands hierarchy to prepare for the merge with new-markdown (#2720).

Pull-Request: #2723

131 files changed:
lib/html/bootstrap.nit
src/catalog/catalog.nit
src/catalog/catalog_json.nit [deleted file]
src/doc/api/api_base.nit
src/doc/commands/commands_base.nit
src/doc/commands/commands_catalog.nit
src/doc/commands/commands_docdown.nit
src/doc/commands/commands_http.nit
src/doc/commands/commands_ini.nit
src/doc/commands/commands_main.nit
src/doc/commands/commands_model.nit
src/doc/commands/commands_parser.nit
src/doc/doc_down.nit [deleted file]
src/doc/static/static_base.nit
src/doc/static/static_cards.nit
src/doc/templates/html_commands.nit [moved from src/doc/commands/commands_html.nit with 65% similarity]
src/doc/templates/html_model.nit [moved from src/doc/templates/templates_html.nit with 64% similarity]
src/doc/templates/json_commands.nit [moved from src/doc/commands/commands_json.nit with 91% similarity]
src/doc/templates/json_model.nit [moved from src/doc/templates/templates_json.nit with 82% similarity]
src/doc/templates/md_commands.nit [moved from src/doc/commands/commands_md.nit with 79% similarity]
src/doc/templates/term_model.nit [moved from src/doc/templates/templates_term.nit with 99% similarity]
src/doc/templates/tests/test_html_commands.nit [moved from src/doc/commands/tests/test_commands_html.nit with 98% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_ancestors.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_ancestors.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_call.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_call.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_children.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_children.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_comment.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_comment.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_descendants.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_descendants.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_entity.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_entity.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_features.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_features.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_ini_clone.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_clone.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_ini_contrib_file.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_contrib_file.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_ini_contrib_file_content.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_contrib_file_content.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_ini_contributors.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_contributors.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_ini_desc.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_desc.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_ini_git.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_git.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_ini_issues.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_issues.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_ini_license.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_license.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_ini_license_file.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_license_file.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_ini_license_file_content.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_license_file_content.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_ini_maintainer.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_ini_maintainer.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_lin.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_lin.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_link.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_link.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_main_compile.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_main_compile.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_mains.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_mains.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_man_options.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_man_options.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_man_synopsis.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_man_synopsis.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_mentities.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_mentities.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_new.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_new.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_param.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_param.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_parents.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_parents.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_return.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_return.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_search.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_search.res with 100% similarity]
src/doc/templates/tests/test_html_commands.sav/test_cmd_testing.res [moved from src/doc/commands/tests/test_commands_html.sav/test_cmd_testing.res with 100% similarity]
src/doc/templates/tests/test_json_commands.nit [moved from src/doc/commands/tests/test_commands_json.nit with 99% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_ancestors.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_ancestors.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_call.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_call.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_children.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_children.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_comment.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_comment.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_descendants.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_descendants.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_entity.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_entity.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_features.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_features.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_ini_clone.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_ini_clone.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_ini_contrib_file.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_ini_contrib_file.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_ini_contrib_file_content.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_ini_contrib_file_content.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_ini_contributors.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_ini_contributors.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_ini_desc.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_ini_desc.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_ini_git.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_ini_git.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_ini_issues.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_ini_issues.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_ini_license.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_ini_license.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_ini_license_file.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_ini_license_file.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_ini_license_file_content.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_ini_license_file_content.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_ini_maintainer.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_ini_maintainer.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_lin.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_lin.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_link.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_link.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_main_compile.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_main_compile.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_mains.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_mains.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_man_options.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_man_options.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_man_synopsis.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_man_synopsis.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_mentities.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_mentities.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_new.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_new.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_param.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_param.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_parents.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_parents.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_return.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_return.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_search.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_search.res with 100% similarity]
src/doc/templates/tests/test_json_commands.sav/test_cmd_testing.res [moved from src/doc/commands/tests/test_commands_json.sav/test_cmd_testing.res with 100% similarity]
src/doc/templates/tests/test_json_model.nit [moved from src/doc/templates/tests/test_templates_json.nit with 98% similarity]
src/doc/templates/tests/test_json_model.sav/test_classdefs_to_full_json.res [moved from src/doc/templates/tests/test_templates_json.sav/test_classdefs_to_full_json.res with 100% similarity]
src/doc/templates/tests/test_json_model.sav/test_classes_to_full_json.res [moved from src/doc/templates/tests/test_templates_json.sav/test_classes_to_full_json.res with 100% similarity]
src/doc/templates/tests/test_json_model.sav/test_groups_to_full_json.res [moved from src/doc/templates/tests/test_templates_json.sav/test_groups_to_full_json.res with 100% similarity]
src/doc/templates/tests/test_json_model.sav/test_modules_to_full_json.res [moved from src/doc/templates/tests/test_templates_json.sav/test_modules_to_full_json.res with 100% similarity]
src/doc/templates/tests/test_json_model.sav/test_packages_to_full_json.res [moved from src/doc/templates/tests/test_templates_json.sav/test_packages_to_full_json.res with 100% similarity]
src/doc/templates/tests/test_json_model.sav/test_propdefs_to_full_json.res [moved from src/doc/templates/tests/test_templates_json.sav/test_propdefs_to_full_json.res with 100% similarity]
src/doc/templates/tests/test_json_model.sav/test_props_to_full_json.res [moved from src/doc/templates/tests/test_templates_json.sav/test_props_to_full_json.res with 100% similarity]
src/doc/templates/tests/test_json_model.sav/test_refs_to_full_json.res [moved from src/doc/templates/tests/test_templates_json.sav/test_refs_to_full_json.res with 100% similarity]
src/doc/templates/tests/test_md_commands.nit [moved from src/doc/commands/tests/test_commands_md.nit with 98% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_ancestors.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_ancestors.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_call.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_call.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_children.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_children.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_comment.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_comment.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_descendants.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_descendants.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_entity.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_entity.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_features.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_features.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_ini_clone.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_ini_clone.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_ini_contrib_file.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_ini_contrib_file.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_ini_contrib_file_content.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_ini_contrib_file_content.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_ini_contributors.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_ini_contributors.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_ini_desc.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_ini_desc.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_ini_git.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_ini_git.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_ini_issues.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_ini_issues.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_ini_license.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_ini_license.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_ini_license_file.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_ini_license_file.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_ini_license_file_content.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_ini_license_file_content.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_ini_maintainer.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_ini_maintainer.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_lin.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_lin.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_link.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_link.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_main_compile.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_main_compile.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_mains.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_mains.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_man_options.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_man_options.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_man_synopsis.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_man_synopsis.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_mentities.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_mentities.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_new.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_new.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_param.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_param.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_parents.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_parents.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_return.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_return.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_search.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_search.res with 100% similarity]
src/doc/templates/tests/test_md_commands.sav/test_cmd_testing.res [moved from src/doc/commands/tests/test_commands_md.sav/test_cmd_testing.res with 100% similarity]
src/doc/term/term.nit
src/frontend/parse_examples.nit
src/model/mdoc.nit
src/nitcatalog.nit
src/nitweb.nit

index cc3d6e2..3e12dd7 100644 (file)
@@ -72,7 +72,7 @@ class Link
        redef fun rendering do
                add "<a{render_css_classes} href=\"{href}\""
                var title = self.title
-               if title != null then add " title=\"{title.write_to_string}\""
+               if title != null then add " title=\"{title.html_escape}\""
                add ">{text}</a>"
        end
 end
index 6a12238..140278e 100644 (file)
@@ -165,24 +165,6 @@ class Person
                return email.md5.to_lower
        end
 
-       # Return a full-featured link to a person
-       fun to_html: String
-       do
-               var res = ""
-               var e = name.html_escape
-               var page = self.page
-               if page != null then
-                       res += "<a href=\"{page.html_escape}\">"
-               end
-               var gravatar = self.gravatar
-               if gravatar != null then
-                       res += "<img src=\"https://secure.gravatar.com/avatar/{gravatar}?size=20&amp;default=retro\">&nbsp;"
-               end
-               res += e
-               if page != null then res += "</a>"
-               return res
-       end
-
        # The standard representation of a person.
        #
        # ~~~
diff --git a/src/catalog/catalog_json.nit b/src/catalog/catalog_json.nit
deleted file mode 100644 (file)
index da1bcfc..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-# 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.
-
-# Translate catalog entities to JSON
-module catalog_json
-
-import catalog
-
-redef class MPackageMetadata
-       serialize
-
-       redef fun core_serialize_to(v) do
-               super
-               v.serialize_attribute("license", license)
-               v.serialize_attribute("maintainers", maintainers)
-               v.serialize_attribute("contributors", contributors)
-               v.serialize_attribute("tags", tags)
-               v.serialize_attribute("tryit", tryit)
-               v.serialize_attribute("apk", apk)
-               v.serialize_attribute("homepage", homepage)
-               v.serialize_attribute("browse", browse)
-               v.serialize_attribute("git", git)
-               v.serialize_attribute("issues", issues)
-               v.serialize_attribute("first_date", first_date)
-               v.serialize_attribute("last_date", last_date)
-       end
-end
-
-# Catalog statistics
-redef class CatalogStats
-       serialize
-
-       redef fun core_serialize_to(v) do
-               super
-               v.serialize_attribute("packages", packages)
-               v.serialize_attribute("maintainers", maintainers)
-               v.serialize_attribute("contributors", contributors)
-               v.serialize_attribute("tags", tags)
-               v.serialize_attribute("modules", modules)
-               v.serialize_attribute("classes", classes)
-               v.serialize_attribute("methods", methods)
-               v.serialize_attribute("loc", loc)
-       end
-end
-
-# MPackage statistics for the catalog
-redef class MPackageStats
-       serialize
-
-       redef fun core_serialize_to(v) do
-               super
-               v.serialize_attribute("mmodules", mmodules)
-               v.serialize_attribute("mclasses", mclasses)
-               v.serialize_attribute("mmethods", mmethods)
-               v.serialize_attribute("loc", loc)
-               v.serialize_attribute("errors", errors)
-               v.serialize_attribute("warnings", warnings)
-               v.serialize_attribute("warnings_per_kloc", warnings_per_kloc)
-               v.serialize_attribute("documentation_score", documentation_score)
-               v.serialize_attribute("commits", commits)
-               v.serialize_attribute("score", score)
-       end
-end
-
-redef class Person
-       serialize
-
-       redef fun core_serialize_to(v) do
-               super
-               v.serialize_attribute("name", name)
-               v.serialize_attribute("email", email)
-               v.serialize_attribute("gravatar", gravatar)
-       end
-end
index 4c3db90..95a6ff0 100644 (file)
@@ -21,8 +21,9 @@ import popcorn::pop_repos
 import popcorn::pop_json
 
 import commands::commands_http
-import commands::commands_json
-import commands::commands_html
+
+import templates::json_commands
+import templates::html_commands
 
 # Nitweb config file.
 class NitwebConfig
index 822b509..bde3f8e 100644 (file)
@@ -24,7 +24,6 @@
 module commands_base
 
 import model::model_index
-import catalog
 
 # Documentation command
 #
index 90f631a..f7bce8e 100644 (file)
@@ -16,6 +16,7 @@
 module commands_catalog
 
 import commands_model
+import catalog
 
 # A DocCommand based on a Catalog
 abstract class CmdCatalog
index fe7345e..ece9dae 100644 (file)
 # Doc down related queries
 module commands_docdown
 
-import commands::commands_parser
-import commands::commands_html
-
-intrude import doc_down
-intrude import markdown::wikilinks
+import templates::md_commands
+import markdown
 
 # Retrieve the MDoc summary
 #
@@ -28,7 +25,7 @@ class CmdSummary
        super CmdComment
 
        # Markdown processor used to parse the headlines
-       var markdown_processor: nullable MarkdownProcessor = null is optional, writable
+       var markdown_processor: MarkdownProcessor is writable
 
        # Resulting summary
        #
@@ -40,12 +37,6 @@ class CmdSummary
                if not res isa CmdSuccess then return res
                var mentity = self.mentity.as(not null)
 
-               var markdown_processor = self.markdown_processor
-               if markdown_processor == null then
-                       markdown_processor = new MarkdownProcessor
-                       self.markdown_processor = markdown_processor
-               end
-
                var mdoc = self.mdoc
                if mdoc == null then
                        mdoc = if fallback then mentity.mdoc_or_fallback else mentity.mdoc
@@ -61,103 +52,3 @@ class CmdSummary
                return res
        end
 end
-
-# Custom Markdown processor able to process doc commands
-class CmdDecorator
-       super NitdocDecorator
-
-       redef type PROCESSOR: CmdMarkdownProcessor
-
-       # Model used by wikilink commands to find entities
-       var model: Model
-
-       # Filter to apply if any
-       var filter: nullable ModelFilter
-
-       redef fun add_span_code(v, buffer, from, to) do
-               var text = new FlatBuffer
-               buffer.read(text, from, to)
-               var name = text.write_to_string
-               name = name.replace("nullable ", "")
-               var mentity = try_find_mentity(name)
-               if mentity == null then
-                       super
-               else
-                       v.add "<code>"
-                       v.emit_text mentity.html_link.write_to_string
-                       v.add "</code>"
-               end
-       end
-
-       private fun try_find_mentity(text: String): nullable MEntity do
-               var mentity = model.mentity_by_full_name(text, filter)
-               if mentity != null then return mentity
-
-               var mentities = model.mentities_by_name(text, filter)
-               if mentities.is_empty then
-                       return null
-               else if mentities.length > 1 then
-                       # TODO smart resolve conflicts
-               end
-               return mentities.first
-       end
-
-       redef fun add_wikilink(v, token) do
-               v.render_wikilink(token, model)
-       end
-end
-
-# Same as `InlineDecorator` but with wikilink commands handling
-class CmdInlineDecorator
-       super InlineDecorator
-
-       redef type PROCESSOR: CmdMarkdownProcessor
-
-       # Model used by wikilink commands to find entities
-       var model: Model
-
-       redef fun add_wikilink(v, token) do
-               v.render_wikilink(token, model)
-       end
-end
-
-# Custom MarkdownEmitter for commands
-class CmdMarkdownProcessor
-       super MarkdownProcessor
-
-       # Parser used to process doc commands
-       var parser: CommandParser
-
-       # Render a wikilink
-       fun render_wikilink(token: TokenWikiLink, model: Model) do
-               var link = token.link
-               if link == null then return
-               var name = token.name
-               if name != null then link = "{name} | {link}"
-
-               var command = parser.parse(link.write_to_string)
-               var error = parser.error
-
-               if error isa CmdError then
-                       emit_text error.to_html.write_to_string
-                       return
-               end
-               if error isa CmdWarning then
-                       emit_text error.to_html.write_to_string
-               end
-               add command.as(not null).to_html
-       end
-end
-
-redef class Text
-       # Read `self` between `nstart` and `nend` (excluded) and writte chars to `out`.
-       private fun read(out: FlatBuffer, nstart, nend: Int): Int do
-               var pos = nstart
-               while pos < length and pos < nend do
-                       out.add self[pos]
-                       pos += 1
-               end
-               if pos == length then return -1
-               return pos
-       end
-end
index cc26f7f..c018ad2 100644 (file)
 # To be more generic, param names should be extracted as variables.
 module commands_http
 
-import commands
-import commands::commands_catalog
+import commands_catalog
+import commands_graph
+import commands_ini
+import commands_main
+import commands_usage
+
 import nitcorn::vararg_routes
 
 redef class DocCommand
index 9274fd0..df312c4 100644 (file)
@@ -14,7 +14,7 @@
 
 module commands_ini
 
-import doc::commands::commands_model
+import commands_model
 
 # Cmd that finds the ini file related to an `mentity`
 abstract class CmdIni
index 9533722..2b3e861 100644 (file)
@@ -14,7 +14,7 @@
 
 module commands_main
 
-import doc::commands::commands_model
+import commands_model
 
 # Cmd that finds the mains of an `mentity`
 class CmdMains
index abf5d7d..3a7215b 100644 (file)
 module commands_model
 
 import commands_base
-
-import model::model_collect
 import modelize
-import modelbuilder
-import htmlight
-import doc_down
 
 # Retrieve the MDoc related to a MEntity
 class CmdComment
@@ -47,7 +42,7 @@ class CmdComment
 
        # Format to render the comment
        #
-       # Can be one of `raw` or `html`.
+       # Can be one of `raw`, `html` or `md`.
        # Default is `raw`.
        var format = "raw" is optional, writable
 
@@ -74,10 +69,6 @@ class CmdComment
                var mdoc = self.mdoc
                if mdoc == null then return null
 
-               if format == "html" then
-                       if full_doc then return mdoc.html_documentation
-                       return mdoc.html_synopsis
-               end
                if full_doc then return mdoc.documentation
                return mdoc.synopsis
        end
@@ -427,10 +418,10 @@ end
 abstract class CmdCode
        super DocCommand
 
-       autoinit(model, modelbuilder, filter, format)
+       autoinit(model, filter, node, format)
 
-       # ModelBuilder used to get AST nodes
-       var modelbuilder: ModelBuilder
+       # AST node to display code from
+       var node: nullable ANode = null is optional, writable
 
        # Rendering format
        #
@@ -444,30 +435,11 @@ abstract class CmdCode
        var format = "raw" is optional, writable
 
        # Render `node` depending on the selected `format`
-       fun render_code(node: nullable ANode): nullable Writable do
-               if node == null then return null
-               if format == "html" then
-                       var hl = new CmdHtmlightVisitor
-                       hl.show_infobox = false
-                       hl.highlight_node node
-                       return hl.html
-               else if format == "ansi" then
-                       var hl = new AnsiHighlightVisitor
-                       hl.highlight_node node
-                       return hl.result
-               end
+       fun render_code(node: ANode): Writable do
                return node.location.text
        end
 end
 
-# Custom HtmlightVisitor for commands
-#
-# We create a new subclass so its behavior can be refined in clients without
-# breaking the main implementation.
-class CmdHtmlightVisitor
-       super HtmlightVisitor
-end
-
 # Cmd that finds the source code related to an `mentity`
 class CmdEntityCode
        super CmdEntity
@@ -475,8 +447,8 @@ class CmdEntityCode
 
        autoinit(model, modelbuilder, filter, mentity, mentity_name, format)
 
-       # AST node to return
-       var node: nullable ANode = null is optional, writable
+       # ModelBuilder used to get AST nodes from entities
+       var modelbuilder: ModelBuilder
 
        # Same as `CmdEntity::init_mentity`
        #
index c3e5118..52ec92b 100644 (file)
 # Used by both Nitx and the Markdown doc commands.
 module commands_parser
 
-import commands::commands_model
-import commands::commands_graph
-import commands::commands_usage
-import commands::commands_catalog
-import commands::commands_ini
-import commands::commands_main
+import commands_catalog
+import commands_graph
+import commands_ini
+import commands_main
+import commands_usage
 
 # Parse string commands to create DocQueries
 class CommandParser
diff --git a/src/doc/doc_down.nit b/src/doc/doc_down.nit
deleted file mode 100644 (file)
index f02b1fd..0000000
+++ /dev/null
@@ -1,251 +0,0 @@
-# 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.
-
-# Handle markdown formatting in Nit comments.
-module doc_down
-
-import markdown
-import htmlight
-private import parser_util
-
-redef class MDoc
-
-       # Synopsis HTML escaped.
-       var synopsis: String is lazy do return content.first.html_escape
-
-       # Comment without synopsis HTML escaped
-       var comment: String is lazy do
-               var lines = content.to_a
-               if not lines.is_empty then lines.shift
-               return lines.join("\n")
-       end
-
-       # Full comment HTML escaped.
-       var documentation: String is lazy do return content.join("\n")
-
-       private var markdown_proc: MarkdownProcessor is lazy, writable do
-               return original_mentity.as(not null).model.nitdoc_md_processor
-       end
-
-       private var inline_proc: MarkdownProcessor is lazy, writable do
-               return original_mentity.as(not null).model.nitdoc_inline_processor
-       end
-
-       # Renders the synopsis as a HTML comment block.
-       var html_synopsis: Writable is lazy do
-               var res = new Template
-               var syn = inline_proc.process(content.first)
-               res.add "<span class=\"synopsys nitdoc\">{syn}</span>"
-               return res
-       end
-
-       # Renders the synopsis as a HTML comment block.
-       var md_synopsis: Writable is lazy do
-               if content.is_empty then return ""
-               return content.first
-       end
-
-       # Renders the comment without the synopsis as a HTML comment block.
-       var html_comment: Writable is lazy do
-               var lines = content.to_a
-               if not lines.is_empty then lines.shift
-               return lines_to_html(lines)
-       end
-
-       #
-       var md_comment: Writable is lazy do
-               if content.is_empty then return ""
-               var lines = content.to_a
-               lines.shift
-               return lines.join("\n")
-       end
-
-       # Renders the synopsis and the comment as a HTML comment block.
-       var html_documentation: Writable is lazy do return lines_to_html(content.to_a)
-
-       # Renders the synopsis and the comment as a HTML comment block.
-       var md_documentation: Writable is lazy do return lines_to_md(content.to_a)
-
-       # Renders markdown line as a HTML comment block.
-       private fun lines_to_html(lines: Array[String]): Writable do
-               var res = new Template
-               var decorator = markdown_proc.decorator.as(NitdocDecorator)
-               decorator.current_mdoc = self
-               res.add "<div class=\"nitdoc\">"
-               # do not use DocUnit as synopsys
-               if not lines.is_empty then
-                       if not lines.first.has_prefix("    ") and
-                          not lines.first.has_prefix("\t") then
-                               # parse synopsys
-                               var syn = inline_proc.process(lines.shift)
-                               res.add "<h1 class=\"synopsys\">{syn}</h1>"
-                       end
-               end
-               # check for annotations
-               for i in [0 .. lines.length[ do
-                       var line = lines[i]
-                       if line.to_upper.has_prefix("ENSURE") or line.to_upper.has_prefix("REQUIRE") then
-                               var html = inline_proc.process(line)
-                               lines[i] = "<p class=\"contract\">{html}</p>"
-                       else if line.to_upper.has_prefix("TODO") or line.to_upper.has_prefix("FIXME") then
-                               var html = inline_proc.process(line)
-                               lines[i] = "<p class=\"todo\">{html}</p>"
-                       end
-               end
-               # add other lines
-               res.add markdown_proc.process(lines.join("\n"))
-               res.add "</div>"
-               decorator.current_mdoc = null
-               return res
-       end
-
-       private fun lines_to_md(lines: Array[String]): Writable do
-               var res = new Template
-               if not lines.is_empty then
-                       var syn = lines.first
-                       if not syn.has_prefix("    ") and not syn.has_prefix("\t") and
-                         not syn.trim.has_prefix("#") then
-                               lines.shift
-                               res.add "# {syn}\n"
-                       end
-               end
-               res.add lines.join("\n")
-               return res
-       end
-end
-
-# The specific markdown decorator used internally to process MDoc object.
-#
-# You should use the various methods of `MDoc` like `MDoc::html_documentation`
-#
-# The class is public so specific behavior can be plugged on it.
-class NitdocDecorator
-       super HTMLDecorator
-
-       private var toolcontext = new ToolContext
-
-       # The currently processed mdoc.
-       #
-       # Unfortunately, this seems to be the simpler way to get the currently processed `MDoc` object.
-       var current_mdoc: nullable MDoc = null
-
-       redef fun add_code(v, block) do
-               var meta = block.meta or else "nit"
-
-               # Do not try to highlight non-nit code.
-               if meta != "nit" and meta != "nitish" then
-                       v.add "<pre class=\"{meta}\"><code>"
-                       v.emit_in block
-                       v.add "</code></pre>\n"
-                       return
-               end
-               # Try to parse code
-               var code = block.raw_content
-               var ast = toolcontext.parse_something(code)
-               if ast isa AError then
-                       v.add "<pre class=\"{meta}\"><code>"
-                       v.emit_in block
-                       v.add "</code></pre>\n"
-                       return
-               end
-               v.add "<pre class=\"nitcode\"><code>"
-               var hl = new HtmlightVisitor
-               hl.line_id_prefix = ""
-               hl.highlight_node(ast)
-               v.add(hl.html)
-               v.add "</code></pre>\n"
-       end
-
-       redef fun add_span_code(v, text, from, to) do
-               # Try to parse it
-               var code = code_from_text(text, from, to)
-               var ast = toolcontext.parse_something(code)
-
-               if ast isa AError then
-                       v.add "<code class=\"rawcode\">"
-                       append_code(v, text, from, to)
-               else
-                       v.add "<code class=\"nitcode\">"
-                       var hl = new HtmlightVisitor
-                       hl.line_id_prefix = ""
-                       hl.highlight_node(ast)
-                       v.add(hl.html)
-               end
-               v.add "</code>"
-       end
-
-       private fun code_from_text(buffer: Text, from, to: Int): String do
-               var out = new FlatBuffer
-               for i in [from..to[ do out.add buffer[i]
-               return out.write_to_string
-       end
-end
-
-# Decorator for span elements.
-#
-# Because inline comments can appear as span elements,
-# InlineDecorator do not decorate things like paragraphs or headers.
-private class InlineDecorator
-       super NitdocDecorator
-
-       redef fun add_paragraph(v, block) do
-               v.emit_in block
-       end
-
-       redef fun add_headline(v, block) do
-               # save headline
-               var line = block.block.first_line
-               if line == null then return
-               var txt = line.value
-               var id = strip_id(txt)
-               var lvl = block.depth
-               headlines[id] = new HeadLine(id, txt, lvl)
-
-               v.emit_in block
-       end
-
-       redef fun add_code(v, block) do
-               # Try to parse code
-               var ast = toolcontext.parse_something(block.block.text.to_s)
-               if ast isa AError then
-                       v.add "<code>"
-                       v.emit_in block
-                       v.add "</code>"
-                       return
-               end
-               v.add "<code class=\"nitcode\">"
-               var hl = new HtmlightVisitor
-               hl.highlight_node(ast)
-               v.add(hl.html)
-               v.add "</code>"
-       end
-end
-
-redef class Model
-       # Get a markdown processor for Nitdoc comments.
-       var nitdoc_md_processor: MarkdownProcessor is lazy, writable do
-               var proc = new MarkdownProcessor
-               proc.decorator = new NitdocDecorator
-               return proc
-       end
-
-       # Get a markdown inline processor for Nitdoc comments.
-       #
-       # This processor is specificaly designed to inlinable doc elements like synopsys.
-       var nitdoc_inline_processor: MarkdownProcessor is lazy, writable do
-               var proc = new MarkdownProcessor
-               proc.decorator = new InlineDecorator
-               return proc
-       end
-end
index a7ae6bb..16f09aa 100644 (file)
@@ -18,8 +18,6 @@ module static_base
 import static_cards
 import modelize
 
-intrude import markdown::wikilinks
-
 # The model of a Nitdoc documentation
 class DocModel
 
index e589ca6..c02f565 100644 (file)
 # Cards templates for the static documentation
 module static_cards
 
-import doc::commands::commands_graph
-import doc::commands::commands_catalog
-import doc::commands::commands_docdown
-import templates_html
+import templates::html_commands
 
 # A card that can be rendered to HTML
 #
@@ -282,10 +279,21 @@ class CardInheritance
                addn "<h4 id='{id}'>{title}</h4>"
                addn "<ul class='list-unstyled'>"
                for mentity in mentities do
-                       addn mentity.html_list_item
+                       addn html_list_item(mentity)
                end
                addn "</ul>"
        end
+
+       private fun html_list_item(mentity: MEntity): ListItem do
+               var tpl = new Template
+               tpl.add mentity.html_namespace
+               var comment = mentity.mdoc_or_fallback
+               if comment != null then
+                       tpl.add ": "
+                       tpl.add comment.html_synopsis
+               end
+               return new ListItem(tpl)
+       end
 end
 
 # A card about the linearization of a MEntity
similarity index 65%
rename from src/doc/commands/commands_html.nit
rename to src/doc/templates/html_commands.nit
index 7aac39a..39e088c 100644 (file)
 # limitations under the License.
 
 # Render commands results as HTML
-module commands_html
+module html_commands
 
-import commands::commands_graph
-import commands::commands_usage
-import commands::commands_ini
-import commands::commands_main
+import commands_catalog
+import commands_docdown
+import commands_graph
+import commands_ini
+import commands_main
+import commands_parser
+import commands_usage
 
-import templates::templates_html
-import doc_down
-import highlight
+import templates::html_model
+intrude import markdown::wikilinks
 
 redef class DocCommand
 
@@ -104,6 +106,17 @@ redef class CmdComment
                end
                return tpl.write_to_string
        end
+
+       redef fun render_comment do
+               var mdoc = self.mdoc
+               if mdoc == null then return null
+
+               if format == "html" then
+                       if full_doc then return mdoc.html_documentation
+                       return mdoc.html_synopsis
+               end
+               return super
+       end
 end
 
 redef class CmdEntityLink
@@ -114,11 +127,37 @@ redef class CmdEntityLink
        end
 end
 
-redef class CmdEntityCode
+redef class CmdCode
        redef fun to_html do
-               var output = render_code(node)
-               if output == null then return ""
-               return "<pre>{output.write_to_string}</pre>"
+               var node = self.node
+               if node == null then return ""
+
+               var code = render_code(node)
+               return "<pre>{code.write_to_string}</pre>"
+       end
+
+       redef fun render_code(node) do
+               if format == "html" then
+                       var hl = new CmdHtmlightVisitor
+                       hl.show_infobox = false
+                       hl.highlight_node node
+                       return hl.html
+               end
+               return super
+       end
+end
+
+# Custom HtmlightVisitor for commands
+#
+# We create a new subclass so its behavior can be refined in clients without
+# breaking the main implementation.
+class CmdHtmlightVisitor
+       super HtmlightVisitor
+
+       redef fun hrefto(mentity) do
+               if mentity isa MClassDef then return mentity.mclass.html_url
+               if mentity isa MPropDef then return mentity.mproperty.html_url
+               return mentity.html_url
        end
 end
 
@@ -246,12 +285,6 @@ redef class CmdIniLicense
 end
 
 redef class CmdEntityFile
-
-       # URL to the file
-       #
-       # Can be refined in subtools.
-       var file_url: nullable String = file is lazy, writable
-
        redef fun to_html do
                var file = self.file
                if file == null then return ""
@@ -323,12 +356,104 @@ redef class CmdTesting
        end
 end
 
-# Misc
+# MDoc
 
-redef class CmdHtmlightVisitor
-       redef fun hrefto(mentity) do
-               if mentity isa MClassDef then return mentity.mclass.html_url
-               if mentity isa MPropDef then return mentity.mproperty.html_url
-               return mentity.html_url
+# Custom Markdown processor able to process doc commands
+class CmdDecorator
+       super NitdocDecorator
+
+       redef type PROCESSOR: CmdMarkdownProcessor
+
+       # Model used by wikilink commands to find entities
+       var model: Model
+
+       # Filter to apply if any
+       var filter: nullable ModelFilter
+
+       redef fun add_span_code(v, buffer, from, to) do
+               var text = new FlatBuffer
+               buffer.read(text, from, to)
+               var name = text.write_to_string
+               name = name.replace("nullable ", "")
+               var mentity = try_find_mentity(name)
+               if mentity == null then
+                       super
+               else
+                       v.add "<code>"
+                       v.emit_text mentity.html_link.write_to_string
+                       v.add "</code>"
+               end
+       end
+
+       private fun try_find_mentity(text: String): nullable MEntity do
+               var mentity = model.mentity_by_full_name(text, filter)
+               if mentity != null then return mentity
+
+               var mentities = model.mentities_by_name(text, filter)
+               if mentities.is_empty then
+                       return null
+               else if mentities.length > 1 then
+                       # TODO smart resolve conflicts
+               end
+               return mentities.first
+       end
+
+       redef fun add_wikilink(v, token) do
+               v.render_wikilink(token, model)
+       end
+end
+
+# Same as `InlineDecorator` but with wikilink commands handling
+class CmdInlineDecorator
+       super InlineDecorator
+
+       redef type PROCESSOR: CmdMarkdownProcessor
+
+       # Model used by wikilink commands to find entities
+       var model: Model
+
+       redef fun add_wikilink(v, token) do
+               v.render_wikilink(token, model)
+       end
+end
+
+# Custom MarkdownEmitter for commands
+class CmdMarkdownProcessor
+       super MarkdownProcessor
+
+       # Parser used to process doc commands
+       var parser: CommandParser
+
+       # Render a wikilink
+       fun render_wikilink(token: TokenWikiLink, model: Model) do
+               var link = token.link
+               if link == null then return
+               var name = token.name
+               if name != null then link = "{name} | {link}"
+
+               var command = parser.parse(link.write_to_string)
+               var error = parser.error
+
+               if error isa CmdError then
+                       emit_text error.to_html.write_to_string
+                       return
+               end
+               if error isa CmdWarning then
+                       emit_text error.to_html.write_to_string
+               end
+               add command.as(not null).to_html
+       end
+end
+
+redef class Text
+       # Read `self` between `nstart` and `nend` (excluded) and writte chars to `out`.
+       private fun read(out: FlatBuffer, nstart, nend: Int): Int do
+               var pos = nstart
+               while pos < length and pos < nend do
+                       out.add self[pos]
+                       pos += 1
+               end
+               if pos == length then return -1
+               return pos
        end
 end
similarity index 64%
rename from src/doc/templates/templates_html.nit
rename to src/doc/templates/html_model.nit
index 4faf0a6..6ec000f 100644 (file)
 # limitations under the License.
 
 # Translate mentities to html blocks.
-module templates_html
+module html_model
 
 import model::model_collect
-import doc::doc_down
-import html::bootstrap
 import catalog
 
+import markdown
+import htmlight
+import html::bootstrap
+private import parser_util
+
 redef class MEntity
 
        # The MEntity unique ID in the HTML output
@@ -47,7 +50,7 @@ redef class MEntity
                end
                var mdoc = self.mdoc_or_fallback
                if title == null and mdoc != null then
-                       title = mdoc.synopsis.html_escape
+                       title = mdoc.synopsis
                end
                return new Link(html_url, text, title)
        end
@@ -86,18 +89,6 @@ redef class MEntity
        # An icon representative of the mentity
        fun html_icon: BSIcon do return new BSIcon("tag", ["text-muted"])
 
-       # A li element that can go in a `HTMLList`
-       fun html_list_item: ListItem do
-               var tpl = new Template
-               tpl.add html_namespace
-               var comment = mdoc_or_fallback
-               if comment != null then
-                       tpl.add ": "
-                       tpl.add comment.html_synopsis
-               end
-               return new ListItem(tpl)
-       end
-
        # CSS classes used to decorate `self`
        #
        # Mainly used for icons.
@@ -364,6 +355,8 @@ redef class MParameter
        end
 end
 
+# Catalog
+
 redef class Person
 
        # HTML uniq id
@@ -377,7 +370,8 @@ redef class Person
        # Link to this person `html_url`
        fun html_link: Link do return new Link(html_url, name)
 
-       redef fun to_html do
+       # Render `self` as HTML
+       fun to_html: String do
                var tpl = new Template
                tpl.addn "<span>"
                var gravatar = self.gravatar
@@ -389,3 +383,192 @@ redef class Person
                return tpl.write_to_string
        end
 end
+
+# MDoc
+
+redef class MDoc
+
+       private var markdown_proc: MarkdownProcessor is lazy, writable do
+               return original_mentity.as(not null).model.nitdoc_md_processor
+       end
+
+       private var inline_proc: MarkdownProcessor is lazy, writable do
+               return original_mentity.as(not null).model.nitdoc_inline_processor
+       end
+
+       # Renders the synopsis as a HTML comment block.
+       var html_synopsis: Writable is lazy do
+               var res = new Template
+               var syn = inline_proc.process(content.first)
+               res.add "<span class=\"synopsys nitdoc\">{syn}</span>"
+               return res
+       end
+
+       # Renders the comment without the synopsis as a HTML comment block.
+       var html_comment: Writable is lazy do
+               var lines = content.to_a
+               if not lines.is_empty then lines.shift
+               return lines_to_html(lines)
+       end
+
+       # Renders the synopsis and the comment as a HTML comment block.
+       var html_documentation: Writable is lazy do return lines_to_html(content.to_a)
+
+       # Renders markdown line as a HTML comment block.
+       private fun lines_to_html(lines: Array[String]): Writable do
+               var res = new Template
+               var decorator = markdown_proc.decorator.as(NitdocDecorator)
+               decorator.current_mdoc = self
+               res.add "<div class=\"nitdoc\">"
+               # do not use DocUnit as synopsys
+               if not lines.is_empty then
+                       if not lines.first.has_prefix("    ") and
+                          not lines.first.has_prefix("\t") then
+                               # parse synopsys
+                               var syn = inline_proc.process(lines.shift)
+                               res.add "<h1 class=\"synopsys\">{syn}</h1>"
+                       end
+               end
+               # check for annotations
+               for i in [0 .. lines.length[ do
+                       var line = lines[i]
+                       if line.to_upper.has_prefix("ENSURE") or line.to_upper.has_prefix("REQUIRE") then
+                               var html = inline_proc.process(line)
+                               lines[i] = "<p class=\"contract\">{html}</p>"
+                       else if line.to_upper.has_prefix("TODO") or line.to_upper.has_prefix("FIXME") then
+                               var html = inline_proc.process(line)
+                               lines[i] = "<p class=\"todo\">{html}</p>"
+                       end
+               end
+               # add other lines
+               res.add markdown_proc.process(lines.join("\n"))
+               res.add "</div>"
+               decorator.current_mdoc = null
+               return res
+       end
+end
+
+# The specific markdown decorator used internally to process MDoc object.
+#
+# You should use the various methods of `MDoc` like `MDoc::html_documentation`
+#
+# The class is public so specific behavior can be plugged on it.
+class NitdocDecorator
+       super HTMLDecorator
+
+       private var toolcontext = new ToolContext
+
+       # The currently processed mdoc.
+       #
+       # Unfortunately, this seems to be the simpler way to get the currently processed `MDoc` object.
+       var current_mdoc: nullable MDoc = null
+
+       redef fun add_code(v, block) do
+               var meta = block.meta or else "nit"
+
+               # Do not try to highlight non-nit code.
+               if meta != "nit" and meta != "nitish" then
+                       v.add "<pre class=\"{meta}\"><code>"
+                       v.emit_in block
+                       v.add "</code></pre>\n"
+                       return
+               end
+               # Try to parse code
+               var code = block.raw_content
+               var ast = toolcontext.parse_something(code)
+               if ast isa AError then
+                       v.add "<pre class=\"{meta}\"><code>"
+                       v.emit_in block
+                       v.add "</code></pre>\n"
+                       return
+               end
+               v.add "<pre class=\"nitcode\"><code>"
+               var hl = new HtmlightVisitor
+               hl.line_id_prefix = ""
+               hl.highlight_node(ast)
+               v.add(hl.html)
+               v.add "</code></pre>\n"
+       end
+
+       redef fun add_span_code(v, text, from, to) do
+               # Try to parse it
+               var code = code_from_text(text, from, to)
+               var ast = toolcontext.parse_something(code)
+
+               if ast isa AError then
+                       v.add "<code class=\"rawcode\">"
+                       append_code(v, text, from, to)
+               else
+                       v.add "<code class=\"nitcode\">"
+                       var hl = new HtmlightVisitor
+                       hl.line_id_prefix = ""
+                       hl.highlight_node(ast)
+                       v.add(hl.html)
+               end
+               v.add "</code>"
+       end
+
+       private fun code_from_text(buffer: Text, from, to: Int): String do
+               var out = new FlatBuffer
+               for i in [from..to[ do out.add buffer[i]
+               return out.write_to_string
+       end
+end
+
+# Decorator for span elements.
+#
+# Because inline comments can appear as span elements,
+# InlineDecorator do not decorate things like paragraphs or headers.
+class InlineDecorator
+       super NitdocDecorator
+
+       redef fun add_paragraph(v, block) do
+               v.emit_in block
+       end
+
+       redef fun add_headline(v, block) do
+               # save headline
+               var line = block.block.first_line
+               if line == null then return
+               var txt = line.value
+               var id = strip_id(txt)
+               var lvl = block.depth
+               headlines[id] = new HeadLine(id, txt, lvl)
+
+               v.emit_in block
+       end
+
+       redef fun add_code(v, block) do
+               # Try to parse code
+               var ast = toolcontext.parse_something(block.block.text.to_s)
+               if ast isa AError then
+                       v.add "<code>"
+                       v.emit_in block
+                       v.add "</code>"
+                       return
+               end
+               v.add "<code class=\"nitcode\">"
+               var hl = new HtmlightVisitor
+               hl.highlight_node(ast)
+               v.add(hl.html)
+               v.add "</code>"
+       end
+end
+
+redef class Model
+       # Get a markdown processor for Nitdoc comments.
+       var nitdoc_md_processor: MarkdownProcessor is lazy, writable do
+               var proc = new MarkdownProcessor
+               proc.decorator = new NitdocDecorator
+               return proc
+       end
+
+       # Get a markdown inline processor for Nitdoc comments.
+       #
+       # This processor is specificaly designed to inlinable doc elements like synopsys.
+       var nitdoc_inline_processor: MarkdownProcessor is lazy, writable do
+               var proc = new MarkdownProcessor
+               proc.decorator = new InlineDecorator
+               return proc
+       end
+end
similarity index 91%
rename from src/doc/commands/commands_json.nit
rename to src/doc/templates/json_commands.nit
index b109c87..aea7be3 100644 (file)
 # limitations under the License.
 
 # Translate command results to json
-module commands_json
+module json_commands
 
-import commands::commands_model
-import commands::commands_graph
-import commands::commands_usage
-import commands::commands_catalog
-import commands::commands_ini
-import commands::commands_main
+import commands_catalog
+import commands_graph
+import commands_ini
+import commands_main
+import commands_usage
 
-import templates::templates_json
-import catalog::catalog_json
+import templates::json_model
+import json::static
 
 redef class DocCommand
        # Return a JSON Serializable representation of `self` results
@@ -86,17 +85,15 @@ redef class CmdEntityLink
        end
 end
 
-redef class CmdEntityCode
+redef class CmdCode
        redef fun to_json do
                var obj = new JsonObject
                var node = self.node
-               if node != null then
-                       obj["location"] = node.location
-               end
-               var output = render_code(node)
-               if output != null then
-                       obj["code"] = output.write_to_string
-               end
+               if node == null then return obj
+
+               var code = render_code(node)
+               obj["location"] = node.location
+               obj["code"] = code.write_to_string
                return obj
        end
 end
similarity index 82%
rename from src/doc/templates/templates_json.nit
rename to src/doc/templates/json_model.nit
index a75dc49..b91a237 100644 (file)
 # rather than the refs.
 #
 # TODO consider serialization module?
-module templates_json
+module json_model
 
 import model::model_collect
-import json::static
 import json::serialization_write
 import catalog
-import doc_down
+
+import html_model
 
 redef class MEntity
        serialize
@@ -376,3 +376,72 @@ end
 redef class String
        super JsonRef
 end
+
+# Catalog
+
+redef class MPackageMetadata
+       serialize
+
+       redef fun core_serialize_to(v) do
+               super
+               v.serialize_attribute("license", license)
+               v.serialize_attribute("maintainers", maintainers)
+               v.serialize_attribute("contributors", contributors)
+               v.serialize_attribute("tags", tags)
+               v.serialize_attribute("tryit", tryit)
+               v.serialize_attribute("apk", apk)
+               v.serialize_attribute("homepage", homepage)
+               v.serialize_attribute("browse", browse)
+               v.serialize_attribute("git", git)
+               v.serialize_attribute("issues", issues)
+               v.serialize_attribute("first_date", first_date)
+               v.serialize_attribute("last_date", last_date)
+       end
+end
+
+# Catalog statistics
+redef class CatalogStats
+       serialize
+
+       redef fun core_serialize_to(v) do
+               super
+               v.serialize_attribute("packages", packages)
+               v.serialize_attribute("maintainers", maintainers)
+               v.serialize_attribute("contributors", contributors)
+               v.serialize_attribute("tags", tags)
+               v.serialize_attribute("modules", modules)
+               v.serialize_attribute("classes", classes)
+               v.serialize_attribute("methods", methods)
+               v.serialize_attribute("loc", loc)
+       end
+end
+
+# MPackage statistics for the catalog
+redef class MPackageStats
+       serialize
+
+       redef fun core_serialize_to(v) do
+               super
+               v.serialize_attribute("mmodules", mmodules)
+               v.serialize_attribute("mclasses", mclasses)
+               v.serialize_attribute("mmethods", mmethods)
+               v.serialize_attribute("loc", loc)
+               v.serialize_attribute("errors", errors)
+               v.serialize_attribute("warnings", warnings)
+               v.serialize_attribute("warnings_per_kloc", warnings_per_kloc)
+               v.serialize_attribute("documentation_score", documentation_score)
+               v.serialize_attribute("commits", commits)
+               v.serialize_attribute("score", score)
+       end
+end
+
+redef class Person
+       serialize
+
+       redef fun core_serialize_to(v) do
+               super
+               v.serialize_attribute("name", name)
+               v.serialize_attribute("email", email)
+               v.serialize_attribute("gravatar", gravatar)
+       end
+end
similarity index 79%
rename from src/doc/commands/commands_md.nit
rename to src/doc/templates/md_commands.nit
index 77ad14a..4c004c7 100644 (file)
 # limitations under the License.
 
 # Render commands results as Markdown
-module commands_md
+module md_commands
 
-import commands::commands_graph
-import commands::commands_usage
-import commands::commands_ini
-import commands::commands_main
+import commands_catalog
+import commands_graph
+import commands_ini
+import commands_main
+import commands_usage
 
-import doc_down
+import highlight
 
 redef class DocCommand
 
@@ -89,6 +90,17 @@ redef class CmdComment
                end
                return tpl.write_to_string
        end
+
+       redef fun render_comment do
+               var mdoc = self.mdoc
+               if mdoc == null then return null
+
+               if format == "md" then
+                       if full_doc then return mdoc.md_documentation
+                       return mdoc.md_synopsis
+               end
+               return super
+       end
 end
 
 redef class CmdEntityLink
@@ -99,17 +111,27 @@ redef class CmdEntityLink
        end
 end
 
-redef class CmdEntityCode
+redef class CmdCode
        redef fun to_md do
-               var output = render_code(node)
-               if output == null then return ""
+               var node = self.node
+               if node == null then return ""
 
+               var code = render_code(node)
                var tpl = new Template
                tpl.addn "~~~nit"
-               tpl.add output.write_to_string
+               tpl.add code.write_to_string
                tpl.addn "~~~"
                return tpl.write_to_string
        end
+
+       redef fun render_code(node) do
+               if format == "ansi" then
+                       var hl = new AnsiHighlightVisitor
+                       hl.highlight_node node
+                       return hl.result
+               end
+               return super
+       end
 end
 
 redef class CmdAncestors
@@ -320,3 +342,39 @@ redef class CmdTesting
                return tpl.write_to_string
        end
 end
+
+# MDoc
+
+redef class MDoc
+
+       # Renders the synopsis as a HTML comment block.
+       var md_synopsis: Writable is lazy do
+               if content.is_empty then return ""
+               return content.first
+       end
+
+       #
+       var md_comment: Writable is lazy do
+               if content.is_empty then return ""
+               var lines = content.to_a
+               lines.shift
+               return lines.join("\n")
+       end
+
+       # Renders the synopsis and the comment as a HTML comment block.
+       var md_documentation: Writable is lazy do return lines_to_md(content.to_a)
+
+       private fun lines_to_md(lines: Array[String]): Writable do
+               var res = new Template
+               if not lines.is_empty then
+                       var syn = lines.first
+                       if not syn.has_prefix("    ") and not syn.has_prefix("\t") and
+                         not syn.trim.has_prefix("#") then
+                               lines.shift
+                               res.add "# {syn}\n"
+                       end
+               end
+               res.add lines.join("\n")
+               return res
+       end
+end
similarity index 99%
rename from src/doc/templates/templates_term.nit
rename to src/doc/templates/term_model.nit
index b4fc2fe..4a442c5 100644 (file)
@@ -16,7 +16,7 @@
 #
 # This module introduces Markdown rendering services in model entities.
 # With the `no_color` option set to `false`, the output can be highlighted for console.
-module templates_term
+module term_model
 
 import model_collect
 import console
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-module test_commands_html is test
+module test_html_commands is test
 
 import test_commands
 intrude import doc::commands::commands_main
-import doc::commands::commands_html
+import html_commands
 
 class TestCommandsHtml
        super TestCommands
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-module test_commands_json is test
+module test_json_commands is test
 
 import test_commands
 intrude import doc::commands::commands_main
-import doc::commands::commands_json
+import json_commands
 
 class TestCommandsJson
        super TestCommands
@@ -12,9 +12,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-module test_templates_json is test
+module test_json_model is test
 
-import templates_json
+import json_model
 import frontend
 
 class TestModelSerialization
similarity index 98%
rename from src/doc/commands/tests/test_commands_md.nit
rename to src/doc/templates/tests/test_md_commands.nit
index 031e21e..de7d655 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-module test_commands_md is test
+module test_md_commands is test
 
 import test_commands
 intrude import doc::commands::commands_main
-import doc::commands::commands_md
+import md_commands
 
 class TestCommandsMd
        super TestCommands
index 5010fc9..7d490e4 100644 (file)
@@ -15,7 +15,8 @@
 module term
 
 import commands::commands_parser
-import templates::templates_term
+import templates::term_model
+import templates::md_commands
 
 redef class CommandParser
 
@@ -221,13 +222,12 @@ redef class CmdEntityCode
                else
                        print title
                end
-               if no_color == null or not no_color then
+               var node = self.node
+               if (no_color == null or not no_color) and node != null then
                        var ansi = render_code(node)
-                       if ansi != null then
-                               print "~~~"
-                               print ansi.write_to_string
-                               print "~~~"
-                       end
+                       print "~~~"
+                       print ansi.write_to_string
+                       print "~~~"
                else
                        printn mentity.cs_source_code
                end
index 84c83a6..78258fa 100644 (file)
@@ -22,7 +22,6 @@ module parse_examples
 import counter
 import typing
 import parse_annotations
-import doc_down
 import model::model_examples
 
 redef class ToolContext
index 261fafe..52a6b7a 100644 (file)
@@ -31,6 +31,19 @@ class MDoc
 
        # The original location of the doc for error messages
        var location: Location
+
+       # The comment first line
+       var synopsis: String is lazy do return content.first
+
+       # All comment lines except for the synopsis
+       var comment: String is lazy do
+               var lines = content.to_a
+               if not lines.is_empty then lines.shift
+               return lines.join("\n")
+       end
+
+       # Full comment
+       var documentation: String is lazy do return content.join("\n")
 end
 
 redef class MEntity
index 244be79..2a0a4a5 100644 (file)
 module nitcatalog
 
 import loader # Scan&load packages, groups and modules
-import doc::doc_down # Display mdoc
 import catalog
 
+import doc::templates::html_model
+
 # A HTML page in a catalog
 #
 # This is just a template with the header pre-filled and the footer injected at rendering.
@@ -531,6 +532,24 @@ redef class Catalog
        var piwik_site_id: Int = 1
 end
 
+redef class Person
+       redef fun to_html do
+               var res = ""
+               var e = name.html_escape
+               var page = self.page
+               if page != null then
+                       res += "<a href=\"{page.html_escape}\">"
+               end
+               var gravatar = self.gravatar
+               if gravatar != null then
+                       res += "<img src=\"https://secure.gravatar.com/avatar/{gravatar}?size=20&amp;default=retro\">&nbsp;"
+               end
+               res += e
+               if page != null then res += "</a>"
+               return res
+       end
+end
+
 var model = new Model
 var tc = new ToolContext
 
index ab16edc..4ba30f5 100644 (file)
@@ -17,7 +17,6 @@ module nitweb
 
 import frontend
 import doc::api
-import doc::doc_down
 
 redef class ToolContext