phoenixframework / phoenix

Peace of mind from prototype to production
https://www.phoenixframework.org
MIT License
20.97k stars 2.84k forks source link

Support Haml through Calliope in View Layer #205

Closed nurugger07 closed 9 years ago

nurugger07 commented 9 years ago

All that is needed is to start putting *.haml files in the templates folder and Calliope will pre-compile them into EEx strings. Actually, because of the way that it works you can mix and match Haml and EEx templates.

chrismccord commented 9 years ago

Johnny, Nice work!

I've pushed up some changes to your PR on a new branch. Please check this diff and let me know what you think: https://github.com/phoenixframework/phoenix/commit/e116ffcc3e7dc67d8b647401ea30a60b6453488f

I refactored things to more easily allow plugging other templating engines in place. The side-effect was a small amount of within layout duplication in each of the Template.EExEngine and Template.HamlEngine, but we can now allow any other engine to precompile their functions/layouts using whatever they need. Users can add additional engines in their configuration. Engines need only to define a precompile function that defines a render/2 function by phoenix conventions:

config :phoenix, :template_engines,
   slim: Slim.PhoenixEngine

See the Template.EExEngine and Template.HamlEngine. Needs more tests, but thoughts so far?

nurugger07 commented 9 years ago

@chrismccord I started out with a config option similar to yours but ended backed out into the simplest change first. I like your changes :) I think we can dry it up some but it's really close.

chrismccord commented 9 years ago

@chrismccord I started out with a config option similar to yours but ended backed out into the simplest change first. I like your changes :) I think we can dry it up some but it's really close.

Feel free to merge that branch back into your PR and continue. One thing to keep in mind is that the fact Calliope uses EEx underneath is an implementation detail, so we don't want to DRY things up too much b/w the EExEngine and HamlEngine should Calliope change in the future. I think we're close!

nurugger07 commented 9 years ago

I didn't actually do a refactoring yet. I think between our two changes we have a good starting point. Once an additional template engine is needed/added we can look at refactoring. There are tests around rendering both EEx and Haml templates with/without layouts and Travis is passing. I did work out my hex issues with @ericmj so calliope is using the hex version.