raymyers / haml4grails

Haml plugin for Grails, based on JHaml
GNU General Public License v3.0
6 stars 5 forks source link

how can I write `and` condition in `g:if` tag? #8

Open fatshotty opened 11 years ago

fatshotty commented 11 years ago

Hello, I'm using your haml4grails plugin. It saves me ;)

Unfortunately, i have something like this:

%g:if(test="${myobj && mysecondObj}")
   .... my code

it will be converted into

<g:if test="${myobj &amp;&amp; mysecondObj}" >
  ... my code

and it make compiler crashes because of &amp;

So, my question is: how can I avoid this error? I need and condition working.

Thanks in advance

raymyers commented 11 years ago

What version of Grails are you using?

fatshotty commented 11 years ago

Thanks for replying

Grails version 2.1.1 Haml4Grails works fine but the && condition :-/

raymyers commented 11 years ago

JHaml doesn't know to skip HTML escaping within a ${...} expression for attribute values. Thanks for bringing that to light, I'm working on fixing it.

In the mean time, try putting the expression itself in parens with no quotes. Haml syntax recognizes that as an expression.

%g:if(test=(myobj && mysecondObj))

Should resolve to:

<g:if test='<%= (myobj && mysecondObj) %>'></g:if>

Let me know if that helps.

fatshotty commented 11 years ago

Hello, thanks for the hack Unfortunately the result is: %li(class=(params.controller == 'suppliers' && isAdmin ? 'selected' : '')) it becomes: <li class="&lt;%= (params.controller == 'suppliers' &amp;&amp; isAdmin ? 'selected' : '') %&gt;"> and in the page I see (using debugbar on firefox): <li class="<%= (params.controller == 'suppliers' && isAdmin ? 'selected' : '') %>"> and it is not the expected behavior :-/

I have tested around but nothing good :(

Thanks

raymyers commented 11 years ago

I've now fixed this in JHaml 0.1.5. Attribute values which look like they have ${}... expression language in them are not escaped.

Haml4Grails 0.4 includes it - you can try out the zipped plugin here: https://github.com/raymyers/haml4grails/tree/master/dist

I'll publish it to the official Grails plugin repo once it's ready.

It's built against Grails 1.3.9, so let me know if there is trouble importing into 2.1.1 - I had some issues getting the dependencies to come through when installing into 2.2.0.

Update: Apparently the dependency strategy for plugins has changed with Grails 2, so I'll have to make some more changes

Another idea for a workaround:

fatshotty commented 11 years ago

Thanks a lot. I'll try and let u know soon ;)