Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xarc/tag-renderer support rendering sub templates #1702

Merged
merged 1 commit into from
Jul 20, 2020
Merged

Conversation

jchip
Copy link
Member

@jchip jchip commented Jul 20, 2020

a renderer for templates base on ES6 template string literals.

Example:

import { createTemplateTags, Token, TokenInvoke, RegisterTokenIds } from "../../src";

import * as custom1 from "../fixtures/custom-1";
import * as tokenHandler from "../fixtures/token-handler";

const subTags2 = createTemplateTags`${RegisterTokenIds(tokenHandler)}
  ${RegisterTokenIds(() => {
    return {
      name: "sub-blah-blah-2",
      tokens: {
        X2: "x2"
      }
    };
  })}
  <div>sub template tags 2${Token("X2")}</div>`;

const subTags = createTemplateTags`${RegisterTokenIds(tokenHandler)}
  ${RegisterTokenIds(() => {
    return {
      name: "sub-blah-blah",
      tokens: {
        X: "x1"
      }
    };
  })}
  <div>sub template tags${Token("X")}${subTags2}</div>`;

export const templateTags = createTemplateTags`<html>
<head>
  ${RegisterTokenIds(tokenHandler)}
  ${RegisterTokenIds(() => {
    return {
      name: "blah-blah",
      tokens: {
        ABC: "ABC",
        "ssr-content": "SSR\n",
        "webapp-header-bundles": () => "header\n"
      }
    };
  })}
  ${RegisterTokenIds(tokenHandler)}
  ${Token("ssr-content")}
  ${Token("webapp-header-bundles")}
  ${Token("webapp-body-bundles")}
  ${Token("PAGE_TITLE")}
  ${Token("prefetch-bundles")}
  ${TokenInvoke(custom1)}
  ${context => {
    return `hello world from function: ${Object.keys(context)}\n`;
  }}
  <script>
    console.log("test");
  </script>
  ${subTags}
  ${Token("meta-tags")}
  ${Token("ABC")}
</head>
</html>`;

@jchip jchip merged commit 3ea2fe7 into master Jul 20, 2020
@jchip jchip deleted the jsx-renderer branch July 29, 2020 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants