I want to create layout components that function like my layout does. A
layout can yield the body content, is there any way to get this
functionality in rhtml templates? For example, say I have a layout
component that has a title bar and a content area. If it is a box with
rounded corners I do not want to repeat this html everywhere, so I''ll
make a
helper. Here is what I have to do now:
<%= start_mini_window("Log in!") %>
log in form html here
<%= end_mini_window %>
Is it possible to do this?
<% mini_window("Log in!") do %>
log in form html here
<% end %>
This feels cleaner to me, but I was unable to get it working. I stopped
trying to get this working when I realized that render() only uses your proc
block when creating a javascriptgenerator.
Any ideas?
Thanks,
Zack Ham
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On 11/29/06, Zack Ham <zackham-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I want to create layout components that function like my layout does. A > layout can yield the body content, is there any way to get this > functionality in rhtml templates? For example, say I have a layout > component that has a title bar and a content area. If it is a box with > rounded corners I do not want to repeat this html everywhere, so I''ll make a > helper. Here is what I have to do now: > > <%= start_mini_window("Log in!") %> > log in form html here > <%= end_mini_window %> > > Is it possible to do this? > > <% mini_window("Log in!") do %> > log in form html here > <% end %> > > This feels cleaner to me, but I was unable to get it working. I stopped > trying to get this working when I realized that render() only uses your proc > block when creating a javascriptgenerator. > > Any ideas? > > Thanks, > Zack HamI''m not sure that I can help you with your particular case, but the form_for helper works like this. The code for that method is def form_for(object_name, *args, &proc) raise ArgumentError, "Missing block" unless block_given? options = args.last.is_a?(Hash) ? args.pop : {} concat(form_tag(options.delete(:url) || {}, options.delete(:html) || {}), proc.binding) fields_for(object_name, *(args << options), &proc) concat(''</form>'', proc.binding) end This can be found at http://dev.rubyonrails.org/svn/rails/trunk/actionpack/lib/action_view/helpers/form_helper.rb That might give you some ideas. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I looked at form_for because it is a good example of the benefits to proc blocks in templates. The code didn''t tell me a whole lot unfortunately. What I really want to do is take the proc block contents and yield it into a string, then pass that string to a partial template. I didn''t see form_for doing that, but maybe I missed something. If I can yield the proc block contents into a string, that lets me actually pass parameters to the block and derive benefits like form_for does. Can anyone explain how/if this is possible, and how it would work with concat()? Thanks! Zack On 11/28/06, Daniel N <has.sox-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > On 11/29/06, Zack Ham <zackham-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I want to create layout components that function like my layout does. > > A layout can yield the body content, is there any way to get this > > functionality in rhtml templates? For example, say I have a layout > > component that has a title bar and a content area. If it is a box with > > rounded corners I do not want to repeat this html everywhere, so I''ll make a > > helper. Here is what I have to do now: > > > > <%= start_mini_window("Log in!") %> > > log in form html here > > <%= end_mini_window %> > > > > Is it possible to do this? > > > > <% mini_window("Log in!") do %> > > log in form html here > > <% end %> > > > > This feels cleaner to me, but I was unable to get it working. I stopped > > trying to get this working when I realized that render() only uses your proc > > block when creating a javascriptgenerator. > > > > Any ideas? > > > > Thanks, > > Zack Ham > > > I''m not sure that I can help you with your particular case, but the > form_for helper works like this. > > The code for that method is > > > def form_for(object_name, *args, &proc) > raise ArgumentError, "Missing block" unless block_given? > options = args.last.is_a?(Hash) ? args.pop : {} > concat(form_tag(options.delete > (:url) || {}, options.delete(:html) || {}), proc.binding) > fields_for(object_name, *(args << options), &proc) > concat(''</form>'', proc.binding) > end > > This can be found at > http://dev.rubyonrails.org/svn/rails/trunk/actionpack/lib/action_view/helpers/form_helper.rb > > That might give you some ideas. > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
copy paste from form_for() method. you may have to figure out how to
pass actual params.
concat() just append strings to output buffer string.
in your controller helper:
-----------------------------------------------------------
def widget(&proc)
raise ArgumentError, "Missing block" unless block_given?
concat(''<div><p>hello world</p>'',
proc.binding)
yield proc
concat(''</div>'', proc.binding)
end
in rhtml
--------------------------------------------------------
<% widget do |w| %>
does it work?
<% end %>
and you got
------------------------------------------------------
<div><p>hello world</p>
does it work?
</div>
wuyaSea operator
http://www.wuyaSea.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
I think this article at "Err the Blog" has the solution you are looking for: http://errtheblog.com/post/13 On 11/28/06, WuyaSea Operator <wuyasea-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > copy paste from form_for() method. you may have to figure out how to > pass actual params. > concat() just append strings to output buffer string. > > in your controller helper: > ----------------------------------------------------------- > def widget(&proc) > raise ArgumentError, "Missing block" unless block_given? > concat(''<div><p>hello world</p>'', proc.binding) > yield proc > concat(''</div>'', proc.binding) > end > > in rhtml > -------------------------------------------------------- > <% widget do |w| %> > does it work? > <% end %> > > and you got > ------------------------------------------------------ > <div><p>hello world</p> > does it work? > > </div> > > > wuyaSea operator > http://www.wuyaSea.com > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Perfect. Thanks Zack On 11/29/06, Jimmy Kittiyachavalit <jkittiya-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I think this article at "Err the Blog" has the solution you are looking > for: > > http://errtheblog.com/post/13 > > > > On 11/28/06, WuyaSea Operator <wuyasea-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > copy paste from form_for() method. you may have to figure out how to > > pass actual params. > > concat() just append strings to output buffer string. > > > > in your controller helper: > > ----------------------------------------------------------- > > def widget(&proc) > > raise ArgumentError, "Missing block" unless block_given? > > concat(''<div><p>hello world</p>'', proc.binding) > > yield proc > > concat(''</div>'', proc.binding) > > end > > > > in rhtml > > -------------------------------------------------------- > > <% widget do |w| %> > > does it work? > > <% end %> > > > > and you got > > ------------------------------------------------------ > > <div><p>hello world</p> > > does it work? > > > > </div> > > > > > > wuyaSea operator > > http://www.wuyaSea.com > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---