ultraq / thymeleafjs

A basic implementation of the Thymeleaf templating engine in JavaScript
Apache License 2.0
52 stars 8 forks source link

Processing of fragments #8

Closed ultraq closed 6 years ago

ultraq commented 7 years ago

I think this will be the last thing really needed before we can start firing Thymeleaf JS into the wild.

Currently, it's good for creating HTML on the server w/ Node servers, but how about on the browser in response to JS events like JSON requests/streams or server-sent events or webworker messages? It'd be cool to be able to execute fragments of Thymeleaf templates over JSON (or any form of) data to generate HTML that can then be inserted into existing documents so developers can dynamically update documents in the same templating language as they're using on the server, and then finally it can open it up to being able to share the same HTML files between client and server.

yubaoquan commented 7 years ago

Is this repo still developing?

ultraq commented 7 years ago

Yup, but there hasn't been any movement on it for a while because it's currently in a state where it "does everything I needed" (which is to let me process basic Thymeleaf templates in a NodeJS server environment) and so have been able to use it in several projects to meet that need.

I've yet to give Thymeleaf's creator a message about it's current state though, so I should probably do that. He was keen to have some basic JS implementation to do some things but I should really catch-up and find out what those things are.

yubaoquan commented 7 years ago

I am developing a mock server which consider to use your package as a renderer for thymeleaf, but I found your package currently not supports some syntaxes of thymeleaf, such as this one:

data: 
{ 
 hello: 'http://xxx.com',
 a: 1
 }

html
<p>click <a data-th-href="@{http://www.baidu.com?query(p=${a})}">here</a> to say hi</p>

after render, nothing changed:

<p>click<a data-th-href="@{http://www.baidu.com?query(p=${hello})}">here</a>to say hi</p>

and I try to use attribute like this:

 data:
{
    domain: 'http://suho.com',
    params: 'a=b'
}

html:
<p>click<a data-th-attr="href=${domain}?${params}">here</a>to say hi</p>

but got this:

<p>click<a href="">here</a>to say hi</p>

So I think there are some basic syntaxes not implemented yet.

ultraq commented 7 years ago

Ah, yes the URL expression syntax hasn't been added to this project. Could you raise a new issue about that (or I can do that when I'm next on a computer) and I can work on adding it as part of that issue rather than this one which is for fragment processing.

ultraq commented 6 years ago

Support for fragments has been added in version 0.9.0, although the work required by devs to get it working on the client side is less than ideal (a special directory, random webpack configuration). Closing for now as I've raised #16 covering that part of getting fragments to work.