Skip to content

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