build(aio): move attribute utils to helpers folder
This allows these utility functions to be reused across packages.
This commit is contained in:
parent
c889fb1ef5
commit
6d9da73090
|
@ -1,5 +1,5 @@
|
||||||
const {extname} = require('canonical-path');
|
const {extname} = require('canonical-path');
|
||||||
const {mapObject} = require('../utils');
|
const {mapObject} = require('../../helpers/utils');
|
||||||
|
|
||||||
module.exports = function collectExamples(exampleMap, regionParser, log, createDocMessage) {
|
module.exports = function collectExamples(exampleMap, regionParser, log, createDocMessage) {
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -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.
|
* 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) {
|
if (attrMap.path) {
|
||||||
// We found a path attribute so look up the example and rebuild the HTML
|
// We found a path attribute so look up the example and rebuild the HTML
|
||||||
const exampleContent = getExampleRegion(doc, attrMap.path, attrMap.region);
|
const exampleContent = getExampleRegion(doc, attrMap.path, attrMap.region);
|
||||||
attributes = Object.keys(attrMap).map(key => ` ${key}="${attrMap[key].replace(/"/g, '"')}"`).join('');
|
return `<${element}${renderAttributes(attrMap)}>\n${exampleContent}\n</${element}>`;
|
||||||
return `<${element}${attributes}>\n${exampleContent}\n</${element}>`;
|
|
||||||
}
|
}
|
||||||
// No path attribute so just ignore this one
|
// No path attribute so just ignore this one
|
||||||
return original;
|
return original;
|
||||||
|
|
|
@ -4,7 +4,7 @@ const inlineC = require('./region-matchers/inline-c');
|
||||||
const inlineCOnly = require('./region-matchers/inline-c-only');
|
const inlineCOnly = require('./region-matchers/inline-c-only');
|
||||||
const inlineHash = require('./region-matchers/inline-hash');
|
const inlineHash = require('./region-matchers/inline-hash');
|
||||||
const DEFAULT_PLASTER = '. . .';
|
const DEFAULT_PLASTER = '. . .';
|
||||||
const {mapObject} = require('../utils');
|
const {mapObject} = require('../../helpers/utils');
|
||||||
|
|
||||||
module.exports = function regionParser() {
|
module.exports = function regionParser() {
|
||||||
return regionParserImpl;
|
return regionParserImpl;
|
||||||
|
|
|
@ -89,5 +89,9 @@ module.exports = {
|
||||||
}
|
}
|
||||||
|
|
||||||
return attrMap;
|
return attrMap;
|
||||||
|
},
|
||||||
|
|
||||||
|
renderAttributes(attrMap) {
|
||||||
|
return Object.keys(attrMap).map(key => ` ${key}="${attrMap[key].replace(/"/g, '"')}"`).join('');
|
||||||
}
|
}
|
||||||
};
|
};
|
Loading…
Reference in New Issue