X-Git-Url: http://nitlanguage.org diff --git a/src/nitweb.nit b/src/nitweb.nit index a953fcb..8baf1e8 100644 --- a/src/nitweb.nit +++ b/src/nitweb.nit @@ -15,9 +15,8 @@ # Runs a webserver based on nitcorn that render things from model. module nitweb -import popcorn::pop_config import frontend -import web +import doc::api redef class ToolContext @@ -30,12 +29,28 @@ redef class ToolContext # Port number to bind on (will overwrite the config one). var opt_port = new OptionInt("Port number to use", -1, "--port") + # --no-private + var opt_no_private = new OptionBool("Do not show private entities", "--no-private") + + # --no-fictive + var opt_no_fictive = new OptionBool("Do not show fictive entities", "--no-fictive") + + # --no-test + var opt_no_test = new OptionBool("Do not show test related entities", "--no-test") + + # --no-attribute + var opt_no_attribute = new OptionBool("Do not show attributes", "--no-attribute") + + # --no-empty-doc + var opt_no_empty_doc = new OptionBool("Do not undocumented entities", "--no-empty-doc") + # Web rendering phase. var webphase: Phase = new NitwebPhase(self, null) init do super - option_context.add_option(opt_config, opt_host, opt_port) + option_context.add_option(opt_config, opt_host, opt_port, opt_no_private, + opt_no_fictive, opt_no_test, opt_no_attribute, opt_no_empty_doc) end end @@ -45,82 +60,71 @@ private class NitwebPhase # Build the nitweb config from `toolcontext` options. fun build_config(toolcontext: ToolContext, mainmodule: MModule): NitwebConfig do + + var model = toolcontext.modelbuilder.model + + var filter = new ModelFilter( + if toolcontext.opt_no_private.value then protected_visibility else private_visibility, + accept_fictive = not toolcontext.opt_no_fictive.value, + accept_empty_doc = not toolcontext.opt_no_empty_doc.value, + accept_test = not toolcontext.opt_no_test.value, + accept_attribute = not toolcontext.opt_no_attribute.value + ) + + var catalog = build_catalog(toolcontext.modelbuilder, filter) + + var config = new NitwebConfig(model, mainmodule, toolcontext.modelbuilder, filter, catalog) var config_file = toolcontext.opt_config.value - if config_file == null then config_file = "nitweb.ini" - var config = new NitwebConfig( - config_file, - toolcontext.modelbuilder.model, - mainmodule, - toolcontext.modelbuilder) + if config_file == null then config.default_config_file = "nitweb.ini" + config.parse_options(args) var opt_host = toolcontext.opt_host.value - if opt_host != null then config["app.host"] = opt_host + if opt_host != null then config.ini["app.host"] = opt_host var opt_port = toolcontext.opt_port.value - if opt_port >= 0 then config["app.port"] = opt_port.to_s + if opt_port >= 0 then config.ini["app.port"] = opt_port.to_s return config end - # Build the nit catalog used in homepage. - fun build_catalog(model: Model, modelbuilder: ModelBuilder): Catalog do - var catalog = new Catalog(modelbuilder) - for mpackage in model.mpackages do - catalog.deps.add_node(mpackage) - for mgroup in mpackage.mgroups do - for mmodule in mgroup.mmodules do - for imported in mmodule.in_importation.direct_greaters do - var ip = imported.mpackage - if ip == null or ip == mpackage then continue - catalog.deps.add_edge(mpackage, ip) - end - end - end - catalog.git_info(mpackage) - catalog.package_page(mpackage) - end - return catalog - end - redef fun process_mainmodule(mainmodule, mmodules) do - var model = mainmodule.model - var modelbuilder = toolcontext.modelbuilder var config = build_config(toolcontext, mainmodule) - var catalog = build_catalog(model, modelbuilder) + config.model.index # pre load model index + config.model.nitdoc_md_processor = config.md_processor var app = new App app.use_before("/*", new SessionInit) app.use_before("/*", new RequestClock) - app.use("/api", new NitwebAPIRouter(config, catalog)) + app.use("/api", new APIRouter(config)) + app.use("/login", new GithubLogin(config.github_client_id)) + app.use("/oauth", new GithubOAuthCallBack(config.github_client_id, config.github_client_secret)) + app.use("/logout", new GithubLogout) app.use("/*", new StaticHandler(toolcontext.share_dir / "nitweb", "index.html")) - app.use_after("/*", new ConsoleLog) + app.use_after("/*", new PopLogger(info_level)) app.listen(config.app_host, config.app_port) end -end - -# Group all api handlers in one router. -class NitwebAPIRouter - super APIRouter - # Catalog to pass to handlers. - var catalog: Catalog - - init do - use("/catalog", new APICatalogRouter(config, catalog)) - use("/list", new APIList(config)) - use("/search", new APISearch(config)) - use("/random", new APIRandom(config)) - use("/entity/:id", new APIEntity(config)) - use("/code/:id", new APIEntityCode(config)) - use("/uml/:id", new APIEntityUML(config)) - use("/linearization/:id", new APIEntityLinearization(config)) - use("/defs/:id", new APIEntityDefs(config)) - use("/feedback/", new APIFeedbackRouter(config)) - use("/inheritance/:id", new APIEntityInheritance(config)) - use("/graph/", new APIGraphRouter(config)) - use("/docdown/", new APIDocdown(config)) - use("/metrics/", new APIMetricsRouter(config)) + # Build the catalog + # + # This method should be called at nitweb startup. + fun build_catalog(modelbuilder: ModelBuilder, filter: nullable ModelFilter): Catalog do + var catalog = new Catalog(modelbuilder) + var mpackages = modelbuilder.model.collect_mpackages(filter) + # Compute the poset + for p in mpackages do + var g = p.root + assert g != null + modelbuilder.scan_group(g) + end + # Build the catalog + for mpackage in mpackages do + catalog.package_page(mpackage) + catalog.git_info(mpackage) + catalog.mpackage_stats(mpackage) + end + return catalog end + end # build toolcontext