diff --git a/docs/style-spec/_generate/expression-types.js b/docs/style-spec/_generate/expression-metadata.js similarity index 86% rename from docs/style-spec/_generate/expression-types.js rename to docs/style-spec/_generate/expression-metadata.js index 5b8dfaa6a05..7b6b181c0b3 100644 --- a/docs/style-spec/_generate/expression-types.js +++ b/docs/style-spec/_generate/expression-metadata.js @@ -1,13 +1,14 @@ 'use strict'; require('flow-remove-types/register'); +const ref = require('../../../src/style-spec/reference/latest'); const toString = require('../../../src/style-spec/function/types').toString; const CompoundExpression = require('../../../src/style-spec/function/compound_expression').CompoundExpression; // registers compound expressions require('../../../src/style-spec/function/definitions'); -const results = { +const types = { string: [{ type: 'String', parameters: ['Value'] @@ -114,12 +115,12 @@ const results = { for (const name in CompoundExpression.definitions) { const definition = CompoundExpression.definitions[name]; if (Array.isArray(definition)) { - results[name] = [{ + types[name] = [{ type: toString(definition[0]), parameters: processParameters(definition[1]) }]; } else { - results[name] = definition.overloads.map((o) => { + types[name] = definition.overloads.map((o) => { return { type: toString(definition.type), parameters: processParameters(o[0]) @@ -128,7 +129,21 @@ for (const name in CompoundExpression.definitions) { } } -delete results['error']; +delete types['error']; + +const expressions = {}; +const expressionGroups = {}; +for (const name in types) { + const spec = ref['expression_name'].values[name]; + expressionGroups[spec.group] = expressionGroups[spec.group] || []; + expressionGroups[spec.group].push(name); + + expressions[name] = { + name: name, + doc: spec.doc, + type: types[name] + }; +} function processParameters(params) { if (Array.isArray(params)) { @@ -138,4 +153,4 @@ function processParameters(params) { } } -module.exports = results; +module.exports = {expressions, expressionGroups}; diff --git a/docs/style-spec/_generate/expression.html b/docs/style-spec/_generate/expression.html index fa07d5ad5bd..e3d51556e1e 100644 --- a/docs/style-spec/_generate/expression.html +++ b/docs/style-spec/_generate/expression.html @@ -1,8 +1,8 @@
- <%= md("" + name + " " + (expressionDocs[name] ? ('
' + expressionDocs[name].doc) : '').trim()) %> + <%= md("" + name + " " + (doc ? ('
' + doc) : '').trim()) %>
- <% for (const overload of expressionTypes[name]) { %> + <% for (const overload of type) { %>
{% highlight javascript %} <%=renderSignature(name, overload) %> diff --git a/docs/style-spec/_generate/generate.js b/docs/style-spec/_generate/generate.js index 0d49b4850c3..46b3f611c6a 100755 --- a/docs/style-spec/_generate/generate.js +++ b/docs/style-spec/_generate/generate.js @@ -2,44 +2,62 @@ // GL style reference generator -var fs = require('fs'); -var path = require('path'); -var ref = require('../../../src/style-spec/reference/latest'); -var _ = require('lodash'); -var remark = require('remark'); -var html = require('remark-html'); +const fs = require('fs'); +const path = require('path'); +const assert = require('assert'); +const ref = require('../../../src/style-spec/reference/latest'); +const _ = require('lodash'); +const remark = require('remark'); +const html = require('remark-html'); -var expressionTypes = require('./expression-types'); +const {expressions, expressionGroups} = require('./expression-metadata'); +const groupedExpressions = [ + 'Types', + 'Feature data', + 'Lookup', + 'Decision', + 'Ramps, scales, curves', + 'Variable binding', + 'String', + 'Color', + 'Math', + 'Zoom' +].map(group => ({ + name: group, + expressions: expressionGroups[group] + .sort((a, b) => a.localeCompare(b)) + .map(name => expressions[name]) +})); + +assert(groupedExpressions.length === Object.keys(expressionGroups).length, 'All expression groups accounted for in generated docs'); function tmpl(x, options) { return _.template(fs.readFileSync(path.join(__dirname, x), 'utf-8'), options); } -var index = tmpl('index.html', { - imports: { - _: _, - item: tmpl('item.html', { - imports: { - _: _, - md: function(markdown) { - return remark().use(html).process(markdown); - } - } - }), - expressions: Object.keys(expressionTypes).sort((a, b) => a.localeCompare(b)), - renderExpression: tmpl('expression.html', { - imports: { +const index = tmpl('index.html', { + imports: { _: _, - expressionDocs: ref['expression_name'].values, - expressionTypes: expressionTypes, - renderSignature: renderSignature, - md: function(markdown) { - return remark().use(html).process(markdown) - } - } - }) - } + item: tmpl('item.html', { + imports: { + _: _, + md: function(markdown) { + return remark().use(html).process(markdown); + } + } + }), + groupedExpressions: groupedExpressions, + renderExpression: tmpl('expression.html', { + imports: { + _: _, + renderSignature: renderSignature, + md: function(markdown) { + return remark().use(html).process(markdown); + } + } + }) + } }); function renderSignature (name, overload) { diff --git a/docs/style-spec/_generate/index.html b/docs/style-spec/_generate/index.html index faa967f3951..545c82cdb16 100755 --- a/docs/style-spec/_generate/index.html +++ b/docs/style-spec/_generate/index.html @@ -1020,8 +1020,11 @@

Example: a zoom-and-property function

Expression

- <% for (var name of expressions) { %> - <%= renderExpression({name: name}) %> + <% for (var group of groupedExpressions) { %> +

<%= group.name %>

+ <% for (var expression of group.expressions) { %> + <%= renderExpression(expression) %> + <% } %> <% } %>
diff --git a/src/style-spec/reference/v8.json b/src/style-spec/reference/v8.json index fe5c5469773..bd85022d4cf 100644 --- a/src/style-spec/reference/v8.json +++ b/src/style-spec/reference/v8.json @@ -1845,187 +1845,248 @@ "type": "enum", "values": { "let": { - "doc": "Binds expressions to named variables, which can then be referenced in the result expression using [\"var\", \"variable_name\"]." + "doc": "Binds expressions to named variables, which can then be referenced in the result expression using [\"var\", \"variable_name\"].", + "group": "Variable binding" }, "var": { - "doc": "References variable bound using \"let\"." + "doc": "References variable bound using \"let\".", + "group": "Variable binding" }, "literal": { - "doc": "Provides a literal array or object value." + "doc": "Provides a literal array or object value.", + "group": "Types" }, "array": { - "doc": "Asserts that the input is an array (optinally with a specific item type and length)." + "doc": "Asserts that the input is an array (optinally with a specific item type and length).", + "group": "Types" }, "at": { - "doc": "Retrieves an item from an array." + "doc": "Retrieves an item from an array.", + "group": "Lookup" }, "contains": { - "doc": "Tests whether a value exists in an array." + "doc": "Tests whether a value exists in an array.", + "group": "Lookup" }, "case": { - "doc": "Yields the value of the first output expression whose corresponding test evaluates to true." + "doc": "Yields the value of the first output expression whose corresponding test evaluates to true.", + "group": "Decision" }, "match": { - "doc": "Yields the output value whose label value matches the input, or the fallback value if no match is found." + "doc": "Yields the output value whose label value matches the input, or the fallback value if no match is found.", + "group": "Decision" }, "coalesce": { - "doc": "Evaluates each expression in turn until the first non-null value is obtained, and returns that value." + "doc": "Evaluates each expression in turn until the first non-null value is obtained, and returns that value.", + "group": "Decision" }, "curve": { - "doc": "Interpolates an output value from the given input/output pairs using the specified interpolation strategy. The input levels must be numeric literals in strictly ascending order." + "doc": "Interpolates an output value from the given input/output pairs using the specified interpolation strategy. The input levels must be numeric literals in strictly ascending order.", + "group": "Ramps, scales, curves" }, "ln2": { - "doc": "Returns mathematical constant ln(2)." + "doc": "Returns mathematical constant ln(2).", + "group": "Math" }, "pi": { - "doc": "Returns the mathematical constant pi." + "doc": "Returns the mathematical constant pi.", + "group": "Math" }, "e": { - "doc": "Returns the mathematical constant e." + "doc": "Returns the mathematical constant e.", + "group": "Math" }, "typeof": { - "doc": "Returns a string describing the type of the given value." + "doc": "Returns a string describing the type of the given value.", + "group": "Types" }, "string": { - "doc": "Asserts that the input value is a String. If multiple values are provided, each one is evaluated in order until a String value is obtained." + "doc": "Asserts that the input value is a String. If multiple values are provided, each one is evaluated in order until a String value is obtained.", + "group": "Types" }, "number": { - "doc": "Asserts that the input value is a Number. If multiple values are provided, each one is evaluated in order until a Number value is obtained." + "doc": "Asserts that the input value is a Number. If multiple values are provided, each one is evaluated in order until a Number value is obtained.", + "group": "Types" }, "boolean": { - "doc": "Asserts that the input value is a Boolean. If multiple values are provided, each one is evaluated in order until a Boolean value is obtained." + "doc": "Asserts that the input value is a Boolean. If multiple values are provided, each one is evaluated in order until a Boolean value is obtained.", + "group": "Types" }, "object": { - "doc": "Asserts that the input value is an Objects." + "doc": "Asserts that the input value is an Objects.", + "group": "Types" }, "to-string": { - "doc": "Coerces the input value to a String." + "doc": "Coerces the input value to a String.", + "group": "Types" }, "to-number": { - "doc": "Coerces the input value to a Number, if possible. If multiple values are provided, each one is evaluated in order until the first successful conversion is obtained." + "doc": "Coerces the input value to a Number, if possible. If multiple values are provided, each one is evaluated in order until the first successful conversion is obtained.", + "group": "Types" }, "to-boolean": { - "doc": "Coerces the input value to a Boolean." + "doc": "Coerces the input value to a Boolean.", + "group": "Types" }, "to-rgba": { - "doc": "Returns the an array of the given color's r, g, b, a components." + "doc": "Returns the an array of the given color's r, g, b, a components.", + "group": "Color" }, "to-color": { - "doc": "Coerces the input value to a Color. If multiple values are provided, each one is evaluated in order until the first successful conversion is obtained." + "doc": "Coerces the input value to a Color. If multiple values are provided, each one is evaluated in order until the first successful conversion is obtained.", + "group": "Types" }, "rgb": { - "doc": "Creates a color value from r, g, b components." + "doc": "Creates a color value from r, g, b components.", + "group": "Color" }, "rgba": { - "doc": "Creates a color value from r, g, b, a components." + "doc": "Creates a color value from r, g, b, a components.", + "group": "Color" }, "get": { - "doc": "Retrieves an the object property value. If it's not provided, the object argument defaults to [\"properties\"]. Returns null if the requested property is missing from the object." + "doc": "Retrieves an the object property value. If it's not provided, the object argument defaults to [\"properties\"]. Returns null if the requested property is missing from the object.", + "group": "Lookup" }, "has": { - "doc": "Tests for the presence of an object property value. If it's not provided, the object argument defaults to [\"properties\"]." + "doc": "Tests for the presence of an object property value. If it's not provided, the object argument defaults to [\"properties\"].", + "group": "Lookup" }, "length": { - "doc": "Gets the length of an array or string." + "doc": "Gets the length of an array or string.", + "group": "Lookup" }, "properties": { - "doc": "Gets the feature properties object. Note that in some cases, it may be more efficient to use [\"get\", \"property_name\"] directly." + "doc": "Gets the feature properties object. Note that in some cases, it may be more efficient to use [\"get\", \"property_name\"] directly.", + "group": "Feature data" }, "geometry-type": { - "doc": "Gets the feature's geometry type: Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon." + "doc": "Gets the feature's geometry type: Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon.", + "group": "Feature data" }, "id": { - "doc": "Gets the feature's id, if it has one." + "doc": "Gets the feature's id, if it has one.", + "group": "Feature data" }, "zoom": { - "doc": "Gets the current zoom level. Note that in style layout and paint properties, [\"zoom\"] may only appear as the input to a top-level [\"curve\"] expression." + "doc": "Gets the current zoom level. Note that in style layout and paint properties, [\"zoom\"] may only appear as the input to a top-level [\"curve\"] expression.", + "group": "Zoom" }, "+": { - "doc": "" + "doc": "", + "group": "Math" }, "*": { - "doc": "" + "doc": "", + "group": "Math" }, "-": { - "doc": "" + "doc": "", + "group": "Math" }, "/": { - "doc": "" + "doc": "", + "group": "Math" }, "%": { - "doc": "" + "doc": "", + "group": "Math" }, "^": { - "doc": "" + "doc": "", + "group": "Math" }, "log10": { - "doc": "" + "doc": "", + "group": "Math" }, "ln": { - "doc": "" + "doc": "", + "group": "Math" }, "log2": { - "doc": "" + "doc": "", + "group": "Math" }, "sin": { - "doc": "" + "doc": "", + "group": "Math" }, "cos": { - "doc": "" + "doc": "", + "group": "Math" }, "tan": { - "doc": "" + "doc": "", + "group": "Math" }, "asin": { - "doc": "" + "doc": "", + "group": "Math" }, "acos": { - "doc": "" + "doc": "", + "group": "Math" }, "atan": { - "doc": "" + "doc": "", + "group": "Math" }, "min": { - "doc": "" + "doc": "", + "group": "Math" }, "max": { - "doc": "" + "doc": "", + "group": "Math" }, "==": { - "doc": "" + "doc": "", + "group": "Decision" }, "!=": { - "doc": "" + "doc": "", + "group": "Decision" }, ">": { - "doc": "" + "doc": "", + "group": "Decision" }, "<": { - "doc": "" + "doc": "", + "group": "Decision" }, ">=": { - "doc": "" + "doc": "", + "group": "Decision" }, "<=": { - "doc": "" + "doc": "", + "group": "Decision" }, "&&": { - "doc": "" + "doc": "", + "group": "Decision" }, "||": { - "doc": "" + "doc": "", + "group": "Decision" }, "!": { - "doc": "" + "doc": "", + "group": "Decision" }, "upcase": { - "doc": "" + "doc": "", + "group": "String" }, "downcase": { - "doc": "" + "doc": "", + "group": "String" }, "concat": { - "doc": "Concetenate the given strings." + "doc": "Concetenate the given strings.", + "group": "String" } } },