Fix running JavaScript (-) to specification. #17

Open
wants to merge 4 commits into
from

Conversation

Projects
None yet
2 participants

nickl- commented Sep 22, 2013

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:

  • running JavaScript blocks are completely processed to allow for other type lines to be included in blocks including nesting of JavaScript blocks
  • as per the haml specification to use indentation for blocks you are not required to end
    • if statements
    • for loops
    • while loops
    • async function blocks
  • includes several specs to test the commonly used combinations including
    • if statements with and without begin {
    • for loops with or without begin {
    • for in loop
    • while loop
    • variable assignment
    • async function blocks

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.

  • else and else if statements will not work as we prepare the _$output variable for subsequent lines after the if statement was already closed.
  • It is not possible to implicitly close a block (this is not to spec but may be required for async function blocks)
  • only async functions as the last parameter of a method is currently supported due to the limitation mentioned previously.

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.

nickl- added some commits Sep 22, 2013

Specific rails version.
Specs are tailor made for rails 3.2 aparantly and this is not the default rails at present.
Fix rawjs to spec.
Realign to the haml spec for running JavaScript or the - operator.
Evaluate the block again to correctly parse block level lines.
Auto close for/if/while statements.
Autoclose for async functions.
Owner

dnagir commented Sep 26, 2013

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment