How to use the @teleporthq/teleport-plugin-common.ASTUtils.addChildJSXText function in @teleporthq/teleport-plugin-common

To help you get started, we’ve selected a few @teleporthq/teleport-plugin-common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github teleporthq / teleport-code-generators / packages / teleport-plugin-react-styled-jsx / src / utils.ts View on Github external
export const generateStyledJSXTag = (content: string): types.JSXElement => {
  const templateLiteral = ASTUtils.stringAsTemplateLiteral(content)
  const styleContent = ASTBuilders.createJSXExpresionContainer(templateLiteral)
  const styleTag = ASTBuilders.createJSXTag('style', [styleContent])
  ASTUtils.addChildJSXText(styleTag, '\n') // for better formatting
  ASTUtils.addAttributeToJSXTag(styleTag, 'jsx')
  return styleTag
}
github teleporthq / teleport-code-generators / packages / teleport-plugin-jsx-head-config / src / index.ts View on Github external
const componentChunk = chunks.find((chunk) => chunk.name === componentChunkName)
    if (!componentChunk) {
      throw new Error(
        `JSX component chunk with name ${componentChunkName} was required and not found.`
      )
    }

    if (!uidl.seo) {
      return structure
    }

    const headASTTags = []

    if (uidl.seo.title) {
      const titleAST = ASTBuilders.createJSXTag('title')
      ASTUtils.addChildJSXText(titleAST, uidl.seo.title)
      headASTTags.push(titleAST)
    }

    if (uidl.seo.metaTags) {
      uidl.seo.metaTags.forEach((tag) => {
        const metaAST = ASTBuilders.createSelfClosingJSXTag('meta')
        Object.keys(tag).forEach((key) => {
          ASTUtils.addAttributeToJSXTag(metaAST, key, tag[key])
        })
        headASTTags.push(metaAST)
      })
    }

    if (uidl.seo.assets) {
      uidl.seo.assets.forEach((asset) => {
        // TODO: Handle other asset types when needed
github teleporthq / teleport-code-generators / packages / teleport-project-generator-gatsby / src / utils.ts View on Github external
ASTUtils.addAttributeToJSXTag(httpMetaTag, 'httpEquiv', 'x-ua-compatible')
  ASTUtils.addAttributeToJSXTag(httpMetaTag, 'content', 'ie=edge')
  ASTUtils.addChildJSXTag(headNode, httpMetaTag)

  const viewPortMeta = ASTBuilders.createSelfClosingJSXTag('meta')
  ASTUtils.addAttributeToJSXTag(viewPortMeta, 'name', 'viewport')
  ASTUtils.addAttributeToJSXTag(
    viewPortMeta,
    'content',
    'width=device-width, initial-scale=1, shrink-to-fit=no'
  )
  ASTUtils.addChildJSXTag(headNode, viewPortMeta)

  addJSXExpressionContainer(bodyNode, 'props', 'preBodyComponents')

  ASTUtils.addChildJSXText(noScriptNode, 'This app works best with JavaScript enabled.')
  ASTUtils.addAttributeToJSXTag(noScriptNode, 'key', 'noscript')
  ASTUtils.addAttributeToJSXTag(noScriptNode, 'id', 'gatsby-noscript')
  ASTUtils.addChildJSXTag(bodyNode, noScriptNode)

  addSpreadAttributes(htmlNode, 'props', 'htmlAttributes')
  addSpreadAttributes(bodyNode, 'props', 'bodyAttributes')
  addJSXExpressionContainer(headNode, 'props', 'headComponents')

  if (settings.language) {
    ASTUtils.addAttributeToJSXTag(htmlNode, 'lang', settings.language)
  }

  ASTBuilders.appendAssetsAST(assets, options, headNode, bodyNode)

  meta.forEach((metaItem) => {
    const metaTag = ASTBuilders.createJSXTag('meta')

@teleporthq/teleport-plugin-common

Common building and modelating functions for ASTs and HASTs

MIT
Latest version published 2 days ago

Package Health Score

82 / 100
Full package analysis

Similar packages