-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(compiler): add support for external templates #219
Conversation
564dd95
to
a463b95
Compare
This PR will trigger a minor release when merged. |
This looks really cool 👍 Just one small thing the htlengine/src/compiler/JSPureTemplate.js Lines 14 to 16 in a463b95
One bug I found is if a template file is using itself:
Which generates: $.template('cdc516118141547c6c395bd7eaa740a3', 'headline', function* _template_cdc516118141547c6c395bd7eaa740a3_headline(args) {
const text = args[1]['text'] || '';
let $t, $n = args[0];
$.dom.text($n,"\n ");
const myModel = yield $.use($use_0, {});
$.dom.text($n,"\n ");
$t = $.dom.create("h1",false,false);
$.dom.text($n,"\n ");
yield $.call(headlineInner, [$n, {"body": text, }]); // <-- 🐛 headlineInner is not defined
$.dom.text($n,"\n");
});
$.template('cdc516118141547c6c395bd7eaa740a3', 'headlineInner', function* _template_cdc516118141547c6c395bd7eaa740a3_headlineInner(args) {
const body = args[1]['body'] || '';
let $t, $n = args[0];
$.dom.text($n,"\n ");
$t = $.dom.create("p",false,false);
$n = $.dom.push($n,$t);
const var_1 = yield $.xss(body, "html");
$.dom.append($n, var_1);
$n = $.dom.pop($n);
$.dom.text($n,"\n");
}); |
a463b95
to
1ed8253
Compare
this is indeed a problem... I'll see if we can fix it here or if we should create a follow up bug. |
since it's not needed anymore, we could also use the default code template again.... |
1ed8253
to
9ee7a97
Compare
const $ = { | ||
col: runtime.col, | ||
exec: runtime.exec.bind(runtime), | ||
xss: runtime.xss.bind(runtime), | ||
listInfo: runtime.listInfo.bind(runtime), | ||
use: runtime.use.bind(runtime), | ||
slyResource: runtime.resource.bind(runtime), | ||
call: runtime.call.bind(runtime), | ||
template: runtime.template.bind(runtime), | ||
dom: runtime.dom, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be possible to replace this part with const $ = runtime
or const $ = runtime.templateHelpers()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's tackle this in a separate PR
9ee7a97
to
4a0538e
Compare
Codecov Report
@@ Coverage Diff @@
## master #219 +/- ##
==========================================
+ Coverage 83.75% 84.06% +0.30%
==========================================
Files 87 89 +2
Lines 3847 3909 +62
==========================================
+ Hits 3222 3286 +64
+ Misses 625 623 -2
Continue to review full report at Codecov.
|
<h1>${data.title}</h1> | ||
<sly data-sly-call="${separator}"/> | ||
</template> | ||
<template data-sly-template.separator>--------------------------------------</template> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jantimon Here, I added a test for a template that uses a template that is later defined in the same script. and it works now :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really cool 👍
# [5.1.0](v5.0.0...v5.1.0) (2020-08-02) ### Features * **compiler:** add support for external templates ([#219](#219)) ([90e20de](90e20de))
🎉 This PR is included in version 5.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
first draft to implement #217