Can I do it without resorting to making another partial to contain the %span content below? # partial begin - if defined(skipLI) && skipLI %span this is not DRY - else %li %span this is not DRY # partial end -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/LIoHBKXXDxIJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Try content_for maybe? Usually it''s used for passing snippets up the template chain, but it would probably work in this case as well. - content_for(:not_dry) do %span this is not DRY - if defined?(skipLI) && skipLI - yield :not_dry - else %li - yield :not_dry On Tue, Jul 19, 2011 at 6:54 PM, Chris Braddock <braddock.chris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> Can I do it without resorting to making another partial to contain the > %span content below? > > # partial begin > - if defined(skipLI) && skipLI > %span this is not DRY > - else > %li > %span this is not DRY > # partial end > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/LIoHBKXXDxIJ. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
One idea off the top of my head: Create a helper method and use content_tag def give_it_to_me html_content = content_tag(:span, ''This is DRY'') defined?(skipLI) && skipLI ? html_content : content_tag(:li, html_content) end I think this will work. Jamey On Tue, Jul 19, 2011 at 12:54 PM, Chris Braddock <braddock.chris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> Can I do it without resorting to making another partial to contain the > %span content below? > > # partial begin > - if defined(skipLI) && skipLI > %span this is not DRY > - else > %li > %span this is not DRY > # partial end > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/LIoHBKXXDxIJ. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Nice! Had to change from - yield to = yield. Thanks. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/3VylSqGfnHIJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks. I was hoping to not have to pull the code out in to another file. Not sure if I would have been able to define a method inside the same haml file or not. The yield suggestion seems to have worked in any case. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/7jg3d08XXaQJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks, it''s good. I had the same problem with links instead of li, and I''ve encountered link_to_if in the reference: =link_to_if make_link, url_for(...) do this is dry :D You could see the source of link_to_if (and link_to_unless) to see how to implement it for %li''s if you want to. Also, I''ve just found capture: - not_dry = capture do %span This is not dry - if defined?(skipLI) && skipLI =not_dry - else %li =not_dry -- Posted via http://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Bernat Kallo wrote in post #1012148:> =link_to_if make_link, url_for(...) do > this is dry :DNo, it''s wrong :$ this is not the way link_to can be used -- Posted via http://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Another option is to create a generic helper: def wrap_with_li_if(condition, content = nil, &block) if block_given? content = capture(&block) end return content_tag(:li, content) if condition return content end Then you can use it like so: = wrap_with_li_if(defined?(skipLI) && skipLI) do %span This is not DRY or - notDRY = "This is not DRY" = wrap_with_li_if(defined?(skipLI) && skipLI, notDRY) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/a4nJLzovFnQJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Now that I''m thinking about it, you can maybe even make it more generic if you like. I can actually think of a few places in my own code this would come in handy: def content_tag_if(condition, tag, content = nil, &block) if block_given? content = capture(&block) end return content_tag(tag, content) if condition return content end = content_tag_if(defined?(skipLI) && skipLI, :li) do %span This is not DRY -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/bPOPDdNZ2IgJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.