Bruker:Jeblad/Module:JSONstat/dok
The purpose of this module is to demonstrate handling of JSON-stat in Lua with closure-based instances modelled as lazy facades. The instances will not be created before boundraries are passed, that is a method returns a value that is wrapped in a closure. This makes a fairly efficient implementation for simple access, but it is not very efficient as it does not cache much of the processing.
The library can be used as simple calls through the invoke parser function, but it is really made as a support library. A main purpose for the lib is to provide Vega-formatted data, often constrained or adapted somehow to fit better with other available data.
Primary access point is the load-method, which will parse one of several sources and return an instance according to the provided data. In Lua-code the instance can be navigated by using provided methods, while in wikitext it is possible to use layout (format) parameters. One such predefined layout could be to create data for Vega, which is nothing more than the dataset values as an expanded table.
Usage
In wikicode the module will typically be called like one of the following
{{#invoke:JSONstat | load | updated }}
{{#invoke:JSONstat | load | Q123456 | label }}
{{#invoke:JSONstat | load | Bruker:Jeblad/SSB01222.json | ${source:%.10s} }}
{{#invoke:JSONstat | load | { ... } | expanded }}
The first one uses the connected item to identify the external JSON-stat dataset (not implemented). This use a layout pragma that reports the datestamp for when it was last updated. The second form identifies an item to use for further identification of a JSON-dataset (not implemented). This use a layout pragma that reports the embedded label. The third form uses identifies a page that contain the dataset. This use an inline format as layout pragma, and reports a truncated source string. The fourth form use an inline definition of the dataset. This use a layout pragma that reports the values on expanded form, that is whats used in Vega.
Similar calls in Lua-code would be similar to the following
local jsonstat = require('Module:JSONstat')
jsonstat.load().updated()
jsonstat.load( 'updated' )
jsonstat.load( 'Q123456' ).label()
jsonstat.load( 'Q123456', 'label' )
jsonstat.load( 'Bruker:Jeblad/SSB01222.json' ).layout( '${source:%.10s}' )
jsonstat.load( 'Bruker:Jeblad/SSB01222.json', '${source:%.10s}' )
jsonstat.load( { ... } ).expanded()
jsonstat.load( { ... }, 'expanded' )