build(aio): move attribute utils to helpers folder

This allows these utility functions to be reused across packages.
This commit is contained in:
Peter Bacon Darwin 2017-04-26 17:58:57 +01:00 committed by Matias Niemelä
parent c889fb1ef5
commit 6d9da73090
5 changed files with 8 additions and 5 deletions

View File

@ -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 {

View File

@ -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</${element}>`;
return `<${element}${renderAttributes(attrMap)}>\n${exampleContent}\n</${element}>`;
}
// No path attribute so just ignore this one
return original;

View File

@ -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;

View File

@ -89,5 +89,9 @@ module.exports = {
}
return attrMap;
},
renderAttributes(attrMap) {
return Object.keys(attrMap).map(key => ` ${key}="${attrMap[key].replace(/"/g, '&quot;')}"`).join('');
}
};