diff --git a/taglibs/layout/marko.json b/taglibs/layout/marko.json index 65de47a1d..f8decd89d 100644 --- a/taglibs/layout/marko.json +++ b/taglibs/layout/marko.json @@ -6,9 +6,7 @@ "remove-dashes": true, "type": "string" }, - "renderer": "./use-tag", - "body-function": "getContent(__layoutHelper)", - "transformer": "./use-tag-transformer.js", + "transformer": "./use-tag.js", "autocomplete": [ { "snippet": "layout-use(\"${1:./path/to/template.marko}\")", @@ -22,10 +20,7 @@ "": { "@into": "string", "@value": "string", - "renderer": "./put-tag", - "import-var": { - "layout": "__layoutHelper" - }, + "transformer": "./put-tag", "autocomplete": [ { "snippet": "layout-put into=\"${1:name}\"", @@ -38,10 +33,7 @@ }, "": { "@name": "string", - "renderer": "./placeholder-tag", - "import-var": { - "content": "data.layoutContent" - }, + "transformer": "./placeholder-tag", "autocomplete": [ { "snippet": "layout-placeholder name=\"${1:name}\"", diff --git a/taglibs/layout/placeholder-tag.js b/taglibs/layout/placeholder-tag.js index 0d53350e8..3218252be 100644 --- a/taglibs/layout/placeholder-tag.js +++ b/taglibs/layout/placeholder-tag.js @@ -1,15 +1,21 @@ -module.exports = function render(input, out) { - var contentMap = input.content; - var content = contentMap ? contentMap[input.name] : null; - if (content) { - if (content.value) { - out.write(content.value); - } else if (content.renderBody) { - content.renderBody(out); - } +module.exports = function render(oldNode, context) { + context.deprecate('The tag is deprecated. Please use instead. See: https://github.com/marko-js/marko/issues/452'); + + var name = oldNode.getAttributeValue('name'); + var builder = context.builder; + var content = builder.memberExpression('input', name.value); + + var newNode = context.createNodeForEl('include'); + newNode.addProps({ _target:content }); + + if (oldNode.firstChild) { + var ifNode = builder.ifStatement(content, [newNode]); + var elseNode = builder.elseStatement(); + oldNode.moveChildrenTo(elseNode); + + oldNode.replaceWith(ifNode); + ifNode.insertSiblingAfter(elseNode); } else { - if (input.renderBody) { - input.renderBody(out); - } + oldNode.replaceWith(newNode); } }; \ No newline at end of file diff --git a/taglibs/layout/put-tag.js b/taglibs/layout/put-tag.js index 5f6733673..0e5c3b23d 100644 --- a/taglibs/layout/put-tag.js +++ b/taglibs/layout/put-tag.js @@ -1,5 +1,18 @@ -module.exports = function render(input, context) { - var layout = input.layout; - var handlePutTag = layout.handlePutTag; - handlePutTag(input); +module.exports = function render(oldNode, context) { + context.deprecate('The tag is deprecated. Please use instead. See: https://github.com/marko-js/marko/issues/452'); + + var name = oldNode.getAttributeValue('into').value; + var value = oldNode.getAttributeValue('value'); + + oldNode.removeAttribute('into'); + oldNode.removeAttribute('value'); + + var newNode = context.createNodeForEl('@'+name, oldNode.getAttributes()); + + if (value) { + newNode.appendChild(context.builder.text(value)); + } + + oldNode.moveChildrenTo(newNode); + oldNode.replaceWith(newNode); }; \ No newline at end of file diff --git a/taglibs/layout/use-tag-transformer.js b/taglibs/layout/use-tag-transformer.js deleted file mode 100644 index f0d63835a..000000000 --- a/taglibs/layout/use-tag-transformer.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -module.exports = function transform(el, context) { - var argument = el.argument; - if (!argument) { - context.addError('Invalid tag. Expected: '); - return; - } - - context.deprecate('The tag is deprecated. Please use instead. See: https://github.com/marko-js/marko/issues/452'); - - var builder = context.builder; - - var args = builder.parseJavaScriptArgs(argument); - var template = args[0]; - - if (template.type === 'Literal') { - template = context.importTemplate(template.value); - } - - if (args[1]) { - el.setAttributeValue('__data', args[1]); - } - - el.argument = null; - - el.setAttributeValue('__template', template); -}; \ No newline at end of file diff --git a/taglibs/layout/use-tag.js b/taglibs/layout/use-tag.js index 0daa33c2c..0f2f8d598 100644 --- a/taglibs/layout/use-tag.js +++ b/taglibs/layout/use-tag.js @@ -1,24 +1,16 @@ -module.exports = function render(input, out) { - var content = {}; +'use strict'; - if (input.getContent) { - input.getContent({ - handlePutTag: function (putTag) { - content[putTag.into] = putTag; - } - }); +module.exports = function transform(oldNode, context) { + var argument = oldNode.argument; + if (!argument) { + context.addError('Invalid tag. Expected: '); + return; } - var dataArg = input.__data; - var templateData = input['*'] || {}; + context.deprecate('The tag is deprecated. Please use instead. See: https://github.com/marko-js/marko/issues/452'); - if (dataArg) { - for (var k in dataArg) { - if (dataArg.hasOwnProperty(k) && !templateData.hasOwnProperty(k)) { - templateData[k] = dataArg[k]; - } - } - } - templateData.layoutContent = content; - input.__template.render(templateData, out); -}; \ No newline at end of file + var newNode = context.createNodeForEl('include', oldNode.getAttributes(), argument); + oldNode.moveChildrenTo(newNode); + + oldNode.replaceWith(newNode); +}; diff --git a/test/autotests/render/include-layout-v3-compat/expected.html b/test/autotests/render/include-layout-v3-compat/expected.html new file mode 100644 index 000000000..2ccdec6f1 --- /dev/null +++ b/test/autotests/render/include-layout-v3-compat/expected.html @@ -0,0 +1 @@ +
BODY CONTENT
FOOTER CONTENT

HEADER CONTENT

BODY CONTENT
FOOTER CONTENT

VALUE HEADER

BODY CONTENT
FOOTER CONTENT

DEFAULT TITLE

BODY CONTENT
FOOTER CONTENT \ No newline at end of file diff --git a/test/autotests/render/include-layout-v3-compat/layout-default.marko b/test/autotests/render/include-layout-v3-compat/layout-default.marko new file mode 100644 index 000000000..ab3c70748 --- /dev/null +++ b/test/autotests/render/include-layout-v3-compat/layout-default.marko @@ -0,0 +1,10 @@ +

+ + DEFAULT TITLE + +

+
+ +
+ + \ No newline at end of file diff --git a/test/autotests/render/include-layout-v3-compat/template.marko b/test/autotests/render/include-layout-v3-compat/template.marko new file mode 100644 index 000000000..92065c698 --- /dev/null +++ b/test/autotests/render/include-layout-v3-compat/template.marko @@ -0,0 +1,18 @@ + + <@body>BODY CONTENT + <@footer>FOOTER CONTENT +
+ + <@header>HEADER CONTENT + <@body>BODY CONTENT + <@footer>FOOTER CONTENT +
+ + <@header>VALUE HEADER + <@body>BODY CONTENT + <@footer>FOOTER CONTENT +
+ + <@body>BODY CONTENT + <@footer>FOOTER CONTENT +
\ No newline at end of file diff --git a/test/autotests/render/include-layout-v3-compat/test.js b/test/autotests/render/include-layout-v3-compat/test.js new file mode 100644 index 000000000..2d4cbe165 --- /dev/null +++ b/test/autotests/render/include-layout-v3-compat/test.js @@ -0,0 +1,3 @@ +exports.templateData = { + layoutDynamic: require('./layout-default.marko') +};