mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Fixes #207 - Marko v3: Re-introduce support for "body-function" in taglib
This commit is contained in:
parent
c1dc3de3de
commit
84de017839
@ -15,7 +15,10 @@ function removeExt(filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function buildInputProps(node, context) {
|
function buildInputProps(node, context) {
|
||||||
|
var tagDef = node.tagDef;
|
||||||
var inputProps = {};
|
var inputProps = {};
|
||||||
|
var builder = context.builder;
|
||||||
|
|
||||||
|
|
||||||
node.forEachAttribute((attr) => {
|
node.forEachAttribute((attr) => {
|
||||||
var attrName = attr.name;
|
var attrName = attr.name;
|
||||||
@ -65,8 +68,20 @@ function buildInputProps(node, context) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (node.body && node.body.length) {
|
if (node.body && node.body.length) {
|
||||||
var renderBodyFunction = context.builder.renderBodyFunction(node.body);
|
|
||||||
inputProps.renderBody = renderBodyFunction;
|
if (tagDef.bodyFunction) {
|
||||||
|
let bodyFunction = tagDef.bodyFunction;
|
||||||
|
let bodyFunctionName = bodyFunction.name;
|
||||||
|
var bodyFunctionParams = bodyFunction.params.map(function(param) {
|
||||||
|
return builder.identifier(param);
|
||||||
|
});
|
||||||
|
|
||||||
|
inputProps[bodyFunctionName] = builder.functionDeclaration(bodyFunctionName, bodyFunctionParams, node.body);
|
||||||
|
} else {
|
||||||
|
var renderBodyFunction = context.builder.renderBodyFunction(node.body);
|
||||||
|
inputProps.renderBody = renderBodyFunction;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return context.builder.literal(inputProps);
|
return context.builder.literal(inputProps);
|
||||||
|
|||||||
@ -459,7 +459,10 @@ function loadTag(tagProps, path, taglib, dirname) {
|
|||||||
if (!hasAttributes(tagProps)) {
|
if (!hasAttributes(tagProps)) {
|
||||||
// allow any attributes if no attributes are declared
|
// allow any attributes if no attributes are declared
|
||||||
tagProps.attributes = {
|
tagProps.attributes = {
|
||||||
'*': 'string'
|
'*': {
|
||||||
|
type: 'string',
|
||||||
|
targetProperty: null
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,42 +1,26 @@
|
|||||||
{
|
{
|
||||||
"tags": {
|
"<layout-use>": {
|
||||||
"layout-use": {
|
"@template": "template",
|
||||||
"renderer": "./use-tag",
|
"@*": {
|
||||||
"attributes": {
|
"remove-dashes": true,
|
||||||
"template": {
|
"type": "string"
|
||||||
"type": "template"
|
|
||||||
},
|
|
||||||
"*": {
|
|
||||||
"remove-dashes": true,
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"body-function": "getContent(__layoutHelper)"
|
|
||||||
},
|
},
|
||||||
"layout-put": {
|
"renderer": "./use-tag",
|
||||||
"renderer": "./put-tag",
|
"body-function": "getContent(__layoutHelper)"
|
||||||
"attributes": {
|
},
|
||||||
"into": {
|
"<layout-put>": {
|
||||||
"type": "string"
|
"@into": "string",
|
||||||
},
|
"@value": "string",
|
||||||
"value": {
|
"renderer": "./put-tag",
|
||||||
"type": "string"
|
"import-var": {
|
||||||
}
|
"layout": "__layoutHelper"
|
||||||
},
|
}
|
||||||
"import-var": {
|
},
|
||||||
"layout": "__layoutHelper"
|
"<layout-placeholder>": {
|
||||||
}
|
"@name": "string",
|
||||||
},
|
"renderer": "./placeholder-tag",
|
||||||
"layout-placeholder": {
|
"import-var": {
|
||||||
"renderer": "./placeholder-tag",
|
"content": "data.layoutContent"
|
||||||
"attributes": {
|
|
||||||
"name": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"import-var": {
|
|
||||||
"content": "data.layoutContent"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
20
test/fixtures/compiler/autotest/custom-tag-body-function/expected.js
vendored
Normal file
20
test/fixtures/compiler/autotest/custom-tag-body-function/expected.js
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
function create(__helpers) {
|
||||||
|
var str = __helpers.s,
|
||||||
|
empty = __helpers.e,
|
||||||
|
notEmpty = __helpers.ne,
|
||||||
|
escapeXml = __helpers.x,
|
||||||
|
__renderer = __helpers.r,
|
||||||
|
__tag = __helpers.t,
|
||||||
|
test_body_function_renderer = __renderer(require("../../../taglib/scanned-tags/test-body-function/renderer"));
|
||||||
|
|
||||||
|
return function render(data, out) {
|
||||||
|
__tag(out, test_body_function_renderer, {
|
||||||
|
"name": "World",
|
||||||
|
"myBody": function myBody(foo, bar) {
|
||||||
|
out.w("This is the body content");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
(module.exports = require("marko").c(__filename)).c(create);
|
||||||
3
test/fixtures/compiler/autotest/custom-tag-body-function/template.marko
vendored
Normal file
3
test/fixtures/compiler/autotest/custom-tag-body-function/template.marko
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<test-body-function name="World">
|
||||||
|
This is the body content
|
||||||
|
</test-body-function>
|
||||||
4
test/fixtures/taglib/scanned-tags/test-body-function/marko-tag.json
vendored
Normal file
4
test/fixtures/taglib/scanned-tags/test-body-function/marko-tag.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"renderer": "./renderer",
|
||||||
|
"body-function": "myBody(foo, bar)"
|
||||||
|
}
|
||||||
3
test/fixtures/taglib/scanned-tags/test-body-function/renderer.js
vendored
Normal file
3
test/fixtures/taglib/scanned-tags/test-body-function/renderer.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
module.exports = function(input, out) {
|
||||||
|
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user