Runs a webserver based on nitcorn that render things from model.

Introduced classes

private class NitwebPhase

nitc :: NitwebPhase

Phase that builds the model and wait for http request to serve pages.

Redefined classes

redef class Sys

nitc :: nitweb $ Sys

The main class of the program.
redef class ToolContext

nitc :: nitweb $ ToolContext

Global context for tools

All class definitions

private class NitwebPhase

nitc $ NitwebPhase

Phase that builds the model and wait for http request to serve pages.
redef class Sys

nitc :: nitweb $ Sys

The main class of the program.
redef class ToolContext

nitc :: nitweb $ ToolContext

Global context for tools
package_diagram nitc::nitweb nitweb nitc\>doc\>api\> api nitc::nitweb->nitc\>doc\>api\> popcorn popcorn nitc\>doc\>api\>->popcorn nitc\>doc\>commands\> commands nitc\>doc\>api\>->nitc\>doc\>commands\> nitc\>doc\>templates\> templates nitc\>doc\>api\>->nitc\>doc\>templates\> nitc\>metrics\> metrics nitc\>doc\>api\>->nitc\>metrics\> ...popcorn ... ...popcorn->popcorn ...nitc\>doc\>commands\> ... ...nitc\>doc\>commands\>->nitc\>doc\>commands\> ...nitc\>doc\>templates\> ... ...nitc\>doc\>templates\>->nitc\>doc\>templates\> ...nitc\>metrics\> ... ...nitc\>metrics\>->nitc\>metrics\> a_star-m a_star-m a_star-m->nitc::nitweb

Ancestors

module abstract_collection

core :: abstract_collection

Abstract collection classes and services.
module abstract_text

core :: abstract_text

Abstract class for manipulation of sequences of characters
module abstract_tree

trees :: abstract_tree

Introduce tree structures abstraction
module actors_injection_phase

nitc :: actors_injection_phase

Injects model for the classes annotated with "is actor" so
module annotation

nitc :: annotation

Management and utilities on annotations
module api

github :: api

Nit object oriented interface to Github api.
module api_auth

nitc :: api_auth

module api_base

nitc :: api_base

Base classes used by nitweb.
module api_docdown

nitc :: api_docdown

Nitdoc specific Markdown format handling for Nitweb
module api_feedback

nitc :: api_feedback

Feedback related features
module api_light

nitc :: api_light

Highlight and collect messages from a piece of code
module api_model

nitc :: api_model

module array

core :: array

This module introduces the standard array structure.
module ast_metrics

nitc :: ast_metrics

Metrics about the nodes and identifiers in the AST
module astbuilder

nitc :: astbuilder

Instantiation and transformation of semantic nodes in the AST of expressions and statements
module astutil

nitc :: astutil

Additional features on Nit AST
module auto_super_init

nitc :: auto_super_init

Computing of super-constructors that must be implicitly called at the begin of constructors.
module base64

base64 :: base64

Offers the base 64 encoding and decoding algorithms
module bintree

trees :: bintree

Binary Tree data-structure
module bitset

core :: bitset

Services to handle BitSet
module bktree

trees :: bktree

Implementation of BKTree
module bootstrap

html :: bootstrap

HTML templates for Bootstrap components.
module bytes

core :: bytes

Services for byte streams and arrays
module c

c :: c

Structures and services for compatibility with the C language
module cache

github :: cache

Enable caching on Github API accesses.
module caching

serialization :: caching

Services for caching serialization engines
module catalog

nitc :: catalog

Basic catalog generator for Nit packages
module check_annotation

nitc :: check_annotation

Check that annotation present in the AST are either primitive or user-declared
module circular_array

core :: circular_array

Efficient data structure to access both end of the sequence.
module codec_base

core :: codec_base

Base for codecs to use with streams
module codecs

core :: codecs

Group module for all codec-related manipulations
module collection

core :: collection

This module define several collection classes.
module commands_base

nitc :: commands_base

Documentation commands
module commands_catalog

