formular
formular copied to clipboard
Adding Haml support and teest
Hi Fran. Unless I'm missing something HAML support ( Haml 5.0.4 with corresponding cells-haml) is available out of the box ( I haven't tried hamlit). Just added a test & gemspec - based off of SLIM. You did all the hard work! 👍
Ignore pull request #62 - I did git add . from wrong directory level 🤕
@konung Can you add an simple example in a branch in the demo repo too?
Thanks so much for adding this - I never quite got around to adding 'formal' support for it!
Full stop. :( So I was doing this with my eyes half closed last night - because I didn't see that haml version produces the same form twices. ( or rather some elements of the form are output twice before the form). I've seen it before somewhere with simple_form I think, but I can't remember where or how I fixed. Anyways this is related to https://github.com/trailblazer/formular/issues/52
And will need to figure out a way around this first. I'll dive into formular later this week :)
@konung we have the same issue with erb actually and why we had to add a blockless api see the erb tests https://github.com/trailblazer/formular/blob/master/test/fixtures/comment/erb/show/view/show.erb
Thank you Fran
This rabbit hole is insane. I figured out a temp solution and even the cause, but I'm not sure where to implement a permanent solution inside formular.
Problem So this has to do with how HAML ( and ERB ) uses output buffer. These issues pointed me in the right direction ( just organizing it here for posterity)
Reference Reading
- http://trailblazer.to/gems/cells/cells4.html#html-escaping
- https://stackoverflow.com/questions/24985539/nested-capture-haml-helpers
- https://stackoverflow.com/questions/12437597/cannot-cache-from-decorator-draper
And these HAMLIT (not haml) issues
- https://github.com/k0kubun/hamlit/issues/53
- https://github.com/hamlit/hamlit-block/issues/1
- https://github.com/k0kubun/hamlit/issues/56
Ad-Hoc Solution
So the solution that can be implement just in the HAML template is to capture contents of every block via capture_haml
%div New
= form(model, "/posts", path_prefix: :comment) do |f|
- capture_haml do
= f.input :id
= f.textarea :body
= f.checkbox :public, value: true
= f.collection :replies do |reply|
- capture_haml do
= reply.input :content
= f.nested :owner do |owner|
- capture_haml do
= owner.input :name
= owner.input :email
= f.input :uuid
= f.submit value: "Submit"
I don't know enough about internals for formular to say if this can be fixed internally, but I think this might be the right spot? https://github.com/trailblazer/formular/blob/master/lib/formular/html_block.rb
@konung Can you add an simple example in a branch in the demo repo too?
I set it up (using the capture_haml approach above), but can't pull request to a non-existent branch on your repo - https://github.com/konung/gemgem-sinatra/tree/formular-haml-bootstrap4
Screenshot: https://user-images.githubusercontent.com/72493/46496670-417a4780-c7de-11e8-845c-5aaa9236be04.png