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

Allow erb and haml helpers to take a block #641

Merged
merged 6 commits into from Feb 26, 2013
Merged

Allow erb and haml helpers to take a block #641

merged 6 commits into from Feb 26, 2013

Conversation

alexeymuranov
Copy link
Contributor

What do you think about this? I have changed only erb and haml helpers because for other template engines i do not know which ones have "layouts".

This is to be able to use nested layouts using erb and haml helpers. Real nested layouts, not in the sense of Rails.

When i want to nest two layouts in my application, i currently can do like this:

render :haml, :outer_layout, :layout => false do
  render :haml, :inner_layout1 do
    haml :page1
  end
end

I want to be able to do simply:

haml :outer_layout, :layout => false do
  haml :inner_layout1 do
    haml :page1
  end
end

@zzak
Copy link
Member

zzak commented Feb 17, 2013

@alexeymuranov Could you provide a test?

@alexeymuranov
Copy link
Contributor Author

Here are the tests. I only made changes for Haml and ERB, but i imagine there are other template engines that can accept blocks. I was tempted to use meta-programming to define these two helpers in one loop, but i think it would make the documentation harder to generate. Maybe there was a reason meta-programming was not used here before.

@zzak
Copy link
Member

zzak commented Feb 17, 2013

@alexeymuranov Some of them already support blocks, maybe you can go through and add support for the rest of them that will allow it?

I think it's best to leave it without any meta-programming. This way it's obvious which template helpers are supported, and can easily be removed or deprecated. That is probably the intention. Maybe @rkh can comment further.

@alexeymuranov
Copy link
Contributor Author

@zzak, do you know which ones exactly support blocks? If you do, can you tell me please?

@zzak
Copy link
Member

zzak commented Feb 17, 2013

@alexeymuranov you will have to check tilt, see tilt/lib/tilt/* and look for #evaluate in each template class.

@rkh
Copy link
Member

rkh commented Feb 18, 2013

Could you also add this to liquid, slim, creole, wlang, yajl and rabl and corresponding tests?

template(:a_page) { "<p>Contents.</p>\n" }
get('/') do
erb :main_outer_layout, :layout => false do
erb :an_inner_layout, :layout => false do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inner erb call should not need the :layout => false.

@alexeymuranov
Copy link
Contributor Author

Do not know how to use layouts in creole, yajl, and rabl, will need to look for examples...

@zzak
Copy link
Member

zzak commented Feb 18, 2013

@alexeymuranov creole, yajl and rabl all have tests, can you check there? these should all have tests, including the new block support.

@alexeymuranov
Copy link
Contributor Author

I do not see how to make a layout in creole for example. There are no such examples among tests, different layout engines are always used with creole.

@rkh
Copy link
Member

rkh commented Feb 18, 2013

Maybe it doesn't work, those were just the ones were the code permits layouts.

@alexeymuranov
Copy link
Contributor Author

It is possible to call yield in rabl: https://github.com/nesquena/rabl/wiki/Using-Layouts, but i have not figured out yet how exactly to use it.

@rkh
Copy link
Member

rkh commented Feb 25, 2013

Also, still needs docs in README.md.

@alexeymuranov
Copy link
Contributor Author

I can add docs to README. However, i would need much more time to figure out how to use yield in creole, yajl, and rabl. It seems that the semantics is slightly different from the five HTML templates that i have modified: in those five, yield can be used to insert ready-to-use blocks of HTML.

@rkh
Copy link
Member

rkh commented Feb 25, 2013

I guess the current code is fine.

In Russian README, "Вложенные шаблоны" -> "Включённые шаблоны"
Move "Embedded Templates" subsection in English and Russian README to a more appropriate place.
In English and Russian README, rename "Embedded Templates" to "Literal Templates".
@alexeymuranov
Copy link
Contributor Author

I have made several changes in English and Russian README, please tell me if you want them separated to another PR.

In Russian README, i had to change the term "вложенные шаблоны" because in my opinion it was not an appropriate translation of "Inline Templates", and conflicted with "вложенные раскладки" for "nested layouts" that i was adding.

I have also moved "Embedded Templates" subsection and renamed them to "Literal Templates". What do you think?

Those are all in separate commits, but if you do not want to merge them now, i can make a separate pull request.

Add README section "Templates with `yield` and nested layouts" in English and Russian.
rkh added a commit that referenced this pull request Feb 26, 2013
Allow `erb` and `haml` helpers to take a block
@rkh rkh merged commit bee7dd4 into sinatra:master Feb 26, 2013
@alexeymuranov alexeymuranov deleted the template-helpers-with-blocks branch February 26, 2013 09:09
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.

None yet

3 participants