var modelbuilder: ModelBuilder
# The JSON API does not filter anything by default.
- #
- # So we can cache the model view.
- var view: ModelView
+ var filter: nullable ModelFilter
# Catalog to pass to handlers.
- var catalog: Catalog is noinit
-
- # Build the catalog
- #
- # This method should be called at nitweb startup.
- # TODO move to nitweb
- fun build_catalog do
- var catalog = new Catalog(modelbuilder)
- # Compute the poset
- for p in view.mpackages do
- var g = p.root
- assert g != null
- modelbuilder.scan_group(g)
-
- catalog.deps.add_node(p)
- for gg in p.mgroups do for m in gg.mmodules do
- for im in m.in_importation.direct_greaters do
- var ip = im.mpackage
- if ip == null or ip == p then continue
- catalog.deps.add_edge(p, ip)
- end
- end
- end
- # Build the catalog
- for mpackage in view.mpackages do
- catalog.package_page(mpackage)
- catalog.git_info(mpackage)
- catalog.mpackage_stats(mpackage)
- end
- self.catalog = catalog
- end
+ var catalog: Catalog
end
# Specific handler for the nitweb API.
var config: NitwebConfig
# Find the MEntity ` with `full_name`.
- fun find_mentity(model: ModelView, full_name: nullable String): nullable MEntity do
+ fun find_mentity(full_name: nullable String): nullable MEntity do
if full_name == null then return null
- var mentity = model.mentity_by_full_name(full_name.from_percent_encoding)
+ var mentity = config.model.mentity_by_full_name(full_name.from_percent_encoding, config.filter)
if mentity == null then return null
- if config.view.accept_mentity(mentity) then return mentity
+
+ var filter = config.filter
+ if filter == null or filter.accept_mentity(mentity) then return mentity
return null
end
res.api_error(400, "Expected mentity full name")
return null
end
- var mentity = find_mentity(config.view, id)
+ var mentity = find_mentity(id)
if mentity == null then
res.api_error(404, "MEntity `{id}` not found")
end
redef class NitwebConfig
# Specific Markdown processor to use within Nitweb
var md_processor: MarkdownProcessor is lazy do
- var parser = new CommandParser(view, modelbuilder)
+ var parser = new CommandParser(model, mainmodule, modelbuilder, catalog, filter)
var proc = new CmdMarkdownProcessor(parser)
- proc.decorator = new CmdDecorator(view)
+ proc.decorator = new CmdDecorator(model)
return proc
end
end
private fun mclasses_metrics: MetricSet do
var metrics = new MetricSet
- metrics.register(new CNOA(config.view))
- metrics.register(new CNOP(config.view))
- metrics.register(new CNOC(config.view))
- metrics.register(new CNOD(config.view))
- metrics.register(new CNOAC(config.view))
- metrics.register(new CNOAA(config.view))
- metrics.register(new CNOAI(config.view))
- metrics.register(new CDIT(config.view))
- metrics.register(new CNBP(config.view))
- metrics.register(new CNBA(config.view))
- metrics.register(new CNBM(config.view))
- metrics.register(new CNBI(config.view))
- metrics.register(new CNBV(config.view))
- metrics.register(new CNBIP(config.view))
- metrics.register(new CNBRP(config.view))
- metrics.register(new CNBHP(config.view))
- metrics.register(new CNBLP(config.view))
+ metrics.register(new CNOA(config.model, config.mainmodule, config.filter))
+ metrics.register(new CNOP(config.model, config.mainmodule, config.filter))
+ metrics.register(new CNOC(config.model, config.mainmodule, config.filter))
+ metrics.register(new CNOD(config.model, config.mainmodule, config.filter))
+ metrics.register(new CNOAC(config.model, config.mainmodule, config.filter))
+ metrics.register(new CNOAA(config.model, config.mainmodule, config.filter))
+ metrics.register(new CNOAI(config.model, config.mainmodule, config.filter))
+ metrics.register(new CDIT(config.model, config.mainmodule, config.filter))
+ metrics.register(new CNBP(config.model, config.mainmodule, config.filter))
+ metrics.register(new CNBA(config.model, config.mainmodule, config.filter))
+ metrics.register(new CNBM(config.model, config.mainmodule, config.filter))
+ metrics.register(new CNBI(config.model, config.mainmodule, config.filter))
+ metrics.register(new CNBV(config.model, config.mainmodule, config.filter))
+ metrics.register(new CNBIP(config.model, config.mainmodule, config.filter))
+ metrics.register(new CNBRP(config.model, config.mainmodule, config.filter))
+ metrics.register(new CNBHP(config.model, config.mainmodule, config.filter))
+ metrics.register(new CNBLP(config.model, config.mainmodule, config.filter))
return metrics
end
private fun mmodules_metrics: MetricSet do
var metrics = new MetricSet
- metrics.register(new MNOA(config.view))
- metrics.register(new MNOP(config.view))
- metrics.register(new MNOC(config.view))
- metrics.register(new MNOD(config.view))
- metrics.register(new MDIT(config.view))
- metrics.register(new MNBD(config.view))
- metrics.register(new MNBI(config.view))
- metrics.register(new MNBR(config.view))
- metrics.register(new MNBCC(config.view))
- metrics.register(new MNBAC(config.view))
+ metrics.register(new MNOA(config.model, config.mainmodule, config.filter))
+ metrics.register(new MNOP(config.model, config.mainmodule, config.filter))
+ metrics.register(new MNOC(config.model, config.mainmodule, config.filter))
+ metrics.register(new MNOD(config.model, config.mainmodule, config.filter))
+ metrics.register(new MDIT(config.model, config.mainmodule, config.filter))
+ metrics.register(new MNBD(config.model, config.mainmodule, config.filter))
+ metrics.register(new MNBI(config.model, config.mainmodule, config.filter))
+ metrics.register(new MNBR(config.model, config.mainmodule, config.filter))
+ metrics.register(new MNBCC(config.model, config.mainmodule, config.filter))
+ metrics.register(new MNBAC(config.model, config.mainmodule, config.filter))
return metrics
end
class APIList
super APICommand
- redef fun command do return new CmdModelEntities(config.view)
+ redef fun command do return new CmdModelEntities(config.model)
end
# Return a random list of MEntities.
class APIRandom
super APICommand
- redef fun command do return new CmdRandomEntities(config.view)
+ redef fun command do return new CmdRandomEntities(config.model)
end
# Search mentities from a cmd string.
class APISearch
super APIList
- redef fun command do return new CmdCatalogSearch(config.view, config.catalog)
+ redef fun command do return new CmdCatalogSearch(config.model, config.catalog)
end
# CmdEntity
class APIEntity
super APICommand
- redef fun command do return new CmdEntity(config.view)
+ redef fun command do return new CmdEntity(config.model)
end
# Return the full MDoc of a MEntity.
class APIEntityDoc
super APICommand
- redef fun command do return new CmdComment(config.view)
+ redef fun command do return new CmdComment(config.model)
end
# List MEntity ancestors
class APIEntityAncestors
super APICommand
- redef fun command do return new CmdAncestors(config.view)
+ redef fun command do return new CmdAncestors(config.model, config.mainmodule)
end
# List MEntity parents
class APIEntityParents
super APICommand
- redef fun command do return new CmdParents(config.view)
+ redef fun command do return new CmdParents(config.model, config.mainmodule)
end
# List MEntity children
class APIEntityChildren
super APICommand
- redef fun command do return new CmdChildren(config.view)
+ redef fun command do return new CmdChildren(config.model, config.mainmodule)
end
# List MEntity descendants
class APIEntityDescendants
super APICommand
- redef fun command do return new CmdDescendants(config.view)
+ redef fun command do return new CmdDescendants(config.model, config.mainmodule)
end
# Linearize super definitions of a MClassDef or a MPropDef if any.
class APIEntityLinearization
super APICommand
- redef fun command do return new CmdLinearization(config.view)
+ redef fun command do return new CmdLinearization(config.model, config.mainmodule)
end
# List definitions of a MEntity.
class APIEntityDefs
super APICommand
- redef fun command do return new CmdFeatures(config.view)
+ redef fun command do return new CmdFeatures(config.model)
end
# List intro definitions of a MEntity.
class APIEntityIntros
super APICommand
- redef fun command do return new CmdIntros(config.view)
+ redef fun command do return new CmdIntros(config.model, config.mainmodule)
end
# List redef definitions of a MEntity.
class APIEntityRedefs
super APICommand
- redef fun command do return new CmdRedefs(config.view)
+ redef fun command do return new CmdRedefs(config.model, config.mainmodule)
end
# List all definitions accessible from a MEntity.
class APIEntityAll
super APICommand
- redef fun command do return new CmdAllProps(config.view)
+ redef fun command do return new CmdAllProps(config.model, config.mainmodule)
end
# Return the source code of MEntity.
class APIEntityCode
super APICommand
- redef fun command do return new CmdEntityCode(config.view, config.modelbuilder)
+ redef fun command do return new CmdEntityCode(config.model, config.modelbuilder)
end
# Return the UML diagram for MEntity.
class APIEntityUML
super APICommand
- redef fun command do return new CmdUML(config.view)
+ redef fun command do return new CmdUML(config.model, config.mainmodule)
end
# Return the inheritance graph for MEntity.
class APIInheritanceGraph
super APICommand
- redef fun command do return new CmdInheritanceGraph(config.view)
+ redef fun command do return new CmdInheritanceGraph(config.model, config.mainmodule)
end
# CmdCatalog
class APICatalogPackages
super APICommand
- redef fun command do return new CmdCatalogPackages(config.view, config.catalog)
+ redef fun command do return new CmdCatalogPackages(config.model, config.catalog)
end
# Get the catalog statistics
class APICatalogStats
super APICommand
- redef fun command do return new CmdCatalogStats(config.view, config.catalog)
+ redef fun command do return new CmdCatalogStats(config.model, config.catalog)
end
# Get the package metadata
class APIEntityMetadata
super APICommand
- redef fun command do return new CmdMetadata(config.view)
+ redef fun command do return new CmdMetadata(config.model)
end
# Get all the tags from the catalog
class APICatalogTags
super APICommand
- redef fun command do return new CmdCatalogTags(config.view, config.catalog)
+ redef fun command do return new CmdCatalogTags(config.model, config.catalog)
end
# Get the packages related to a tag
class APICatalogTag
super APICommand
- redef fun command do return new CmdCatalogTag(config.view, config.catalog)
+ redef fun command do return new CmdCatalogTag(config.model, config.catalog)
end
# Get a person existing in the catalog
class APICatalogPerson
super APICommand
- redef fun command do return new CmdCatalogPerson(config.view, config.catalog)
+ redef fun command do return new CmdCatalogPerson(config.model, config.catalog)
end
# Get the list of mpackages maintained by a person
class APICatalogMaintaining
super APICommand
- redef fun command do return new CmdCatalogMaintaining(config.view, config.catalog)
+ redef fun command do return new CmdCatalogMaintaining(config.model, config.catalog)
end
# Get the list of mpackages contributed by a person
class APICatalogContributing
super APICommand
- redef fun command do return new CmdCatalogContributing(config.view, config.catalog)
+ redef fun command do return new CmdCatalogContributing(config.model, config.catalog)
end
# CmdIni
class APIIniDesc
super APICommand
- redef fun command do return new CmdIniDescription(config.view)
+ redef fun command do return new CmdIniDescription(config.model)
end
# Get the package Git URL from the ini file
class APIIniGit
super APICommand
- redef fun command do return new CmdIniGitUrl(config.view)
+ redef fun command do return new CmdIniGitUrl(config.model)
end
# Get the package Git clone command from the ini file
class APIIniClone
super APICommand
- redef fun command do return new CmdIniCloneCommand(config.view)
+ redef fun command do return new CmdIniCloneCommand(config.model)
end
# Get the package issues URL from the ini file
class APIIniIssues
super APICommand
- redef fun command do return new CmdIniIssuesUrl(config.view)
+ redef fun command do return new CmdIniIssuesUrl(config.model)
end
# Get the package maintainer from the ini file
class APIIniMaintainer
super APICommand
- redef fun command do return new CmdIniMaintainer(config.view)
+ redef fun command do return new CmdIniMaintainer(config.model)
end
# Get the package contributors from the ini file
class APIIniContributors
super APICommand
- redef fun command do return new CmdIniContributors(config.view)
+ redef fun command do return new CmdIniContributors(config.model)
end
# Get the package license from the ini file
class APIIniLicense
super APICommand
- redef fun command do return new CmdIniLicense(config.view)
+ redef fun command do return new CmdIniLicense(config.model)
end
# Get the package license file
class APIIniLicenseFile
super APICommand
- redef fun command do return new CmdLicenseFile(config.view)
+ redef fun command do return new CmdLicenseFile(config.model)
end
# Get the package contrib file
class APIIniContribFile
super APICommand
- redef fun command do return new CmdContribFile(config.view)
+ redef fun command do return new CmdContribFile(config.model)
end
# Get the package license file content
class APIIniLicenseFileContent
super APICommand
- redef fun command do return new CmdLicenseFileContent(config.view)
+ redef fun command do return new CmdLicenseFileContent(config.model)
end
# Get the package contrib file content
class APIIniContribFileContent
super APICommand
- redef fun command do return new CmdContribFileContent(config.view)
+ redef fun command do return new CmdContribFileContent(config.model)
end
accept_attribute = not toolcontext.opt_no_attribute.value
)
- var view = new ModelView(model, mainmodule, filter)
+ var catalog = build_catalog(toolcontext.modelbuilder, filter)
- var config = new NitwebConfig(model, mainmodule, toolcontext.modelbuilder, view)
+ var config = new NitwebConfig(model, mainmodule, toolcontext.modelbuilder, filter, catalog)
var config_file = toolcontext.opt_config.value
if config_file == null then config.default_config_file = "nitweb.ini"
config.parse_options(args)
do
var config = build_config(toolcontext, mainmodule)
config.model.nitdoc_md_processor = config.md_processor
- config.build_catalog
var app = new App
app.listen(config.app_host, config.app_port)
end
+
+ # 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)
+
+ catalog.deps.add_node(p)
+ for gg in p.mgroups do for m in gg.mmodules do
+ for im in m.in_importation.direct_greaters do
+ var ip = im.mpackage
+ if ip == null or ip == p then continue
+ catalog.deps.add_edge(p, ip)
+ end
+ end
+ 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