From dd3a86c5649291b4e443fb1176652fb66529a50c Mon Sep 17 00:00:00 2001 From: Bryce Watson Date: Tue, 29 Dec 2015 18:03:33 -0800 Subject: [PATCH] adding assign tag --- taglibs/core/assign-tag.js | 14 ++++++++++++++ taglibs/core/marko-taglib.json | 3 +++ .../render/autotest/assign-tag/expected.html | 1 + .../render/autotest/assign-tag/template.marko | 3 +++ test/fixtures/render/autotest/assign-tag/test.js | 1 + 5 files changed, 22 insertions(+) create mode 100644 taglibs/core/assign-tag.js create mode 100644 test/fixtures/render/autotest/assign-tag/expected.html create mode 100644 test/fixtures/render/autotest/assign-tag/template.marko create mode 100644 test/fixtures/render/autotest/assign-tag/test.js diff --git a/taglibs/core/assign-tag.js b/taglibs/core/assign-tag.js new file mode 100644 index 000000000..d0b99c8ab --- /dev/null +++ b/taglibs/core/assign-tag.js @@ -0,0 +1,14 @@ +module.exports = function codeGenerator(elNode, generator) { + var attributes = elNode.attributes; + + if (!attributes) { + generator.addError('Invalid tag. Argument is missing. Example; '); + return elNode; + } + + var builder = generator.builder; + + return attributes.map((attr) => { + return builder.assignment(attr.name, attr.value); + }); +}; \ No newline at end of file diff --git a/taglibs/core/marko-taglib.json b/taglibs/core/marko-taglib.json index 0020fc8a0..829c3b789 100644 --- a/taglibs/core/marko-taglib.json +++ b/taglibs/core/marko-taglib.json @@ -14,6 +14,9 @@ "": { "node-factory": "./var-tag" }, + "": { + "code-generator": "./assign-tag" + }, "<*>": { "transformer": "./core-transformer" } diff --git a/test/fixtures/render/autotest/assign-tag/expected.html b/test/fixtures/render/autotest/assign-tag/expected.html new file mode 100644 index 000000000..cb608c9a6 --- /dev/null +++ b/test/fixtures/render/autotest/assign-tag/expected.html @@ -0,0 +1 @@ +HELLO 1230 \ No newline at end of file diff --git a/test/fixtures/render/autotest/assign-tag/template.marko b/test/fixtures/render/autotest/assign-tag/template.marko new file mode 100644 index 000000000..19ba3bbd4 --- /dev/null +++ b/test/fixtures/render/autotest/assign-tag/template.marko @@ -0,0 +1,3 @@ + + +${bar.toUpperCase()} ${foo*10} \ No newline at end of file diff --git a/test/fixtures/render/autotest/assign-tag/test.js b/test/fixtures/render/autotest/assign-tag/test.js new file mode 100644 index 000000000..c4013b344 --- /dev/null +++ b/test/fixtures/render/autotest/assign-tag/test.js @@ -0,0 +1 @@ +exports.templateData = {};