From 6d9da73090aa465b3591296614dab586fa17a34d Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Wed, 26 Apr 2017 17:58:57 +0100 Subject: [PATCH] build(aio): move attribute utils to helpers folder This allows these utility functions to be reused across packages. --- .../examples-package/processors/collect-examples.js | 2 +- .../examples-package/processors/render-examples.js | 5 ++--- .../transforms/examples-package/services/region-parser.js | 2 +- aio/tools/transforms/{examples-package => helpers}/utils.js | 4 ++++ .../transforms/{examples-package => helpers}/utils.spec.js | 0 5 files changed, 8 insertions(+), 5 deletions(-) rename aio/tools/transforms/{examples-package => helpers}/utils.js (93%) rename aio/tools/transforms/{examples-package => helpers}/utils.spec.js (100%) diff --git a/aio/tools/transforms/examples-package/processors/collect-examples.js b/aio/tools/transforms/examples-package/processors/collect-examples.js index c09baee5cc..a12782386b 100644 --- a/aio/tools/transforms/examples-package/processors/collect-examples.js +++ b/aio/tools/transforms/examples-package/processors/collect-examples.js @@ -1,5 +1,5 @@ const {extname} = require('canonical-path'); -const {mapObject} = require('../utils'); +const {mapObject} = require('../../helpers/utils'); module.exports = function collectExamples(exampleMap, regionParser, log, createDocMessage) { return { diff --git a/aio/tools/transforms/examples-package/processors/render-examples.js b/aio/tools/transforms/examples-package/processors/render-examples.js index 670dd0792a..9ff0ce19e8 100644 --- a/aio/tools/transforms/examples-package/processors/render-examples.js +++ b/aio/tools/transforms/examples-package/processors/render-examples.js @@ -1,4 +1,4 @@ -const { parseAttributes } = require('../utils'); +const { parseAttributes, renderAttributes } = require('../../helpers/utils'); /** * Search the renderedContent looking for code examples that have a path (and optionally a region) attribute. @@ -17,8 +17,7 @@ module.exports = function renderExamples(getExampleRegion) { if (attrMap.path) { // We found a path attribute so look up the example and rebuild the HTML const exampleContent = getExampleRegion(doc, attrMap.path, attrMap.region); - attributes = Object.keys(attrMap).map(key => ` ${key}="${attrMap[key].replace(/"/g, '"')}"`).join(''); - return `<${element}${attributes}>\n${exampleContent}\n`; + return `<${element}${renderAttributes(attrMap)}>\n${exampleContent}\n`; } // No path attribute so just ignore this one return original; diff --git a/aio/tools/transforms/examples-package/services/region-parser.js b/aio/tools/transforms/examples-package/services/region-parser.js index 76eb124bea..d996ce8301 100644 --- a/aio/tools/transforms/examples-package/services/region-parser.js +++ b/aio/tools/transforms/examples-package/services/region-parser.js @@ -4,7 +4,7 @@ const inlineC = require('./region-matchers/inline-c'); const inlineCOnly = require('./region-matchers/inline-c-only'); const inlineHash = require('./region-matchers/inline-hash'); const DEFAULT_PLASTER = '. . .'; -const {mapObject} = require('../utils'); +const {mapObject} = require('../../helpers/utils'); module.exports = function regionParser() { return regionParserImpl; diff --git a/aio/tools/transforms/examples-package/utils.js b/aio/tools/transforms/helpers/utils.js similarity index 93% rename from aio/tools/transforms/examples-package/utils.js rename to aio/tools/transforms/helpers/utils.js index 858263a844..f0291a417c 100644 --- a/aio/tools/transforms/examples-package/utils.js +++ b/aio/tools/transforms/helpers/utils.js @@ -89,5 +89,9 @@ module.exports = { } return attrMap; + }, + + renderAttributes(attrMap) { + return Object.keys(attrMap).map(key => ` ${key}="${attrMap[key].replace(/"/g, '"')}"`).join(''); } }; diff --git a/aio/tools/transforms/examples-package/utils.spec.js b/aio/tools/transforms/helpers/utils.spec.js similarity index 100% rename from aio/tools/transforms/examples-package/utils.spec.js rename to aio/tools/transforms/helpers/utils.spec.js