diff --git a/modules/core/context.js b/modules/core/context.js index 25a72c2ae..57e7178b8 100644 --- a/modules/core/context.js +++ b/modules/core/context.js @@ -8,12 +8,7 @@ import _isString from 'lodash-es/isString'; import _map from 'lodash-es/map'; import { dispatch as d3_dispatch } from 'd3-dispatch'; - -import { - json as d3_json, - text as d3_text -} from 'd3-request'; - +import { json as d3_json } from 'd3-request'; import { select as d3_select } from 'd3-selection'; import { @@ -461,9 +456,11 @@ export function coreContext() { if (utilExternalValidationRules()) { var validationsUrl = utilStringQs(window.location.hash).validations; - d3_text(validationsUrl, function (err, mapcss) { + d3_json(validationsUrl, function (err, mapcssConfigs) { if (err) return; - var validations = _map(mapcss, function(mapcss) { return utilMapCSSRule(mapcss, context.presets().areaKeys()); }); + var validations = _map(mapcssConfigs, function(mapcssConfig) { + return utilMapCSSRule(mapcssConfig, context.presets().areaKeys()); + }); context.validationRules = function() { return validations; }; }); } diff --git a/modules/util/mapcss_rule.js b/modules/util/mapcss_rule.js index 7187bdb90..ab0b68c3b 100644 --- a/modules/util/mapcss_rule.js +++ b/modules/util/mapcss_rule.js @@ -59,8 +59,11 @@ export function utilMapCSSRule(selector, areaKeys) { .map(function(key) { return ruleChecks[key]; }); }, + selector: function() { + return selector; + }, buildTagMap: function() { - var selectorKeys = Object.keys(selector); + var selector = this.selector(), selectorKeys = Object.keys(selector); var tagMap = _reduce(selectorKeys, function (expectedTags, key) { var values; if (/regex/gi.test(key)) { @@ -146,7 +149,7 @@ export function utilMapCSSRule(selector, areaKeys) { if (entity.type === 'node' || entity.type === 'relation') { return selector.geometry === entity.type; } else if (entity.type === 'way') { - return this.inferGeometry(areaKeys) === entity.geometry(graph); + return this.inferGeometry() === entity.geometry(graph); } }, findWarnings: function (entity, graph, warnings) { diff --git a/test/spec/util/mapcss_rule.js b/test/spec/util/mapcss_rule.js index 0052dc05d..d6168b750 100644 --- a/test/spec/util/mapcss_rule.js +++ b/test/spec/util/mapcss_rule.js @@ -47,7 +47,7 @@ describe('iD.utilMapCSSRule', function() { var rules = selectors.map(function(s) { return iD.utilMapCSSRule(s, areaKeys); }); it ('turns selector object in mapcssRule', function () { var ruleKeys = [ - 'ruleChecks', 'type','buildChecks', 'buildTagMap', 'matches', + 'ruleChecks', 'type','buildChecks', 'selector', 'buildTagMap', 'matches', 'areaKeys', 'inferGeometry', 'geometryMatches','findWarnings' ]; rules.forEach(function(rule) { @@ -110,7 +110,13 @@ describe('iD.utilMapCSSRule', function() { }); }); }); - describe('areaKeys', function() { + describe('#selector', function() { + it('returns selector used to construct rule', function() { + var rule = iD.utilMapCSSRule(selectors[1], areaKeys); + expect(rule.selector()).to.eql(selectors[1]); + }); + }); + describe('#areaKeys', function() { it('returns areaKeys used to construct rule', function() { var rule = iD.utilMapCSSRule(selectors[0], areaKeys); expect(rule.areaKeys()).to.eql(areaKeys);