-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update stale links ref #1 * fix instructions ref #1 * fix build script ref #1 * update readmen ref #1 * update gitignore to push needed rules dir ref #1 * remove maprules-ui artifacts * update stale links,0 bad instructions in readme, messed up package json, and bad build script (#2) * update stale links ref #1 * fix instructions ref #1 * fix build script ref #1 * update readmen ref #1 * update gitignore to push needed rules dir ref #1 * 5 (#7) * begin circleci setup ref #5 * hey, don't forget about schemas dir rules! ref #5 * update build just to see of circle recognizes ref #5 * pluck fontawesome ref #4
- Loading branch information
1 parent
0afe788
commit 6217985
Showing
26 changed files
with
371 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
version: 2 | ||
jobs: | ||
build: | ||
working_directory: ~/maprules | ||
docker: | ||
- image: circleci/node:10.7.0 | ||
steps: | ||
- checkout | ||
- run: | ||
name: update-npm | ||
command: 'sudo npm install -g npm@latest' | ||
- run: | ||
name: install dependencies | ||
command: 'npm install --save sqlite3 && npm install' | ||
- run: | ||
name: build | ||
command: 'npm run build' | ||
- run: | ||
name: fixture | ||
command: 'NODE_ENV=testing npm run fixture' | ||
- run: | ||
name: test | ||
command: 'npm test' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ package-lock.json | |
doc | ||
spec | ||
rules/ | ||
!adapters/rules | ||
!schemas/rules | ||
maprule/ | ||
db/*.sqlite | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# 0.0.1-alpha | ||
|
||
##### September 30th, 2018 | ||
##### October 9th, 2018 | ||
|
||
- :tada: first release! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
|
||
const buildTagChecks = require('./tagChecks'); | ||
const buildDisabledFeatureChecks = require('../../disabledFeatures'); | ||
|
||
const translateOsmType = require('../../helpers').translateOsmType; | ||
const flattenElements = require('../../helpers').flattenElements; | ||
const inferJosmGeometries = require('../../josmPresets/helpers').inferJosmGeometries; | ||
|
||
/** | ||
* Provided presetConfig, replies rules used to build MapCSS | ||
* replies a single mapcss rule config. | ||
* @param {Object} config presetConfig | ||
* @return {Object} single mapcss rule config. | ||
*/ | ||
module.exports = (config) => { | ||
const configRules = config.presets.map((preset) => { | ||
const rules = preset.fields.map((field) => { | ||
return buildTagChecks(field, preset.primary, preset.name, config.name); | ||
}); | ||
|
||
return inferJosmGeometries(preset.geometry).map((geometry) => { | ||
return { | ||
osmType: geometry, | ||
rules: flattenElements(rules) | ||
}; | ||
}); | ||
}); | ||
|
||
if (config.hasOwnProperty('disabledFeatures')) { | ||
const disabledFeatures = ['node', 'way'].map((geom) => { | ||
return buildDisabledFeatureChecks(config.disabledFeatures, geom, config.name); | ||
}); | ||
configRules.concat(disabledFeatures); | ||
} | ||
|
||
return flattenElements(configRules); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
|
||
const adaptEqualityToConditional = require('../../../../helpers').adaptEqualityToConditional; | ||
const escaped = require('../../../../helpers').escaped; | ||
|
||
/** | ||
* Provided parameters for rule's truthiness and severity, | ||
* returns config used to build mapcss selector and validation error/warning | ||
* @param {String} key key part of selector's key, value pair | ||
* @param {Boolean} valCondition defines truthiness of rule when equalityValues are present | ||
* @param {Array} equalityValues values, that if present, define the possible values that if coupled / not coupled with key, cause an validation error/warning | ||
* @return {Object} config object used to build mapcss selector and validation error/warning | ||
*/ | ||
const _alpha = (key, value) => { | ||
const values = value.values.map(v => `^${escaped(v.split(' - ')[0])}$`).join('|'); | ||
const equality = value.valCondition ? '!~' : '=~'; | ||
return [`[${key}][${key}${equality}/${values}/]`]; | ||
}; | ||
|
||
/** | ||
* Provided key and numericEquality object, | ||
* replies config used to build mapcss selector and validation error/warning | ||
* @param {String} key key part of the selector's key/val pair | ||
* @param {Object} numericEquality subset of numeric values object | ||
* @return {string} string component of mapcss config | ||
*/ | ||
const _numeric = (key, value) => { | ||
return [adaptEqualityToConditional(key, value)]; | ||
}; | ||
|
||
module.exports = { | ||
numeric: _numeric, | ||
alpha: _alpha | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
|
||
const THROW_ERROR = require('../../../constants').THROW_ERROR; | ||
const THROW_WARNING = require('../../../constants').THROW_WARNING; | ||
|
||
const message = require('./message'); | ||
const fieldConditional = require('./fieldConditional'); | ||
const getToThrow = require('../../../helpers').getToThrow; | ||
const impliesEqual = require('../../../helpers').impliesEqual; | ||
|
||
/** | ||
* Provided field and primary key, | ||
* replies array of configs defining mapcss selectors | ||
* @param {object} field field config from preset within presetConfig | ||
* @param {object} primary primary tag config from field config | ||
* @return {array} array of configs defining mapcss selectors | ||
*/ | ||
module.exports = (field, primary, presetName,) => { | ||
const keyCondition = Number(field.keyCondition); | ||
const values = field.values; | ||
const tagChecks = []; | ||
const tagCheckBase = primary.map(p => `[${p.key}=${p.val}]`).join(''); | ||
const conditionalVerb = keyCondition === 0 ? 'must not' : keyCondition === 1 ? 'must' : 'may'; | ||
|
||
tagChecks.push({ | ||
base: tagCheckBase, | ||
fieldConditionals: [keyCondition !== 0 ? `[!${field.key}]` : `[${field.key}]`], | ||
toThrow: keyCondition !== 2 ? THROW_ERROR : THROW_WARNING, | ||
message: `'${presetName}' preset ${conditionalVerb} include ${field.key}` | ||
}); | ||
|
||
if (keyCondition !== 0) { | ||
values.forEach((value) => { | ||
const checkType = value.valCondition > 2 || impliesEqual(values) ? 'numeric' : 'alpha'; | ||
|
||
const messageBuilder = message[checkType]; | ||
const fieldConditionBuilder = fieldConditional[checkType]; | ||
|
||
tagChecks.push({ | ||
base: tagCheckBase, | ||
toThrow: getToThrow(value), | ||
fieldConditionals: fieldConditionBuilder(field.key, value), | ||
message: messageBuilder(field.key, value) | ||
}); | ||
}); | ||
|
||
} | ||
|
||
return tagChecks; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
const adaptNumericToMessage = require('../../../../helpers').adaptNumericToMessage; | ||
|
||
/** | ||
* builds a error message for alpha (so string based) rules | ||
* @param {Array} equalityValues list of equality values to be adapted to error messages | ||
* @param {Number} messageMatch numeric encoding of must/must not/may | ||
* @return {String} error message | ||
*/ | ||
const _alpha = (key, value) => { | ||
const valuesString = value.values.map(v => `'${v}'`).join(','); | ||
let conditionalMessage = ''; | ||
if (value.valCondition === 0) conditionalMessage += 'must not'; | ||
if (value.valCondition === 1) conditionalMessage += 'must'; | ||
if (value.valCondition === 2) conditionalMessage += 'may'; | ||
return `${key} ${conditionalMessage} be ${valuesString}`; | ||
}; | ||
|
||
/** | ||
* builds a error message for numeric rules | ||
* @param {Array} equalityValues list of equality values to be adapted to error messages | ||
* @return {String} error message | ||
*/ | ||
const _numeric = (key, value) => { | ||
const valueString = adaptNumericToMessage(value.values[0], value.valCondition); | ||
return `${key} must be ${valueString}`; | ||
}; | ||
|
||
module.exports = { | ||
alpha: _alpha, | ||
numeric: _numeric | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
const buildRulesConfig = require('./config'); | ||
const buildMapCSS = require('./mapCSS'); | ||
|
||
/** | ||
* Provided a preset config, adapts/generates | ||
* mapcss string reflecting rules written inside config | ||
* @param {Object} config presetConfig | ||
* @return {String} mapcss string | ||
*/ | ||
module.exports = (config) => { | ||
try { | ||
const rulesConfig = buildRulesConfig(config); | ||
return buildMapCSS(rulesConfig); | ||
} catch (error) { | ||
throw error; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
|
||
const buildRule = require('./rule'); | ||
const flattenElements = require('../../helpers').flattenElements; | ||
|
||
/** | ||
* Provided mapcss config, replies mapcss string | ||
* @param {Object} config the mapcss config | ||
* @return {String} mapcss string | ||
*/ | ||
module.exports = (config) => { | ||
return flattenElements(config.map((configRule) => { | ||
return configRule.rules.map((tagCheck) => { | ||
return buildRule(tagCheck, configRule.osmType); | ||
}); | ||
})).join(''); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
|
||
/** | ||
* | ||
* @param {Object} rule config for mapcss tag selector | ||
* @param {String} osmType osmType that prepends tag selector | ||
* @return {String} mapcss selector | ||
*/ | ||
module.exports = (rule, osmType) => { | ||
const isClosed = osmType === 'closedway'; | ||
const fieldConditionals = rule.fieldConditionals; | ||
const toThrow = rule.toThrow; | ||
|
||
let selectors = ''; | ||
if (fieldConditionals !== undefined) { | ||
selectors += fieldConditionals.map(fieldConditional => { | ||
|
||
let selector = `${isClosed ? 'way': osmType}${rule.base}${fieldConditional}`; | ||
if (isClosed) { | ||
selector += ':closed'; | ||
} | ||
|
||
return selector; | ||
|
||
}).join(fieldConditionals.length > 1 ? ',\n' : ''); | ||
|
||
} else { | ||
selectors += `${isClosed ? 'way' : osmType}${rule.base}`; | ||
|
||
} | ||
return `${selectors}{ | ||
${toThrow}: "${rule.message}"; | ||
}\n`; | ||
}; |
Oops, something went wrong.