packages/heml-render/src/index.js
async function renderElements (elements, globals) {
  const { $ } = globals
  const elementMap = keyBy(elements, 'tagName')
  const metaTagNames = filter(elements, { parent: [ 'head' ] }).map(({ tagName }) => tagName)
  const nonMetaTagNames = difference(elements.map(({ tagName }) => tagName), metaTagNames)

  const $nodes = [
    ...$.findNodes(metaTagNames), /** Render the meta elements first to last */
    ...$.findNodes(nonMetaTagNames).reverse() /** Render the elements last to first/outside to inside */
  ]

  for (let $node of $nodes) {
    const element = elementMap[$node.prop('tagName').toLowerCase()]
    const contents = $node.html()
    const attrs = $node[0].attribs

    const renderedValue = await Promise.resolve(renderElement(element, attrs, contents))

    $node.replaceWith(renderedValue.trim())
  }
}
async function renderElements (elements, globals) {
  const { $ } = globals
  const elementMap = keyBy(elements, 'tagName')
  const metaTagNames = filter(elements, { parent: [ 'head' ] }).map(({ tagName }) => tagName)
  const nonMetaTagNames = difference(elements.map(({ tagName }) => tagName), metaTagNames)

  const $nodes = [
    ...$.findNodes(metaTagNames), /** Render the meta elements first to last */
    ...$.findNodes(nonMetaTagNames).reverse() /** Render the elements last to first/outside to inside */
  ]

  for (let $node of $nodes) {
    const element = elementMap[$node.prop('tagName').toLowerCase()]
    const contents = $node.html()
    const attrs = $node[0].attribs

    const renderedValue = await Promise.resolve(renderElement(element, attrs, contents))

    $node.replaceWith(renderedValue.trim())
  }
}
async function renderElements ( elements , globals ) { const { $ } = globals const elementMap = keyBy ( elements , 'tagName' ) const metaTagNames = filter ( elements , { parent : [ 'head' ] } ) . map ( ( { tagName } ) => tagName ) const nonMetaTagNames = difference ( elements . map ( ( { tagName } ) => tagName ) , metaTagNames ) const $nodes = [ ... $ . findNodes ( metaTagNames ) , /** Render the meta elements first to last */ ... $ . findNodes ( nonMetaTagNames ) . reverse ( ) /** Render the elements last to first/outside to inside */ ] for ( let $node of $nodes ) { const element = elementMap [ $node . prop ( 'tagName' ) . toLowerCase ( ) ] const contents = $node . html ( ) const attrs = $node [ 0 ] . attribs const renderedValue = await Promise . resolve ( renderElement ( element , attrs , contents ) ) $node . replaceWith ( renderedValue . trim ( ) ) } }
Renders all HEML elements
@param  {Array}  elements  List of element definitons
@param  {Object} globals
@return {Promise}
Renders all HEML elements