nitc :: commands_catalog

Commands to retrieve Catalog related data
module commands_docdown

nitc :: commands_docdown

Doc down related queries
module commands_graph

nitc :: commands_graph

Graph commands
module commands_http

nitc :: commands_http

Initialize commands from HTTP requests
module commands_model

nitc :: commands_model

Doc commands about a Model or a MEntity
module commands_parser

nitc :: commands_parser

A parser that create DocCommand from a string
module commands_usage

nitc :: commands_usage

Commands about how mentities are used
module config

config :: config

Configuration options for nit tools and apps
module console

console :: console

Defines some ANSI Terminal Control Escape Sequences.
module core

core :: core

Standard classes and methods used by default by Nit programs and libraries.
module counter

counter :: counter

Simple numerical statistical analysis and presentation
module csv

csv :: csv

CSV document handling.
module curl

curl :: curl

Data transfer powered by the native curl library
module deriving

nitc :: deriving

Injection of automatic method definitions for standard methods, based on the attributes of the classes
module detect_covariance

nitc :: detect_covariance

Detect the static usage of covariance in the code.
module detect_variance_constraints

nitc :: detect_variance_constraints

Collect metrics about detected variances constraints on formal types.
module digraph

graph :: digraph

Implementation of directed graphs, also called digraphs.
module div_by_zero

nitc :: div_by_zero

Detection of divisions by zero in obvious cases
module dot

dot :: dot

Dot rendering library
module engine_tools

serialization :: engine_tools

Advanced services for serialization engines
module environ

core :: environ

Access to the environment variables of the process
module error

core :: error

Standard error-management infrastructure.
module error

json :: error

Intro JsonParseError which is exposed by all JSON reading APIs
module exec

core :: exec

Invocation and management of operating system sub-processes.
module explain_assert_api

nitc :: explain_assert_api

Explain failed assert to the console (service declaration only)
module file

core :: file

File manipulations (create, read, write, etc.)
module file_server

nitcorn :: file_server

Provides the FileServer action, which is a standard and minimal file server
module fixed_ints

core :: fixed_ints

Basic integers of fixed-precision
module fixed_ints_text

core :: fixed_ints_text

Text services to complement fixed_ints
module flat

core :: flat

All the array-based text representations
module flow

nitc :: flow

Intraprocedural static flow.
module frontend

nitc :: frontend

Collect and orchestration of main frontend phases
module gc

core :: gc

Access to the Nit internal garbage collection mechanism
module generate_hierarchies

nitc :: generate_hierarchies

Create dot files for various hierarchies of a model.
module github

github :: github

Nit wrapper for Github API
module glsl_validation

nitc :: glsl_validation

Check shader code within Nit modules using the tool glslangValidator
module hash_collection

core :: hash_collection

Introduce HashMap and HashSet.
module highlight

nitc :: highlight

Highlighting of Nit AST
module html

html :: html

HTML output facilities
module html_commands

nitc :: html_commands

Render commands results as HTML
module html_model

nitc :: html_model

Translate mentities to html blocks.
module htmlight

nitc :: htmlight

Highlighting of Nit AST with HTML
module http_errors

nitcorn :: http_errors

Offers ErrorTemplate to display error pages
module http_request

nitcorn :: http_request

Provides the HttpRequest class and services to create it
module http_request_buffer

nitcorn :: http_request_buffer

Http request parsing for buffered inputs.
module http_response

nitcorn :: http_response

Provides the HttpResponse class and http_status_codes
module i18n_phase

nitc :: i18n_phase

Basic support of internationalization through the generation of id-to-string tables
module inheritance_metrics

nitc :: inheritance_metrics

Collect metrics about inheritance usage
module ini

ini :: ini

Read and write INI configuration files
module inspect

serialization :: inspect

Refine Serializable::inspect to show more useful information
module iso8859_1

core :: iso8859_1

Codec for ISO8859-1 I/O
module json

json :: json

