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

Adds sb.jinja helper #105

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Adds sb.jinja helper #105

wants to merge 6 commits into from

Conversation

liamgriffiths
Copy link
Contributor

@liamgriffiths liamgriffiths commented Jul 22, 2024

This PR implements the sb.jinja helper. It allows a user to produce FutureString (soon Future<string> #93) values with the result of rendering a Jinja2 template.

For example,

import { Substrate, Box, sb } from "substrate";

async function main() {
  const SUBSTRATE_API_KEY = process.env["SUBSTRATE_API_KEY"];

  const substrate = new Substrate({
    apiKey: SUBSTRATE_API_KEY
  });

  const a = new Box({ value: ["a", "b"] });
  const b = new Box({ value: { x: "x" } });

  const f = sb.jinja('as=[{% for a in as %}{{a}},{% endfor%}], b={{b["x"]}}, c={{c}}', {
    as: a.future.value,
    b: b.future.value,
    c: "1234",
  });

  const c = new Box({ value: f });

  const res = await substrate.run(a, b, c);
  console.log(JSON.stringify(res.json, null, 2));
}
main();

@liamgriffiths liamgriffiths force-pushed the liam/jinja-future-support branch from c8d7e8b to 87e3b11 Compare July 22, 2024 19:31
@liamgriffiths liamgriffiths force-pushed the liam/jinja-future-support branch from 87e3b11 to a0859fe Compare August 22, 2024 20:03
@liamgriffiths liamgriffiths marked this pull request as ready for review August 22, 2024 20:03
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.

1 participant