RailsApps / rails3-devise-rspec-cucumber

An example Rails 3.2 app with Devise and RSpec and Cucumber.
http://railsapps.github.io/
445 stars 144 forks source link

generated Slim view application.html.slim contains syntax error #36

Closed cmwelsh closed 11 years ago

cmwelsh commented 11 years ago

I had to change this line when I generated a new Rails application using this recipe and Slim templates. The generated Slim template had a syntax error.

The reason seems to be that Haml2Slim is buggy. Perhaps we can work around this with a less complicated erb template.

diff --git a/app/views/layouts/application.html.slim b/app/views/layouts/application.html.slim
index 7203cb4..55ecf17 100644
--- a/app/views/layouts/application.html.slim
+++ b/app/views/layouts/application.html.slim
@@ -3,7 +3,7 @@ html
   head
     meta content="width=(device-width,)initial-scale=1.0" name="viewport"
       title= content_for?(:title) ? yield(:title) : "Learn2d"
-      meta content=(content_for?(:description) ? yield(:description) :)"Learn2d" name="description"
+      meta content=(content_for?(:description) ? yield(:description) : "Learn2d") name="description"
         = stylesheet_link_tag "application", :media => "all"
         = javascript_include_tag "application"
         = csrf_meta_tags
cmwelsh commented 11 years ago

I thought this was a bug specific to this project. I am going to move this to the main GitHub project for the composer. Slim template generation is just not working well enough yet.

DanielKehoe commented 11 years ago

In rails_apps_composer, I can remove the "description" meta-tag in the layout when Slim is selected, if that is the only problem. The "description" meta-tag is largely superfluous. But is that all that fails when Slim is selected?

cmwelsh commented 11 years ago

I think it also happened in app/views/layouts/_messages.html.slim. The bug occurs when html_to_slim encounters ternary operators. It usually messes up the parentheses (or more).

DanielKehoe commented 11 years ago

Is there an open issue for html_to_slim? Have you reported it? It'd be nice to see this resolved without working around it in rails_apps_composer. In any case, thanks for bringing it to my attention.

cmwelsh commented 11 years ago

There are known deficiencies in the Haml2Slim[1] gem. I'm not sure what the next step would be - I just wanted to make you aware. :)

"Due to the complex logic behind both Haml's and Slim's parsers, there is currently no way of reliably converting between Haml and Slim templates. Haml2Slim only serves as a preliminary tool for templates conversion. You should always manually verify the converted templates."

[1] https://github.com/fredwu/haml2slim

DanielKehoe commented 11 years ago

Yes, I saw that warning when I looked for a way to convert ERB to Slim. Tell me, do you think it's worthwhile to continue to offer Slim as an option for rails_apps_composer? I don't use Slim but wanted to offer the option to use Slim.

cmwelsh commented 11 years ago

Perhaps you could mark it as "experimental, due to the templates not being converted 100% properly yet". A novice is more likely to want something that "just works" and save themselves the hassle.

DanielKehoe commented 11 years ago

Good point. I'll add a note to the prompt.