Read and write JSON formatted text using the standard serialization services
module json_commands

nitc :: json_commands

Translate command results to json
module json_model

nitc :: json_model

Make model entities Serializable.
module kernel

core :: kernel

Most basic classes and methods.
module lexer

nitc :: lexer

Lexer and its tokens.
module lexer_work

nitc :: lexer_work

Internal algorithm and data structures for the Nit lexer
module libevent

libevent :: libevent

Low-level wrapper around the libevent library to manage events on file descriptors
module list

core :: list

This module handle double linked lists
module literal

nitc :: literal

Parsing of literal values in the abstract syntax tree.
module loader

nitc :: loader

Loading of Nit source files
module local_var_init

nitc :: local_var_init

Verify that local variables are initialized before their usage
module location

nitc :: location

Nit source-file and locations in source-file
module logger

logger :: logger

A simple logger for Nit
module markdown

markdown :: markdown

Markdown parsing.
module markdown_ast

markdown2 :: markdown_ast

Markdown AST representation
module markdown_block_parsing

markdown2 :: markdown_block_parsing

Markdown blocks parsing
module markdown_github

markdown2 :: markdown_github

Markdown Github mode
module markdown_html_rendering

markdown2 :: markdown_html_rendering

HTML rendering of Markdown documents
module markdown_inline_parsing

markdown2 :: markdown_inline_parsing

Parser for inline markdown
module markdown_rendering

markdown2 :: markdown_rendering

Markdown document rendering
module math

core :: math

Mathematical operations
module mclasses_metrics

nitc :: mclasses_metrics

Collect common metrics about mclasses
module md5

md5 :: md5

Native MD5 digest implementation as Text::md5
module md_commands

nitc :: md_commands

Render commands results as Markdown
module mdoc

nitc :: mdoc

Documentation of model entities
module media_types

nitcorn :: media_types

Services to identify Internet media types (or MIME types, Content-types)
module mendel_metrics

nitc :: mendel_metrics

The Mendel model helps to understand class hierarchies.
module meta

meta :: meta

Simple user-defined meta-level to manipulate types of instances as object.
module metrics

nitc :: metrics

Various statistics about Nit models and programs
module metrics_base

nitc :: metrics_base

Helpers for various statistics tools.
module mmodule

nitc :: mmodule

modules and module hierarchies in the metamodel
module mmodule_data

nitc :: mmodule_data

Define and retrieve data in modules
module mmodules_metrics

nitc :: mmodules_metrics

Collect common metrics about modules
module model

nitc :: model

Classes, types and properties
module model_base

nitc :: model_base

The abstract concept of model and related common things
module model_collect

nitc :: model_collect

Collect things from the model.
module model_examples

nitc :: model_examples

Examples for Model entities
module model_hyperdoc

nitc :: model_hyperdoc

Dump of Nit model into hypertext human-readable format.
module model_index

nitc :: model_index

Search things from the Model
module model_viz

nitc :: model_viz

Visualisation of Nit models
module modelbuilder_base

nitc :: modelbuilder_base

Load nit source files and build the associated model
module modelize

nitc :: modelize

Create a model from nit source files
module modelize_class

nitc :: modelize_class

Analysis and verification of class definitions to instantiate model element
module modelize_property

nitc :: modelize_property

Analysis and verification of property definitions to instantiate model element
module mongodb

mongodb :: mongodb

MongoDB Nit Driver.
module more_collections

more_collections :: more_collections

Highly specific, but useful, collections-related classes.
module mpackage

nitc :: mpackage

Modelisation of a Nit package
module native

core :: native

Native structures for text and bytes
module native_curl

curl :: native_curl

Binding of C libCurl which allow us to interact with network.
module native_mongodb

mongodb :: native_mongodb

Native wrapper for the MongoDB C Driver
module nitcorn

nitcorn :: nitcorn

The nitcorn Web server framework creates server-side Web apps in Nit
module nitpm_shared

nitc :: nitpm_shared

