Closed Mevrael closed 8 years ago
@Mevrael I think the idea of using local-global which will be executed in child module is incorrect and conflicts with the idea of modules. Template literal is not template angine. It should work only in current scope. Any module has different scope.
Indeed. What do you think about exporting functions with data parameter? So transpiled and bunlded code would look like
var template = function(data) {
return '<div>' + data.name + '</div>';
}
May be add an option for this.
Probably there could be also an option to pass a callback to format code
before returning it.
@Mevrael The idea of this plugin is loading only strings which can be passed in template engines. For example angular requires only template string and processes it inside. You can create own template plugin (but choose please sensible name).
Plugins should be atomic and do only one thing.
Adding some new options would not break this idea.
Instead of
str({
extensions: ['.html']
}),
there could be:
function parser(content) {
content = content.replace(),
...
// format template for any framework or template engine instead of doing it in browser
}
str({
extensions: ['.html', '.php'],
format: 'template-closure',
parser: parser
}),
@Mevrael The name of this plugins is string
, not template
. I can add only some transform option for example to minify html.
Exactly, it's name is string
and string > template since template is a subclass of string. String is a general data type.
And you just said about minification yourself, this breaks your minimalistic atomic philosophy.
@Mevrael It's about minification special type not js. Okay how do you wanna pass data to string? It should return function in this case. This plugin exports only strings.
as I said if I wanna use another format I pass it to options
import tpl from './template.html';
let user = ...
let data = {
user: user
};
console.log(tpl(data));
Oh, you still about template syntax. I can't do this. Plugins should return es5 stuff. Templates is not about that.
@Mevrael Use custom plugin for this case.
There is tool called Babel and plugin for rollup also...
Anyway thank you for conversation, I'll made my own plugin for general use cases.
Babel should process only user script, not generated.
I can't use variables inside imported html templates because right now you are using JSON.stringify() on the content.
template.html:
js:
Does not works, it prints to console ${name} not John. If I replace
to
everything works.