Skip to content

Implementing the TiltYieldingFilter #28

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ethul
Copy link

@ethul ethul commented Mar 19, 2012

Hi All,

The purpose of this filter is to allow templates that adhere to the Tilt interface to yield to other templates, and be able to generate the final result from the nested structure. For example, if we have a slim template called layout.slim that we wanted to use as the layout for all of our HTML pages, it might look something like the following.

doctype html
html lang="en"
  head
    meta charset="utf-8"
    title template
  body
    == yield

For completeness, say we have an index.slim as follows where we want to use the template above as our layout for the index.

h1 Hello

Using the TiltYieldingFilter, we can create an Assetfile to generate the desired result. For instance:

require "slim"
require "rake-pipeline-web-filters"
output "public"
input "assets" do
  match "{layout,index}.slim" do
    tilt_yielding :yields_to => ["layout","index"], :output_name => "index.html"
  end
end

Building the Assetfile above, the filter would run the index.slim through Tilt, and then pass that result as the value for the yield in the layout.slim.

I am sure there is a more elegant way to do this, but I couldn't manage to get it going with the current filters out there. Though, maybe I am missing something! Anyways, if you have any suggestions or want to accept the pull request, that would be great!

Best,
-Eric

PS - I was thinking to modify the existing TiltFilter, but the behavior of the generate_output is so different that I thought it was cleaner to just make a new filter. I'd be open to working in the functionality to TiltFilter though.

The purpose of this filter is to allow templates that adhere to the Tilt
interface to yield to other templates. Basically, a yields-to chain is
created where the templates sequentially yield to their predecessor in
the list.

For example, given the yields-to chain of [a,b,c] the filter will
process this as a yields-to b and then b yields to c. This causes the
following behavior:
  - c is processed by Tilt, call this c'
  - c' is given as the value of the yield in b
  - b is processed by Tilt, call this b'
  - b' is given as the value of the yield in a
  - a is processed by Tilt, call this a'
  - a' is written as the final output
@dudleyf
Copy link
Collaborator

dudleyf commented May 20, 2012

Thanks for the PR, sorry it's taken so long to get back to you.

I'd like for the TiltFilter itself to be able to handle nested templates, but I'm not sure this is the right way to go. I don't like having to specify the :yields_to list up front. I don't know of a better way off the top of my head, but I'd like to think about it a little more.

@ethul
Copy link
Author

ethul commented May 21, 2012

No problem about the PR, and I agree that specifying the :yields_to list up front is not the most robust solution, but it fit the bill for the project I was working on at the time. I'd be interested in something more elegant though and can also put some more thought into this.

Cheers,
-Eric

@morgoth
Copy link
Contributor

morgoth commented May 21, 2012

You can take a look at very simple filter, that adds support for layout. Maybe you can figure out something based on that.
https://gist.github.com/b23ffa4fe052d26505b3

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

Successfully merging this pull request may close these issues.

3 participants