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

Please consider adding "partial" functionality to this library #1

Open
bzerangue opened this issue Oct 19, 2012 · 7 comments
Open

Please consider adding "partial" functionality to this library #1

bzerangue opened this issue Oct 19, 2012 · 7 comments

Comments

@bzerangue
Copy link

Out of result of the following Twitter conversation, I would like to make a request to add "partial" functionality to the "Haml Contrib" project…

@bmz wrote: @compay is there a way to do partials with Haml outside of Rails? If not, is there a reason why it can't?

@compay wrote: @bmz No, it's not built in, because it's a framework feature rather than a language one. But it's easy to implement: semicomplete.com/blog/tags/haml

@compay wrote: @bmz that said, we've recently created a "Haml Contrib" project for things that don't belong in the language, but are generally useful...

@compay wrote: @bmz ...and I think a simple implementation of partials is a good candidate for inclusion there.

@compay wrote: @bmz Feel free to open an issue at github.com/haml/haml-cont… and share your thoughts on how you think it should work

I know Sass and Haml were once from the same library. Sass natively has always had a "partials" feature (or at least that I know), but Haml does not. I have never understood why that is.

I would love to have the opportunity to manage my HAML templates outside of a framework per se. I would like to have my CodeKit (or Terminal), my text editor, my browser and that's it. Why do I need to learn some framework language to manage my Haml templates in a modular and DRY way?

I think it would be a great benefit to add "partial" (or include) functionality to the "Haml Contrib" project. I love writing Haml and managing my templates with it, but would love to start modularizing it (or managing it in chunks). Partials would allow users to utilize DRY principles while managing their Haml markup without having to learn or rely on Rails or Sinatra or any other framework.

I envision it working similar to the way partials work in Sass. Add a file name with underscore preceding the name _nav.haml. This file would and could be included but not compiled by the Haml processor to a normal HTML file.

Please consider adding "partial" functionality to the "Haml Contrib" project.

Thank you for your consideration!

@mattwildig
Copy link
Contributor

There was a question on StackOverflow asking how to do something like this that I had a go at answering: http://stackoverflow.com/questions/6125265/using-layouts-in-haml-files-independently-of-rails.

I’ve created a simple implementation based on this and pushed to a branch: https://github.com/haml/haml-contrib/tree/partials.

Have a look and let me know what you think. To use it you’ll need to clone the haml-contrib repo and make sure it’s checked out to the partials branch, then you can do:

$ haml -I'/path/to/haml-contrib/lib' -rhaml/partials your_haml_file.haml

And inside your Haml file you can use the render method to render a partial.

This will need a bit of polishing up before it’s ready to be merged, in particular I haven’t written any tests.

Other issues:

  1. The method name. I’ve used render based on Rails, but I’m undecided on whether this is good (because people will know what to expect) or bad (because it’s not quite the same as Rails).
  2. The base directory – currently it just defaults to the current working directory, should this be configurable? (If so how?).
  3. The filename search process. I just made this up based on what seemed ok. Thoughts?

@bzerangue
Copy link
Author

@mattwildig I tried it out. It seems to work OK with your instructions. Do you know if it's possible to pass those parameters in apps like CodeKit?

@mattwildig
Copy link
Contributor

I don’t know, it will depend on what options CodeKit gives for customising it’s use of Haml. Does it allow adding files to be required before Haml does its thing?

Note that you don’t necessarily need the -I option, which is adding to Ruby’s load path – you could just require /path/to/haml-contrib/lib/haml/partials directly if you have the option to add files to require but not to alter the load path.

A possible workaround might be to require the partials file in your Haml files themselves:

- $:.unshift '/path/to/haml-contrib/lib' unless $:.include? '/path/to/haml-contrib/lib'
- require 'haml/partials'

or

- require '/path/to/haml-contrib/lib/haml/partials'

@AllanD
Copy link

AllanD commented Aug 5, 2013

wow 10 months ago, and codekit still doesn't have partials functionality? Its like getting 99% there with 100% being required to match out-side of rails development.

@nxtbz
Copy link

nxtbz commented Feb 23, 2014

i'm curious, did somebody got the haml :render working in codekit ?

@aethant
Copy link

aethant commented Feb 27, 2014

I'd really like :php to work in Codekit, but no dice. :/

@nxtbz
Copy link

nxtbz commented Feb 28, 2014

Then try 'middleman', dont know if it supports php but the app is more functional and maintained

Verstuurd vanaf mijn iPhone

Op 27 feb. 2014 om 23:36 heeft aethant notifications@github.com het volgende geschreven:

I'd really like :php to work in Codekit, but no dice. :/


Reply to this email directly or view it on GitHub.

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

5 participants