mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Marko v3: Fixes #222 - Allow open only tags to be defined in tag definition
This commit is contained in:
parent
c78ca5f352
commit
8f9d1094af
@ -77,7 +77,11 @@ class HtmlJsParser {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var parser = this.parser = htmljs.createParser(listeners);
|
var parser = this.parser = htmljs.createParser(listeners, {
|
||||||
|
isOpenTagOnly: function(tagName) {
|
||||||
|
return handlers.isOpenTagOnly(tagName);
|
||||||
|
}
|
||||||
|
});
|
||||||
parser.parse(src);
|
parser.parse(src);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -268,6 +268,11 @@ class Parser {
|
|||||||
|
|
||||||
return null; // Default parse state
|
return null; // Default parse state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isOpenTagOnly(tagName) {
|
||||||
|
var tagDef = this.context.getTagDef(tagName);
|
||||||
|
return tagDef && tagDef.openTagOnly;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Parser;
|
module.exports = Parser;
|
||||||
@ -50,6 +50,7 @@ class Tag{
|
|||||||
this.isRepeated = null;
|
this.isRepeated = null;
|
||||||
this.isNestedTag = false;
|
this.isNestedTag = false;
|
||||||
this.parentTagName = null;
|
this.parentTagName = null;
|
||||||
|
this.openTagOnly = null;
|
||||||
this.body = null;
|
this.body = null;
|
||||||
this.type = null; // Only applicable for nested tags
|
this.type = null; // Only applicable for nested tags
|
||||||
this._nodeFactory = undefined;
|
this._nodeFactory = undefined;
|
||||||
|
|||||||
@ -426,6 +426,10 @@ TagHandlers.prototype = {
|
|||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid value for "body". Allowed: "static-text", "parsed-text" or "html"');
|
throw new Error('Invalid value for "body". Allowed: "static-text", "parsed-text" or "html"');
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
openTagOnly: function(value) {
|
||||||
|
this.tag.openTagOnly = value;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
2
test/fixtures/render/autotest/custom-tag-open-tag-only/expected.html
vendored
Normal file
2
test/fixtures/render/autotest/custom-tag-open-tag-only/expected.html
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Hello Frank!
|
||||||
|
Hello John!
|
||||||
6
test/fixtures/render/autotest/custom-tag-open-tag-only/marko-taglib.json
vendored
Normal file
6
test/fixtures/render/autotest/custom-tag-open-tag-only/marko-taglib.json
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"<open-tag-only>": {
|
||||||
|
"renderer": "./open-tag-only-tag.js",
|
||||||
|
"open-tag-only": true
|
||||||
|
}
|
||||||
|
}
|
||||||
3
test/fixtures/render/autotest/custom-tag-open-tag-only/open-tag-only-tag.js
vendored
Normal file
3
test/fixtures/render/autotest/custom-tag-open-tag-only/open-tag-only-tag.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
module.exports = function (input, out) {
|
||||||
|
out.write('Hello ' + input.name + '!\n');
|
||||||
|
};
|
||||||
2
test/fixtures/render/autotest/custom-tag-open-tag-only/template.marko
vendored
Normal file
2
test/fixtures/render/autotest/custom-tag-open-tag-only/template.marko
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<open-tag-only name="Frank">
|
||||||
|
<open-tag-only name="John" />
|
||||||
1
test/fixtures/render/autotest/custom-tag-open-tag-only/test.js
vendored
Normal file
1
test/fixtures/render/autotest/custom-tag-open-tag-only/test.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
exports.templateData = {};
|
||||||
Loading…
x
Reference in New Issue
Block a user