<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -23,6 +23,7 @@ The following tags are available to help you build the form:
   &lt;r:mailer:radio name=&quot;&quot; /&gt;
   &lt;r:mailer:radiogroup name=&quot;&quot;&gt; ... &lt;/r:mailer:radiogroup&gt;
   &lt;r:mailer:select name=&quot;&quot;&gt; ... &lt;/r:mailer:select&gt;
+  &lt;r:mailer:date_select name=&quot;&quot;/&gt;
   &lt;r:mailer:textarea name=&quot;&quot;&gt; ... &lt;/r:mailer:textarea&gt;
   &lt;r:mailer:option name=&quot;&quot; /&gt;
 </diff>
      <filename>README.rdoc</filename>
    </modified>
    <modified>
      <diff>@@ -34,4 +34,4 @@ class MailController &lt; ApplicationController
     [(string.empty? ? {} : YAML::load(string).symbolize_keys), page]
   end
 
-end
\ No newline at end of file
+end</diff>
      <filename>app/controllers/mail_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,6 @@
 module MailerTags
   include Radiant::Taggable
+  include ActionView::Helpers::DateHelper
 
   def config
     @config ||= begin
@@ -180,6 +181,30 @@ module MailerTags
   			end
   	end
 	  result
+	end
+	
+  desc %{ Uses @ActionView::Helpers::DateHelper.date_select@ to render three select tags for date selection. }
+  tag 'mailer:date_select' do |tag|
+    raise_error_if_name_missing &quot;mailer:date_select&quot;, tag.attr
+    name = tag.attr.delete('name')
+    
+    options = {}
+    
+    tag.attr.each do |k, v|
+      if v =~ /(true|false)/
+        options[k] = (v == 'true')
+      elsif v =~ /\d+/
+        options[k] = v.to_i
+      elsif k == 'order'
+        options[k] = v.split(',').map(&amp;:strip).map(&amp;:to_sym)
+      else
+        options[k] = v
+      end
+    end
+    
+    options.symbolize_keys!
+    
+    date_select('mailer', name, options)
   end
 
   desc %{
@@ -195,7 +220,7 @@ module MailerTags
       element = tag.locals.page.last_mail.data
     end
     if name
-      element[name].is_a?(Array) ? element[name].to_sentence : element[name]
+      format_mailer_data(element, name)
     else
       element.to_hash.to_yaml.to_s
     end
@@ -218,6 +243,28 @@ module MailerTags
     mail = tag.locals.page.last_mail || tag.globals.page.last_mail
     tag.expand if name &amp;&amp; mail.data[name] &amp;&amp; (eq.blank? || eq == mail.data[name])
   end
+  
+  def format_mailer_data(element, name)
+    data = element[name]
+    if Array === data
+      data.to_sentence
+    elsif date = detect_date(element, name)
+      date
+    else
+      data
+    end
+  end
+  
+  def detect_date(mail, name)
+    date_components = mail.select { |key, value| key =~ Regexp.new(&quot;#{name}\\(\\di\\)&quot;) }
+    
+    if date_components.length == 3
+      date_values = date_components.sort { |a, b| a[0] &lt;=&gt; b[0] }.map { |v| v[1].to_i }
+      return Date.new(*date_values)
+    else
+      return nil
+    end
+  end
 
   def prior_value(tag, tag_name=tag.attr['name'])
     if mail = tag.locals.page.last_mail</diff>
      <filename>lib/mailer_tags.rb</filename>
    </modified>
    <modified>
      <diff>@@ -176,6 +176,40 @@ describe &quot;MailerTags&quot; do
       pages(:mail_form).should render(&quot;&lt;r:mailer:select name='foo' required='true'/&gt;&quot;).as(%Q{&lt;select size=&quot;1&quot; id=&quot;foo&quot; name=&quot;mailer[foo]&quot;&gt;&lt;/select&gt;&lt;input type=&quot;hidden&quot; name=&quot;mailer[required][foo]&quot; value=&quot;true&quot; /&gt;})
     end
   end
+  
+  describe &quot;&lt;r:mailer:date_select&gt;&quot; do
+    # HACK: Quick way to get a tag rendered to string in the context of a page.
+    # How can this be made better?
+    def render_tag_in_mailer(content)
+      tag = Spec::Rails::Matchers::RenderTags.new
+      tag.send(:render_content_with_page, content, pages(:mail_form))
+    end
+    
+    it &quot;should render select tags for each date component&quot; do
+      date_select = render_tag_in_mailer('&lt;r:mailer:date_select name=&quot;foo&quot; /&gt;')
+      date_select.should have_tag('select[name=?]', &quot;mailer[foo(1i)]&quot;)
+      date_select.should have_tag('select[name=?]', &quot;mailer[foo(2i)]&quot;)
+      date_select.should have_tag('select[name=?]', &quot;mailer[foo(3i)]&quot;)
+    end
+    
+    it &quot;should include blank options&quot; do
+      date_select = render_tag_in_mailer('&lt;r:mailer:date_select name=&quot;foo&quot; include_blank=&quot;true&quot; /&gt;')
+      date_select.should have_tag('select[name=?]', &quot;mailer[foo(1i)]&quot;) do
+        with_tag('option[value=?]', '')
+      end
+      date_select.should have_tag('select[name=?]', &quot;mailer[foo(2i)]&quot;) do
+        with_tag('option[value=?]', '')
+      end
+      date_select.should have_tag('select[name=?]', &quot;mailer[foo(3i)]&quot;) do
+        with_tag('option[value=?]', '')
+      end
+    end
+    
+    it &quot;should order select tags&quot; do
+      date_select = render_tag_in_mailer('&lt;r:mailer:date_select name=&quot;foo&quot; order=&quot;day,year,month&quot; /&gt;')
+      date_select.should have_tag('select[name=?]+select[name=?]+select[name=?]','mailer[foo(3i)]', 'mailer[foo(1i)]', 'mailer[foo(2i)]')
+    end
+  end
 
   describe &quot;&lt;r:mailer:textarea&gt;&quot; do
     it &quot;should render a textarea tag&quot; do
@@ -236,6 +270,11 @@ describe &quot;MailerTags&quot; do
     it &quot;should render nothing when the value is not present&quot; do
       @page.should render('&lt;r:mailer:get name=&quot;body&quot; /&gt;').as('')
     end
+    
+    it &quot;should render date when date params are detected&quot; do
+      @page.last_mail = @mail = Mail.new(@page, @page.config, 'foo(1i)' =&gt; '2008', 'foo(2i)' =&gt; '10', 'foo(3i)' =&gt; '29')
+      @page.should render('&lt;r:mailer:get name=&quot;foo&quot; /&gt;').as('2008-10-29')
+    end
   end
   
   describe &quot;&lt;r:mailer:get_each&gt;&quot; do</diff>
      <filename>spec/lib/mailer_tags_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>12149cbe499a56fbc4ba3398003f54445d86c07c</id>
    </parent>
  </parents>
  <author>
    <name>Jason Stirk</name>
    <email>jstirk@gmail.com</email>
  </author>
  <url>http://github.com/radiant/radiant-mailer-extension/commit/52fe964b3bb20c310c88576c10f31c6c1da13b54</url>
  <id>52fe964b3bb20c310c88576c10f31c6c1da13b54</id>
  <committed-date>2008-11-27T06:32:06-08:00</committed-date>
  <authored-date>2008-11-27T06:32:06-08:00</authored-date>
  <message>Merged in changes from Aissac's tree.</message>
  <tree>5612937c49274c3af2882aa9e8dcd467020e1bf3</tree>
  <committer>
    <name>Jason Stirk</name>
    <email>jstirk@gmail.com</email>
  </committer>
</commit>
