Template strings as a template language.

2015-09-13 Thread Thomas
I'd really like to use Template strings as a templating language, but unless I include a lot of boilerplate code (export a template string wrapped in a function from a file) or use eval after loading a file as a string it's pretty much impossible. Is there a simpler way to be doing this? Or

Re: Template strings as a template language.

2015-09-13 Thread Thomas
They would be whatever they are in the scope in which the template string is evaluated. Thomas > On 14 Sep 2015, at 12:15 AM, Mark S. Miller wrote: > > > >> On Sun, Sep 13, 2015 at 7:08 AM, Thomas >> wrote: >> What I've been doing: >>

Re: Template strings as a template language.

2015-09-13 Thread Alexander Jones
Same place as `eval`. Arguably both should have the option of explicitly passing a scope, for extra strictness, like Python's. On 13 September 2015 at 15:15, Mark S. Miller wrote: > > > On Sun, Sep 13, 2015 at 7:08 AM, Thomas > wrote: > >>

Re: Template strings as a template language.

2015-09-13 Thread Alexander Jones
I think it would look something like this: ```js tag `string text ${expression} string text` // vs. String.templateEval("string text ${expression} string text", tag) ``` (Clearly, evaluation errors would be a runtime error, much like how `eval` itself works.) My hunch is this would be quite a

Re: Template strings as a template language.

2015-09-13 Thread Thomas
What I've been doing: export const template = ({title, content}) => `template string for ${title}`; Or variations thereof. I then import that module wherever I need to use the template and call it as a function. Using eval and having the template string as a normal string (so, read the

Re: Template strings as a template language.

2015-09-13 Thread Mark S. Miller
On Sun, Sep 13, 2015 at 7:08 AM, Thomas wrote: > What I've been doing: > > export const template = ({title, content}) => `template string for > ${title}`; > > Or variations thereof. I then import that module wherever I need to use > the template and call it as a

Re: Template strings as a template language.

2015-09-13 Thread Mark S. Miller
On Sun, Sep 13, 2015 at 2:42 AM, Thomas wrote: > I'd really like to use Template strings as a templating language, but > unless I include a lot of boilerplate code (export a template string > wrapped in a function from a file) Hi Thomas, could you give a concrete

Re: Template strings as a template language.

2015-09-13 Thread Mark S. Miller
How is explicitly passing a scope different from calling the function with a {title, content} object? On Sun, Sep 13, 2015 at 7:24 AM, Alexander Jones wrote: > Same place as `eval`. Arguably both should have the option of explicitly > passing a scope, for extra

Re: Template strings as a template language.

2015-09-13 Thread Alexander Jones
Not exactly sure what you mean. But if you are you asking how ```js let template = 'this ${foo} and that ${bar}'; // later... let output = String.evalTemplate(template, {foo: "thing", bar: "other thing"}); ``` is different to ```js let template = ({foo, bar}) => `this ${foo} and that ${bar}`;

Re: Template strings as a template language.

2015-09-13 Thread Thomas
Mark, I'll put together a GitHub gist or repo and send it to you in the morning (I should be asleep) to make things clearer. I'll try explaining it differently in the meantime: What I'd like to do is use ES6 Template string as a templating language. For the sake of readability and

Re: Template strings as a template language.

2015-09-13 Thread Mark S. Miller
The great achievement of modern js module systems including the es6 std module system is to end the greatest pain of prior js: linkage through side effects to the shared global scope. Good riddance. If you're talking about a scope other than the global one, how would a template come to be

Re: Template strings as a template language.

2015-09-13 Thread Thomas
> On 14 Sep 2015, at 1:38 AM, Alexander Jones wrote: > > Not exactly sure what you mean. But if you are you asking how > > ```js > let template = 'this ${foo} and that ${bar}'; > // later... > let output = String.evalTemplate(template, {foo: "thing", bar: "other > thing"}); >

Re: Template strings as a template language.

2015-09-13 Thread Mark S. Miller
On Sun, Sep 13, 2015 at 8:58 AM, Bob Myers wrote: > Templating languages typically "compile" templates into functions through > various lexical transformations. > > Consider a template file foo.tem: > > ``` > My name is ${this.name}. > ``` > > Lexically transform this into > > ```

RE: Template strings as a template language.

2015-09-13 Thread Ron Buckton
This is theoretically possible: ``` let t = $template` ${$item.permalink} ${$each($item.comments)` ${$parent.permalink} ${$if($item.title)` ${$parent.permalink} `} `} `; let s = t(data); ``` ...given an adequate implementation using proxies (to create bindings for e.g.

Re: Template strings as a template language.

2015-09-13 Thread Isiah Meadows
On Sun, Sep 13, 2015 at 7:09 PM, Mark S. Miller wrote: > > > On Sun, Sep 13, 2015 at 8:58 AM, Bob Myers wrote: >> >> Templating languages typically "compile" templates into functions through >> various lexical transformations. >> >> Consider a template file

Re: Template strings as a template language.

2015-09-13 Thread Thomas
For those interested, this gist better shows what's being discussed: https://gist.github.com/thomasfoster96/193e7c08aae499f810a1 Ron: Yes, that's already possible - but tagged template strings don't really offer much of an advantage over a function as far as templating goes (IMHO). Thomas >

Re: es-discuss Digest, Vol 103, Issue 30

2015-09-13 Thread Mohsen Azimi
I actually used template strings as templateing in two of my projects. You can take aa look here: https://github.com/mohsen1/json-schema-view-js/blob/master/src/index.js#L59-L175 Two main problems I had with this was: * There is no `if` condition in template strings. I had to **hack** my way by

Re: es-discuss Digest, Vol 103, Issue 30

2015-09-13 Thread Thomas
Sent from my iPhone > On 14 Sep 2015, at 2:59 PM, Mohsen Azimi wrote: > > I actually used template strings as templateing in two of my projects. You > can take aa look here: > > https://github.com/mohsen1/json-schema-view-js/blob/master/src/index.js#L59-L175 Will take a