Services related to the Nit package manager
module no_warning

nitc :: no_warning

Fill toolcontext information about blacklisting of warnings.
module nullables_metrics

nitc :: nullables_metrics

Statistics about the usage of nullables
module numeric

core :: numeric

Advanced services for Numeric types
module opts

opts :: opts

Management of options on the command line
module ordered_tree

ordered_tree :: ordered_tree

Manipulation and presentation of ordered trees.
module parallelization_phase

nitc :: parallelization_phase

Phase generating threads for functions annotated with threaded annotation
module parse_annotations

nitc :: parse_annotations

Simple annotation parsing
module parser

nitc :: parser

Parser.
module parser_base

parser_base :: parser_base

Simple base for hand-made parsers of all kinds
module parser_nodes

nitc :: parser_nodes

AST nodes of the Nit language
module parser_prod

nitc :: parser_prod

Production AST nodes full definition.
module parser_util

nitc :: parser_util

Utils and tools related to parsers and AST
module parser_work

nitc :: parser_work

Internal algorithm and data structures for the Nit parser
module phase

nitc :: phase

Phases of the processing of nit programs
module pipeline

pipeline :: pipeline

Pipelined filters and operations on iterators.
module pop_auth

popcorn :: pop_auth

Authentification handlers.
module pop_config

popcorn :: pop_config

Configuration file and options for Popcorn apps
module pop_handlers

popcorn :: pop_handlers

Route handlers.
module pop_json

popcorn :: pop_json

Introduce useful services for JSON REST API handlers.
module pop_repos

popcorn :: pop_repos

Repositories for data management.
module pop_routes

popcorn :: pop_routes

Internal routes representation.
module pop_sessions

popcorn :: pop_sessions

Session handlers
module pop_tasks

popcorn :: pop_tasks

Popcorn threaded tasks
module pop_validation

popcorn :: pop_validation

Quick and easy validation framework for Json inputs
module popcorn

popcorn :: popcorn

Application server abstraction on top of nitcorn.
module poset

poset :: poset

Pre order sets and partial order set (ie hierarchies)
module poset_metrics

nitc :: poset_metrics

Metrics about the various posets of the model of a Nit program
module protocol

core :: protocol

module pthreads

pthreads :: pthreads

Main POSIX threads support and intro the classes Thread, Mutex and Barrier
module queries

mongodb :: queries

Mongo queries framework
module queue

core :: queue

Queuing data structures and wrappers
module range

core :: range

Module for range of discrete objects.
module rapid_type_analysis

nitc :: rapid_type_analysis

Rapid type analysis on the AST
module rbtree

trees :: rbtree

A red–black tree is a data structure which is a type of self-balancing binary search tree.
module re

core :: re

Regular expression support for all services based on Pattern
module reactor

nitcorn :: reactor

Core of the nitcorn project, provides HttpFactory and Action
module readme_metrics

nitc :: readme_metrics

Collect common metrics about README files
module realtime

realtime :: realtime

Services to keep time of the wall clock time
module refinement_metrics

nitc :: refinement_metrics

Collect metrics about refinement usage
module regex_phase

nitc :: regex_phase

Check for error in regular expressions from string literals
module ropes

core :: ropes

Tree-based representation of a String.
module rta_metrics

nitc :: rta_metrics

Metrics from RTA
module safe

serialization :: safe

Services for safer deserialization engines
module scope

nitc :: scope

Identification and scoping of local variables and labels.
module self_metrics

nitc :: self_metrics

Metrics about the usage of explicit and implicit self
module semantize

nitc :: semantize

Process bodies of methods in regard with the model.
module serialization

serialization :: serialization

General serialization services
module serialization_core

serialization :: serialization_core

Abstract services to serialize Nit objects to different formats
module serialization_model_phase

nitc :: serialization_model_phase

Phase generating methods (model-only) to serialize Nit objects
module serialization_read

json :: serialization_read

Services to read JSON: deserialize_json and JsonDeserializer
module serialization_write

