<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sean&#039;s Blog &#187; block</title>
	<atom:link href="http://seanbehan.com/tag/block/feed/" rel="self" type="application/rss+xml" />
	<link>http://seanbehan.com</link>
	<description>Web Programming, Ruby on Rails, Wordpress, PHP from Burlington, Vermont</description>
	<lastBuildDate>Wed, 18 Jan 2012 21:44:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Yield a Block within Rails Helper Method with Multiple Content_tags Using Concat</title>
		<link>http://seanbehan.com/programming/yield-a-block-within-rails-helper-method-with-multiple-content_tags-using-concat/</link>
		<comments>http://seanbehan.com/programming/yield-a-block-within-rails-helper-method-with-multiple-content_tags-using-concat/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 14:58:53 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[concat]]></category>
		<category><![CDATA[content_tag]]></category>
		<category><![CDATA[dry]]></category>
		<category><![CDATA[helpers]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[strings]]></category>
		<category><![CDATA[views]]></category>
		<category><![CDATA[wrapper]]></category>
		<category><![CDATA[yield]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=923</guid>
		<description><![CDATA[To clean up some repetitive html coding in views, pass a block of text to a helper function which will wrap it for you the same way, each and every time. For example, I have a &#8216;help&#8217; link which will toggle the display of a block of text if a link is clicked. I use [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fprogramming%2Fyield-a-block-within-rails-helper-method-with-multiple-content_tags-using-concat%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Yield a Block within Rails Helper Method with Multiple Content_tags Using Concat" data-url="http://seanbehan.com/programming/yield-a-block-within-rails-helper-method-with-multiple-content_tags-using-concat/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>To clean up some repetitive html coding in views, pass a block of text to a helper function which will wrap it for you the same way, each and every time. For example, I have a &#8216;help&#8217; link which will toggle the display of a block of text if a link is clicked. I use this &#8220;+/- help&#8221; link throughout my application in various views. I could create a partial but this gets messy. Instead this is what I want to write in my views&#8230;</p>
<pre class="wp-code-highlight prettyprint">
&amp;lt;% help do %&amp;gt;
  here is my help text...
&amp;lt;% end %&amp;gt;
</pre>
<p>which will render HTML similar to this&#8230;</p>
<pre class="wp-code-highlight prettyprint">
&amp;lt;a href='#' 'class='help' id='help_link_123456' onclick='some_func_to_toggle_state'&amp;gt;+/- help&amp;lt;/a&amp;gt;
&amp;lt;div id=&quot;help_123456&quot;&amp;gt;
  here is my help text...
&amp;lt;/div&amp;gt;
</pre>
<p>In order to accomplish this you need to create a helper method. Assigning a unique id, just a random number, will help avoid collisions with the state of the toggled div if you use this more than once per page. Placing other HTML helper methods inside the concat() method allows multiple tags as well as rendering the block passed to the function in the appropriate place. It looks a little unwieldy, but works nicely.</p>
<pre class="wp-code-highlight prettyprint">
# app/helpers/application_helper.rb
module ApplicationHelper
  def help(&amp;block)
    uniqid = rand; concat( link_to_function(&quot;+/- help&quot;) do |page|
      page[&quot;help_#{uniqid}&quot;].toggle
      page.visual_effect :highlight, &quot;help_#{uniqid}&quot;
    end + content_tag(:div,:class=&gt;&quot;help&quot;,:id=&gt;&quot;help_#{uniqid}&quot;, :style=&gt;&quot;display:none&quot;) do
      yield
    end )
  end
end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/programming/yield-a-block-within-rails-helper-method-with-multiple-content_tags-using-concat/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cool Conditional Syntax in Ruby (on Rails)</title>
		<link>http://seanbehan.com/ruby-on-rails/cool-conditional-syntax-in-ruby-on-rails/</link>
		<comments>http://seanbehan.com/ruby-on-rails/cool-conditional-syntax-in-ruby-on-rails/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 15:05:21 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[beauty]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[conditional]]></category>
		<category><![CDATA[syntax]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=541</guid>
		<description><![CDATA[Ruby is beautiful @posts = if true Post.all else [] end Simply elegant!]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fruby-on-rails%2Fcool-conditional-syntax-in-ruby-on-rails%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Cool Conditional Syntax in Ruby (on Rails)" data-url="http://seanbehan.com/ruby-on-rails/cool-conditional-syntax-in-ruby-on-rails/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>Ruby is beautiful</p>
<pre class="wp-code-highlight prettyprint">

@posts =
  if true
     Post.all
  else
    []
  end
</pre>
<p>Simply elegant!</p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/ruby-on-rails/cool-conditional-syntax-in-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

