From a6641d9c7235784654b3170b98a9319ae3e33924 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 23 May 2020 14:28:21 -0400 Subject: [PATCH] Add a template to dump the parameters to a custom helper. --- js/dustjs_shim.js | 13 ++++++++ js/permanently_disabled_test_cases/README.md | 11 +++++++ .../helpers_dump_parameters/README.md | 30 +++++++++++++++++++ .../helpers_dump_parameters/input1.json | 6 ++++ .../helpers_dump_parameters/main.dust | 7 +++++ 5 files changed, 67 insertions(+) create mode 100644 js/permanently_disabled_test_cases/README.md create mode 100644 js/permanently_disabled_test_cases/helpers_dump_parameters/README.md create mode 100644 js/permanently_disabled_test_cases/helpers_dump_parameters/input1.json create mode 100644 js/permanently_disabled_test_cases/helpers_dump_parameters/main.dust diff --git a/js/dustjs_shim.js b/js/dustjs_shim.js index c38f06d..8e90167 100644 --- a/js/dustjs_shim.js +++ b/js/dustjs_shim.js @@ -3,6 +3,19 @@ var dust = require("dustjs-helpers"); var fs = require("fs"); const path = require("path"); +dust.helpers.dumpParameters = function(chunk, context, bodies, params) { + // Dump the parameters to a dust helper to figure out what is passed + // to a helper. I figure I need to make sure I'm passing + // approximately the same information to my render functions if I + // end up supporting custom helpers in the future to make sure + // helpers can be ported easily. + // console.log(JSON.stringify(Array.prototype.slice.call(arguments))); + console.log("chunk: ", chunk); + console.log("context: ", JSON.stringify(context)); + console.log("bodies: ", bodies); + console.log("params: ", params); +} + var argv = process.argv.slice(2); if (argv.length < 1) { console.error("Expecting only 1 argument (a path to a template)"); diff --git a/js/permanently_disabled_test_cases/README.md b/js/permanently_disabled_test_cases/README.md new file mode 100644 index 0000000..1435ea6 --- /dev/null +++ b/js/permanently_disabled_test_cases/README.md @@ -0,0 +1,11 @@ +This folder is for test cases that are NEVER expected to work on duster but I've written to investigate the behavior of original dust. Examples of this are: + +Custom javascript dust helpers +------------------------------ + +Inside the shim I wrote a very basic custom dust helper to investigate the chunk, context, bodies, and params parameters so that I can theoretically expose a similar interface for custom rust dust helpers. Since I won't be perfectly replicating those objects, duster would never output a byte-for-byte identical output for that helper. + +Javascript context helpers +-------------------------- + +I do not intend to integrate a javascript engine into duster, so context helpers written as javascript inside the json context will not work on duster. I believe, based on my interface-based approach, I'll be able to support runtime functions written in rust and stored in rust objects (not from JSON) to serve the same functionality as context helpers but that still remains to be seen. diff --git a/js/permanently_disabled_test_cases/helpers_dump_parameters/README.md b/js/permanently_disabled_test_cases/helpers_dump_parameters/README.md new file mode 100644 index 0000000..2c1d01e --- /dev/null +++ b/js/permanently_disabled_test_cases/helpers_dump_parameters/README.md @@ -0,0 +1,30 @@ +Chunk +----- + +Some sort of object which contains an array of rendered elements. For example, using: + +``` +Testing dump parameters +{#names} + {.} +{/names} +``` + +The first interation would have `["Testing dump parameters", "Alice"]`. + +Question: Do any helpers read from chunk or just write to it? If its just writing, then my current architecture of just returning a `String` would work fine, though having a shared buffer thats written to would probably reduce the allocations and therefore improve performance. + +Context +------- + +Some sort of object that contains essentially the "breadcrumbs" variable I am currently using to track the context tree. Also tracks template name, globals and options. I guess options would be that whole preserve whitespace or not option. I was just going to store this option on the dust renderer type, but I guess I should bake it into the breadcrumbs to pass into helpers if I implement support for custom helpers. + +Bodies +------ + +No idea, but based on the name I assume it contains the contents of the helper, or at least some way to render the internal body of the helper. + +Params +------ + +A mapping of the parameters directly on the helper. diff --git a/js/permanently_disabled_test_cases/helpers_dump_parameters/input1.json b/js/permanently_disabled_test_cases/helpers_dump_parameters/input1.json new file mode 100644 index 0000000..74f3606 --- /dev/null +++ b/js/permanently_disabled_test_cases/helpers_dump_parameters/input1.json @@ -0,0 +1,6 @@ +{ + "names": [ + "Alice", + "Bob" + ] +} diff --git a/js/permanently_disabled_test_cases/helpers_dump_parameters/main.dust b/js/permanently_disabled_test_cases/helpers_dump_parameters/main.dust new file mode 100644 index 0000000..ebc883e --- /dev/null +++ b/js/permanently_disabled_test_cases/helpers_dump_parameters/main.dust @@ -0,0 +1,7 @@ +Testing dump parameters +{#names} + {.} + {@dumpParameters foo="bar"} + Internal + {/dumpParameters} +{/names}