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) {
|
||||
var tagDef = node.tagDef;
|
||||
var inputProps = {};
|
||||
var builder = context.builder;
|
||||
|
||||
|
||||
node.forEachAttribute((attr) => {
|
||||
var attrName = attr.name;
|
||||
@ -65,8 +68,20 @@ function buildInputProps(node, context) {
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
@ -459,7 +459,10 @@ function loadTag(tagProps, path, taglib, dirname) {
|
||||
if (!hasAttributes(tagProps)) {
|
||||
// allow any attributes if no attributes are declared
|
||||
tagProps.attributes = {
|
||||
'*': 'string'
|
||||
'*': {
|
||||
type: 'string',
|
||||
targetProperty: null
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -1,42 +1,26 @@
|
||||
{
|
||||
"tags": {
|
||||
"layout-use": {
|
||||
"renderer": "./use-tag",
|
||||
"attributes": {
|
||||
"template": {
|
||||
"type": "template"
|
||||
},
|
||||
"*": {
|
||||
"remove-dashes": true,
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"body-function": "getContent(__layoutHelper)"
|
||||
"<layout-use>": {
|
||||
"@template": "template",
|
||||
"@*": {
|
||||
"remove-dashes": true,
|
||||
"type": "string"
|
||||
},
|
||||
"layout-put": {
|
||||
"renderer": "./put-tag",
|
||||
"attributes": {
|
||||
"into": {
|
||||
"type": "string"
|
||||
},
|
||||
"value": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"import-var": {
|
||||
"layout": "__layoutHelper"
|
||||
}
|
||||
},
|
||||
"layout-placeholder": {
|
||||
"renderer": "./placeholder-tag",
|
||||
"attributes": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"import-var": {
|
||||
"content": "data.layoutContent"
|
||||
}
|
||||
"renderer": "./use-tag",
|
||||
"body-function": "getContent(__layoutHelper)"
|
||||
},
|
||||
"<layout-put>": {
|
||||
"@into": "string",
|
||||
"@value": "string",
|
||||
"renderer": "./put-tag",
|
||||
"import-var": {
|
||||
"layout": "__layoutHelper"
|
||||
}
|
||||
},
|
||||
"<layout-placeholder>": {
|
||||
"@name": "string",
|
||||
"renderer": "./placeholder-tag",
|
||||
"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