w3c/specberus

Name: specberus

Owner: World Wide Web Consortium

Description: Specberus is a checker used at W3C to validate the compliance of Technical Reports with publication rules.

Created: 2013-12-19 10:43:31.0

Updated: 2017-09-09 08:08:29.0

Pushed: 2017-12-29 08:19:07.0

Homepage: https://www.w3.org/pubrules/

Size: 3846

Language: HTML

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

npm version License Build Status Coverage Status Dependency Status devDependency Status

Specberus

Greenkeeper badge

Specberus is a checker used at W3C to validate the compliance of Technical Reports with publication rules.

  1. Installation
  2. Running
  3. Testing
  4. JS API
  5. REST API
  6. Profiles
  7. Validation events
  8. Writing rules
1. Installation

Specberus is a Node.js application, distributed through npm. Alternatively, you can clone the repository and run:

m install -d

In order to get all the dependencies installed. Naturally, this requires that you have a reasonably recent version of Node.js installed.

2. Running

Currently there is no shell to run Specberus. Later we will add both Web and CLI interfaces based on the same core library.

Syntax and command-line parameters
I_KEY="<YOUR W3C API KEY>" npm start [PORT]

Specberus relies on the W3C API to run a few checks. You will need to provide your key in an environment variable API_KEY

Meaning of positional parameters:

  1. PORT: where Specberus will be listening for HTTP connections. (Default 80.)

Examples:

I_KEY="<YOUR W3C API KEY>" npm start
I_KEY="<YOUR W3C API KEY>" npm start 3001

Set the environment variable DEBUG to run in debug mode instead:

BUG=true API_KEY="<YOUR W3C API KEY>" npm start

This modifies the behaviour of certain parts of the application to facilitate debugging. eg, CSS and JS resources will not be loaded in their minified/uglified forms (the web UI will load bootstrap.css, bootstrap.js and jquery.js instead of bootstrap.min.css, bootstrap.min.js and jquery.min.js).

If Specberus is not going to be served from the root directory of a domain, or if it will be served through a proxy, set also BASE_URI pointing to the public root URI of Specberus; eg

SE_URI=https://spec-store.com/check/ API_KEY=deadbeef npm start
SE_URI=/hostname/can/be/omitted/ API_KEY=deadbeef npm start 88
3. Testing

Testing is done using mocha. Simply run:

I_KEY="<YOUR W3C API KEY>" mocha

from the root and you will be running the test suite. Mocha can be installed with:

m install -g mocha

Some of the tests can on occasion take a long time, or fail outright because a remote service is unavailable. To work around this, you can set SKIP_NETWORK:

IP_NETWORK=1 API_KEY="<YOUR W3C API KEY>" mocha
4. JS API

The interface you get when you require("specberus") is that from lib/validator. It returns a Specberus instance that is properly configured for operation in the Node.js environment (there is nominal support for running Specberus under other environments, but it isn't usable at this time).

(See also the REST API.)

validate(options)

This method takes an object with the following fields:

extractMetadata(options)

This method eventually extends this with metadata inferred from the document. Once the event end-all is emitted, the metadata should be available in a new property called meta.

The options accepted are equal to those in validate(), except that a profile is not necessary and will be ignored (finding out the profile is one of the goals of this method).

this.meta will be an Object and may include up to 15 properties described below:

If some of these pieces of metadata cannot be deduced, that key will not exist, or its value will not be defined.

This is an example of the value of Specberus.meta after the execution of Specberus.extractMetadata():


rofile": "WD",
itle": "Title of the spec",
ocDate": "2016-2-3",
hisVersion": "http://www.w3.org/TR/2016/WD-foobar-20160203/",
atestVersion": "http://www.w3.org/TR/foobar/",
reviousVersion": "http://www.w3.org/TR/2015/WD-foobar-20150101/",
ditorsDraft": "http://w3c.github.io/foobar/",
elivererIDs": [123, 456],
ditorIDs": [ 12345 ],
nformative": false,
ectrack": true,
rocess": "http://www.w3.org/2015/Process-20150901/" }

5. REST API

Similar to the JS API, Specberus exposes a REST API via HTTP too.

The endpoint is <host>/api/. Use either url or file to pass along the document (neither source nor document are allowed).

Note: If you want to use the public W3C instance of Specberus, you can replace <host> with https://www.w3.org/pubrules.

There are three GET methods available.

version

Returns the version string, eg 1.5.3.

metadata

Extract all known metadata from a document; see below for information about the return value.

validate

Check the document (syntax). Many of the options understood by the JS method validate are accepted.

The special profile auto is also available.

Examples
Return values

Methods metadata and validate return a JSON object with these properties:

If there is an internal error, the document cannot be retrieved or is not recognised, or validation fails, both methods would return HTTP status code 400. Also, in the case of validate, success would be false and errors.length > 0.

This is an example of a successful validation of a document, with profile auto:

uccess": true,
rrors": [],
arnings":
 "headers.ol-toc",
 "links.linkchecker",
 "links.compound",
 "headers.dl" ],
nfo":
 "sotd.diff",
 "structure.display-only",
 "structure.display-only",
 "structure.display-only",
 "validation.wcag" ],
etadata":
 "profile": "WD",
 "title": "Character Model for the World Wide Web: String Matching and Searching",
 "docDate": "2016-4-7",
 "thisVersion": "http://www.w3.org/TR/2016/WD-charmod-norm-20160407/",
 "latestVersion": "http://www.w3.org/TR/charmod-norm/",
 "previousVersion": "http://www.w3.org/TR/2015/WD-charmod-norm-20151119/",
 "editorsDraft": "http://w3c.github.io/charmod-norm/",
 "delivererIDs": [ 32113 ],
 "editorIDs": [ 33573 ],
 "rectrack": false,
 "informative": false,
 "process": "http://www.w3.org/2015/Process-20150901/",
 "url": "https://www.w3.org/TR/2016/WD-charmod-norm-20160407/"


When the profile is given by the user (instead of being set to auto), fewer items of metadata are returned.

metadata returns a similar structure, where all values are empty arrays, except for the key metadata which contains the metadata object.

6. Profiles

Profiles are simple objects that support the following API:

A profile is basically a configuration of what to check. You can load a specific profile from under lib/profiles or create your own.

Here follows the current hierarchy of profiles. Each profile inherits all rules from its parent profile. Profiles that are identical to its parent profile, ie that do not add any new rules, are marked too.

7. Validation events

For a given checking run, the event sink you specify will be receiving a bunch of events as indicated below. Events are shown as having parameters since those are passed to the event handler.

8. Writing rules

Rules are simple modules that just expose a check(sr, cb) method. They receive a Specberus object and a callback, use the Specberus object to fire validation events and call the callback when they're done.

The Specberus object exposes the following API that's useful for validation:


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.