+# Documentation generator for the nit language.
+# Generate API documentation in HTML format from nit source code.
+module nitdoc
+
+import model_utils
+import modelize_property
+import markdown
+
+# The NitdocContext contains all the knowledge used for doc generation
+class NitdocContext
+
+ private var toolcontext = new ToolContext
+ private var model: Model
+ private var mbuilder: ModelBuilder
+ private var mainmodule: MModule
+ private var class_hierarchy: POSet[MClass]
+ private var arguments: Array[String]
+ private var output_dir: nullable String
+ private var dot_dir: nullable String
+ private var share_dir: nullable String
+ private var source: nullable String
+ private var min_visibility: MVisibility
+
+ private var github_upstream: nullable String
+ private var github_basesha1: nullable String
+ private var github_gitdir: nullable String
+
+ private var opt_dir = new OptionString("Directory where doc is generated", "-d", "--dir")
+ private var opt_source = new OptionString("What link for source (%f for filename, %l for first line, %L for last line)", "--source")
+ private var opt_sharedir = new OptionString("Directory containing the nitdoc files", "--sharedir")
+ private var opt_shareurl = new OptionString("Do not copy shared files, link JS and CSS file to share url instead", "--shareurl")
+ private var opt_nodot = new OptionBool("Do not generate graphes with graphviz", "--no-dot")
+ private var opt_private: OptionBool = new OptionBool("Generate the private API", "--private")
+
+ private var opt_custom_title: OptionString = new OptionString("Title displayed in the top of the Overview page and as suffix of all page names", "--custom-title")
+ private var opt_custom_menu_items: OptionString = new OptionString("Items displayed in menu before the 'Overview' item (Each item must be enclosed in 'li' tags)", "--custom-menu-items")
+ private var opt_custom_overview_text: OptionString = new OptionString("Text displayed as introduction of Overview page before the modules list", "--custom-overview-text")
+ private var opt_custom_footer_text: OptionString = new OptionString("Text displayed as footer of all pages", "--custom-footer-text")
+
+ private var opt_github_upstream: OptionString = new OptionString("The branch where edited commits will be pulled into (ex: user:repo:branch)", "--github-upstream")
+ private var opt_github_base_sha1: OptionString = new OptionString("The sha1 of the base commit used to create pull request", "--github-base-sha1")
+ private var opt_github_gitdir: OptionString = new OptionString("The git working directory used to resolve path name (ex: /home/me/myproject/)", "--github-gitdir")
+
+ private var opt_piwik_tracker: OptionString = new OptionString("The URL of the Piwik tracker (ex: nitlanguage.org/piwik/)", "--piwik-tracker")
+ private var opt_piwik_site_id: OptionString = new OptionString("The site ID in Piwik tracker", "--piwik-site-id")
+
+ init do
+ toolcontext.option_context.add_option(opt_dir)
+ toolcontext.option_context.add_option(opt_source)
+ toolcontext.option_context.add_option(opt_sharedir, opt_shareurl)
+ toolcontext.option_context.add_option(opt_nodot)
+ toolcontext.option_context.add_option(opt_private)
+ toolcontext.option_context.add_option(opt_custom_title)
+ toolcontext.option_context.add_option(opt_custom_footer_text)
+ toolcontext.option_context.add_option(opt_custom_overview_text)
+ toolcontext.option_context.add_option(opt_custom_menu_items)
+ toolcontext.option_context.add_option(opt_github_upstream)
+ toolcontext.option_context.add_option(opt_github_base_sha1)
+ toolcontext.option_context.add_option(opt_github_gitdir)
+ toolcontext.option_context.add_option(opt_piwik_tracker)
+ toolcontext.option_context.add_option(opt_piwik_site_id)
+ toolcontext.process_options
+ self.arguments = toolcontext.option_context.rest
+
+ if arguments.length < 1 then
+ print "usage: nitdoc [options] file..."
+ toolcontext.option_context.usage
+ exit(1)
+ end
+ self.process_options
+
+ model = new Model
+ mbuilder = new ModelBuilder(model, toolcontext)
+ # Here we load and process all modules passed on the command line
+ var mmodules = mbuilder.parse(arguments)
+ if mmodules.is_empty then return
+ mbuilder.run_phases
+
+ if mmodules.length == 1 then
+ mainmodule = mmodules.first
+ else
+ # We need a main module, so we build it by importing all modules
+ mainmodule = new MModule(model, null, "<main>", new Location(null, 0, 0, 0, 0))
+ mainmodule.set_imported_mmodules(mmodules)
+ end
+ self.class_hierarchy = mainmodule.flatten_mclass_hierarchy
+ end