dnagir / ruby-haml-js

HAML-JS Tile and Rails 3.1 Template
MIT License
86 stars 13 forks source link

Fix running JavaScript (-) to specification. #17

Open nickl- opened 11 years ago

nickl- commented 11 years ago

I saw the undocumented custom filter hacks referred to by #9 but those :if and :loop constructs are one of the gripes I have with jade, these are not required in a templating engine, IMO. We have sufficient ability to handle conditions and loops in the underlying language so it is unnecessary for the template engine to duplicate the effort.

Whether to keep the out of spec features or not is not what this patch is aiming for, instead it is an attempt to make the JavaScript lines run as - working as is expected.

What has been added:

See spec for example.

Although this is already very useful and serves the majority of use cases there are some things that still need attention. We currently only consider the immediate block of the parent but in certain conditions we will have to take the first outdent into consideration. This means that the following will not work yet.

Because we are not yet considering the first outdented line something like setTimeout is not possible yet. ex.

- setTimeout(function () {
 %p This html supplied asynchronously
- }, 1000);

But even with these remaining limitations I consider this patch a move in the right direction as the rawjs implementation is not of any use currently.

dnagir commented 10 years ago

Thanks for the PR. Looks good.

But unfortunately I will not accept any changes to the original HAML JS implementation (except the regular updates). You'll be better off sending this PR to https://github.com/creationix/haml-js. Then if it will be accepted, we will update it here.