json :: serialization_write

Services to write Nit objects to JSON strings: serialize_to_json and JsonSerializer
module server_config

nitcorn :: server_config

Classes and services to configure the server
module sessions

nitcorn :: sessions

Automated session management
module signal_handler

nitcorn :: signal_handler

Handle SIGINT and SIGTERM to close the server after all active events
module simple_misc_analysis

nitc :: simple_misc_analysis

Simple vavious processing on a AST
module sorter

core :: sorter

This module contains classes used to compare things and sorts arrays.
module static

json :: static

Static interface to read Nit objects from JSON strings
module static_types_metrics

nitc :: static_types_metrics

Metrics on the usage of explicit static types.
module store

json :: store

Store and load json data.
module stream

core :: stream

Input and output streams of characters
module tables

nitc :: tables

Module that interfaces the parsing tables.
module tables_metrics

nitc :: tables_metrics

Metrics on table generation
module template

template :: template

Basic template system
module text

core :: text

All the classes and methods related to the manipulation of text entities
module time

core :: time

Management of time and dates
module token

nitcorn :: token

Simple generate_token service, independent of the rest of the nitcorn framework
module toolcontext

nitc :: toolcontext

Common command-line tool infrastructure than handle options and error messages
module trees

trees :: trees

General module for tree data structures
module trie

trees :: trie

A trie (or prefix tree) is a datastructure used to perform prefix searches.
module typing

nitc :: typing

Intraprocedural resolution of static types and OO-services
module uml

nitc :: uml

Group head module for UML generation services
module uml_base

nitc :: uml_base

Exposes the base class for UML generation of a Model
module uml_class

nitc :: uml_class

Provides facilities of exporting a Model to a UML class diagram
module uml_module

nitc :: uml_module

Services for generation of a UML package diagram based on a Model
module union_find

core :: union_find

union–find algorithm using an efficient disjoint-set data structure
module utf8

core :: utf8

Codec for UTF-8 I/O
module vararg_routes

nitcorn :: vararg_routes

Routes with parameters.
module version

nitc :: version

This file was generated by git-gen-version.sh

Parents

module api

nitc :: api

Components required to build a web server about the nit model.

Children

module a_star-m

a_star-m

# Runs a webserver based on nitcorn that render things from model.
module nitweb

import frontend
import doc::api

redef class ToolContext

	# Path to app config file.
	var opt_config = new OptionString("Path to app config file", "--config")

	# Host name to bind on (will overwrite the config one).
	var opt_host = new OptionString("Host to bind the server on", "--host")

	# 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, opt_no_private,
			opt_no_fictive, opt_no_test, opt_no_attribute, opt_no_empty_doc)
	end
end

# Phase that builds the model and wait for http request to serve pages.
private class NitwebPhase
	super Phase

	# 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.default_config_file = "nitweb.ini"
		config.parse_options(args)
		var opt_host = toolcontext.opt_host.value
		if opt_host != null then config.ini["app.host"] = opt_host
		var opt_port = toolcontext.opt_port.value
		if opt_port >= 0 then config.ini["app.port"] = opt_port.to_s
		return config
	end

	redef fun process_mainmodule(mainmodule, mmodules)
	do
		var config = build_config(toolcontext, mainmodule)
		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 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 PopLogger(info_level))

		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)
		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
var toolcontext = new ToolContext
var tpl = new Template
tpl.add "Usage: nitweb [OPTION]... <file.nit>...\n"
tpl.add "Run a webserver based on nitcorn that serves pages about model."
toolcontext.tooldescription = tpl.write_to_string

# process options
toolcontext.process_options(args)
var arguments = toolcontext.option_context.rest

# build model
var model = new Model
var mbuilder = new ModelBuilder(model, toolcontext)
var mmodules = mbuilder.parse_full(arguments)

# process
if mmodules.is_empty then return
mbuilder.run_phases
toolcontext.run_global_phases(mmodules)
src/nitweb.nit:15,1--149,39