<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Robby on Rails: Tag copyrights</title>
    <link>http://www.robbyonrails.com/articles/tag/copyrights</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>thoughts.sort_by{|t| t[:topic]}.collect </description>
    <item>
      <title>DRY(a): Year After Year</title>
      <description>&lt;p&gt;I&amp;#8217;m guilty of it. Many of you are likely guilty of it&amp;#8230; and I know that several customers of our &lt;a href="http://www.robbyonrails.com/articles/2007/06/17/audit-your-rails-development-team"&gt;Rails Code Audit and Review service&lt;/a&gt; are guilty of it.&lt;/p&gt;


	&lt;p&gt;How many times have you realized (after a few months has passed) that your Copyright date/year on your web site was no longer current?&lt;/p&gt;


	&lt;p&gt;How many of you had the same problem last year? The year before?&lt;/p&gt;


	&lt;p&gt;Let me share some advice with you all&amp;#8230; &lt;span class="caps"&gt;DRY&lt;/span&gt; (a)!&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Don&amp;#8217;t Repeat Yourself (again)!&lt;/strong&gt;&lt;/p&gt;


	&lt;p&gt;This is really a simple problem to fix but when we&amp;#8217;re busy tackling bigger problems&amp;#8230; little things like this slip by. Don&amp;#8217;t worry, you&amp;#8217;re not the only one who was reminded by a colleague three months into the year that you forgot to update this.&lt;/p&gt;


	&lt;p&gt;On client projects, we have a handful of helpers that we drop into the application. We&amp;#8217;re starting to extract more of these into plugins and will be releasing those as time permits. It just happened that I found myself looking at yet-another Rails code base this afternoon that was showing 2007 in the footer. An easily forgivable offense.. but if you&amp;#8217;re going to go in there and change it (again), &lt;em&gt;take a moment to do the right thing&lt;/em&gt;. ;-)&lt;/p&gt;


	&lt;p&gt;Our solution at &lt;a href="http://planetargon.com"&gt;Planet Argon&lt;/a&gt; on client projects is to create a basic view helper that renders the current year. This allows us to do the following.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
  &amp;lt;div id="footer"&amp;gt;
    &amp;amp;copy; Copyright &amp;lt;%= current_year -%&amp;gt;. All Rights Reserved.
  &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;The helper code looks like:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
  # add to application_helper.rb
  module ApplicationHelper
    def current_year
      Time.now.strftime('%Y')
    end
  end
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Voila. Not rocket science.. is it?&lt;/p&gt;


	&lt;p&gt;Guess what? I&amp;#8217;m getting really tired of adding this to every Rails project that I touch. So, I bottled this little gem into a new Rails plugin that we&amp;#8217;ll just add to future projects.&lt;/p&gt;


	&lt;h2&gt;Introducing Year after Year&lt;/h2&gt;


	&lt;p&gt;This is really the smallest plugin that I could put together (and it includes specs!)&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;What does it provide you?&lt;/strong&gt;&lt;/p&gt;


	&lt;p&gt;YearAfterYear will provide you a helper that will render the current year (dynamically)! That&amp;#8217;s right&amp;#8230; just add the plugin to your Rails application and you too can enjoy New Years 2009 without having to have a deployment ready with a one line change from 2008 to 2009!&lt;/p&gt;


	&lt;p&gt;To use.. add the following to any view from within Ruby on Rails.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
  &amp;lt;%= current_year -%&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

	&lt;h3&gt;Installation&lt;/h3&gt;


	&lt;p&gt;As I&amp;#8217;m using git, you&amp;#8217;ll need to grab this and put it into &lt;code&gt;vendor/plugins&lt;/code&gt;. That&amp;#8217;s it!&lt;/p&gt;


	&lt;p&gt;You can grab it on &lt;a href="http://github.com"&gt;GitHub&lt;/a&gt;!&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://github.com/robbyrussell/year_after_year/"&gt;http://github.com/robbyrussell/year_after_year/&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;Bugs / Feature Requests &lt;a href="http://planetargon.lighthouseapp.com/projects/5187-open-source-projects/tickets"&gt;here&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Happy New Years (8+ months early)!&lt;/p&gt;


	&lt;p&gt;Just a friendly reminder to not forget the small stuff&amp;#8230; because your visitors will notice! ;-)&lt;/p&gt;


	&lt;h3&gt;Updates&amp;#8230;&lt;/h3&gt;


	&lt;p&gt;I got a few requests for this to also provide a range of years for people who like to do: &lt;strong&gt;2005-2007&lt;/strong&gt;. So this is now provided as well.&lt;/p&gt;


	&lt;p&gt;&lt;code&gt;year_range(start_year)&lt;/code&gt;&lt;/p&gt;


Example:
&lt;pre&gt;&lt;code&gt;
  &amp;lt;%= year_range(2005) %&amp;gt; # =&amp;gt; 2005-2008
&lt;/code&gt;&lt;/pre&gt;
</description>
      <pubDate>Mon, 24 Mar 2008 22:05:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:4228a063-facc-4a13-bdb0-342c0fab415e</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2008/03/24/dry-a-year-after-year</link>
      <category>Ruby on Rails</category>
      <category>Ruby</category>
      <category>Programming</category>
      <category>PLANET ARGON</category>
      <category>sarcasm</category>
      <category>plugin</category>
      <category>rails</category>
      <category>rubyonrails</category>
      <category>years</category>
      <category>copyrights</category>
      <category>joke</category>
      <category>plugins</category>
    </item>
  </channel>
</rss>
