Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HAML Compatibility #4

Closed
Florian95 opened this issue Jul 25, 2011 · 18 comments
Closed

HAML Compatibility #4

Florian95 opened this issue Jul 25, 2011 · 18 comments

Comments

@Florian95
Copy link

Hi,

I use Spree, and they use Deface... But all my views are in HAML.

Its possible to add support of HAML to deface ?

Regards,

@BDQ
Copy link
Member

BDQ commented Aug 17, 2011

Deface in it's current incarnation couldn't support HAML as all the selectors are based on CSS standards and HAML obviously isn't parseable (by Nokogiri).

So we'd need come up with a way to parse and select elements of a HAML document. I know there's libraries out there that might get us some of the way towards that, but someone uses HAML is going to have to take point on this development. I'm glad to help integrate it with Deface, when the time comes.

@stephanelpaul
Copy link

I've done a quick hack in which I convert haml to erb and then erb to haml not the most viable solution but it was a quick one we needed.

@ndbroadbent
Copy link

I'm really interested in using this for Fat Free CRM's plugins. We currently have a simple hook system that needs a lot of improvement. However, all our views are written in HAML.

I really like the sound of converting from HAML to ERB, and then passing that to deface.
One reason is that HAML's strict rules (such as indentation) could make it difficult to support this kind of customization.
Another reason is that the production environment could pre-cache the compiled view templates, so there wouldn't be any difference in performance.

@stephanep, could you please share how you are converting HAML to ERB?

@ndbroadbent
Copy link

This looks very promising: https://gist.github.com/17371

Hope to give it a try sometime soon.

@BDQ
Copy link
Member

BDQ commented Jan 12, 2012

@ndbroadbent - I'd be delighted to get HAML support baked into Deface, I was under the impression that HAML couldn't be reliably converted back to ERB. That example looks very promising.

I've got some other HAML improvements locally too, that allow you to supply HAML as the replacement markup. I'll get it pushed to a branch for you to review shortly.

@BDQ
Copy link
Member

BDQ commented Jan 13, 2012

@ndbroadbent @stephanep @Florian95 - I've got HAML support added to a branch for now. I'd appreciate if you guys could test it out and let me know how it works for you.

https://github.com/railsdog/deface/tree/haml

It works by using the Haml2Erb converter that @ndbroadbent mentions above, when Deface detects a haml view that's a target of an override, it will first convert the haml to erb and then apply the overrides.

You can also use haml files for the :template or :partial options (again deface will just convert to ERB).

Finally, I've added a new option instead of :text (which expects erb), you can pass a fragment of haml to the :haml option. EG:

http://pastie.org/3177417

There's no test or docs coverage yet, just wanted to see if it was a viable solution before I spend anymore time on it!

@ndbroadbent
Copy link

That's awesome, thanks! We're quite busy right now finishing some other FFCRM features for our organization, but I will try to find some time to test this out in a plugin. Perhaps early next week.
Cheers!

@stdcall
Copy link

stdcall commented Jan 21, 2012

I'm testing your deface haml branch with
gem 'deface', git: 'git://github.com/railsdog/deface.git', branch: "haml"
in my spree application Gemfile.
Here is little snippet from spree_application.html.haml layout:
%body(data-hook="body"){ class: body_class, id: @body_id || 'default'}
First, Rails report error "undefined method body_class", and second, after cleaning body_class out of block, it generates clean tag, without attributes set in.

@BDQ
Copy link
Member

BDQ commented Jan 22, 2012

@stdcall Can you give me a copy of your entire spree_application file for testing?

@stdcall
Copy link

stdcall commented Jan 22, 2012

@BDQ
Copy link
Member

BDQ commented Jan 23, 2012

@stdcall I just pushed a fix for those issues you were seeing can you update to the latest haml branch and try again.

In order to get your spree_application.html.haml to parse you need to indent the following line:

  - @bc = body_class

So that it is inside the head tag - nokogiri doesn't allow any other tags at the same level as head or body.

@BDQ
Copy link
Member

BDQ commented Jan 26, 2012

Just pushed some more updates to the haml branch.

@BDQ
Copy link
Member

BDQ commented Feb 21, 2012

Has anyone given the haml stuff a real test? I've just done some very basic stuff, as I don't use haml myself.

@dvictory
Copy link

I think I found an issue. It doesn't like haml with blocks.

I tried the following:
=form_tag "/blah" do
=text_field_tag "test"
=submit_tag "Do something"

This returns "unexpected $end, expecting keyword_end" errors

For now my work around is to put haml blocks in an erb partial and then do
=render 'my_form'

I use a lot of haml I will report back with more issues if I find any, but this is the only one so far.

@BDQ
Copy link
Member

BDQ commented Feb 24, 2012

@dvictory thanks for reporting this, I'll get working on a fix for this.

@BDQ
Copy link
Member

BDQ commented Feb 24, 2012

@dvictory fixed the block handling:

railsdog/deface@f405217

@dvictory
Copy link

@BDQ Awesome! Works like a champ!

@BDQ
Copy link
Member

BDQ commented Apr 12, 2012

Marking this as closed, feel free to file new ticket for specific haml issues.

@BDQ BDQ closed this as completed Apr 12, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants