diff options
author | Jamis Buck <jamis@37signals.com> | 2005-08-22 14:47:16 +0000 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2005-08-22 14:47:16 +0000 |
commit | 82f44f314402cbd4627caa1c8ba24c35a5c875dd (patch) | |
tree | cd553b5c20ee9e2340a0fb5a5e0ee54e9d72db30 /actionpack | |
parent | c031a0163356502392f1e6b2839eb248909f9def (diff) | |
download | rails-82f44f314402cbd4627caa1c8ba24c35a5c875dd.tar.gz rails-82f44f314402cbd4627caa1c8ba24c35a5c875dd.tar.bz2 rails-82f44f314402cbd4627caa1c8ba24c35a5c875dd.zip |
Added :use_short_month option to select_month helper to show month names as abbreviations
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2033 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG | 2 | ||||
-rwxr-xr-x | actionpack/lib/action_view/helpers/date_helper.rb | 8 | ||||
-rwxr-xr-x | actionpack/test/template/date_helper_test.rb | 18 |
3 files changed, 26 insertions, 2 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 941538018c..165417969b 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added :use_short_month option to select_month helper to show month names as abbreviations + * Make link_to escape the javascript in the confirm option #1964 [nicolas.pouillard@gmail.com] * Make assert_redirected_to properly check URL's passed as strings #1910 [Scott Barron] diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 4b75e08e69..a516072acb 100755 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -181,16 +181,20 @@ module ActionView # select_month(Date.today, :add_month_numbers => true) # Will use keys like "1 - January", "3 - March" # # Override the field name using the <tt>:field_name</tt> option, 'month' by default. + # + # If you would prefer to show month names as abbreviations, set the + # <tt>:use_short_month</tt> key in +options+ to true. def select_month(date, options = {}) month_options = [] + month_names = options[:use_short_month] ? Date::ABBR_MONTHNAMES : Date::MONTHNAMES 1.upto(12) do |month_number| month_name = if options[:use_month_numbers] month_number elsif options[:add_month_numbers] - month_number.to_s + ' - ' + Date::MONTHNAMES[month_number] + month_number.to_s + ' - ' + month_names[month_number] else - Date::MONTHNAMES[month_number] + month_names[month_number] end month_options << ((date && (date.kind_of?(Fixnum) ? date : date.month) == month_number) ? diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index 27c340633f..c90a478292 100755 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -130,6 +130,24 @@ class DateHelperTest < Test::Unit::TestCase assert_equal expected, select_month(8, :add_month_numbers => true) end + def test_select_month_with_numbers_and_names_with_abbv + expected = %(<select name="date[month]">\n) + expected << %(<option value="1">1 - Jan</option>\n<option value="2">2 - Feb</option>\n<option value="3">3 - Mar</option>\n<option value="4">4 - Apr</option>\n<option value="5">5 - May</option>\n<option value="6">6 - Jun</option>\n<option value="7">7 - Jul</option>\n<option value="8" selected="selected">8 - Aug</option>\n<option value="9">9 - Sep</option>\n<option value="10">10 - Oct</option>\n<option value="11">11 - Nov</option>\n<option value="12">12 - Dec</option>\n) + expected << "</select>\n" + + assert_equal expected, select_month(Time.mktime(2003, 8, 16), :add_month_numbers => true, :use_short_month => true) + assert_equal expected, select_month(8, :add_month_numbers => true, :use_short_month => true) + end + + def test_select_month_with_abbv + expected = %(<select name="date[month]">\n) + expected << %(<option value="1">Jan</option>\n<option value="2">Feb</option>\n<option value="3">Mar</option>\n<option value="4">Apr</option>\n<option value="5">May</option>\n<option value="6">Jun</option>\n<option value="7">Jul</option>\n<option value="8" selected="selected">Aug</option>\n<option value="9">Sep</option>\n<option value="10">Oct</option>\n<option value="11">Nov</option>\n<option value="12">Dec</option>\n) + expected << "</select>\n" + + assert_equal expected, select_month(Time.mktime(2003, 8, 16), :use_short_month => true) + assert_equal expected, select_month(8, :use_short_month => true) + end + def test_select_year expected = %(<select name="date[year]">\n) expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n) |