date_select_separator 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -36,9 +36,10 @@ And then use ```use_separators: true```:
36
36
  <%= f.date_select :birthday, use_separators: {inline: true} %>
37
37
  <%= f.datetime_select :birthday, time_separator: '', use_separators: {inline: true} %>
38
38
 
39
- # Options: html_tag, class_prefix
39
+ # Options: html_tag, class_prefix etc
40
40
  <%= f.date_select :birthday, use_month_numbers: true, use_separators: {html_tag: :div, class_prefix: 'foo'} %>
41
-
41
+ <%= f.date_select :birthday, use_month_numbers: true, use_separators: {year: 'yy', month: 'mm', day: 'dd'} %>
42
+
42
43
  ## Contributing
43
44
 
44
45
  1. Fork it
@@ -1,3 +1,3 @@
1
1
  module DateSelectSeparator
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -20,7 +20,7 @@ module ActionView
20
20
 
21
21
  if separators.present?
22
22
  if use_inline_separator?(separators)
23
- options.merge!({:use_separator => translated_separator_name(type)})
23
+ options.merge!({:use_separator => separator_name(type, separators)})
24
24
  build_select(type, build_options_with_separator(selected, options))
25
25
  else
26
26
  build_select(type, build_options(selected, options)) + separator_tag(type, separators)
@@ -41,6 +41,15 @@ module ActionView
41
41
  I18n.translate(key, :locale => @options[:locale])
42
42
  end
43
43
 
44
+ def separator_name(type, separators)
45
+ if separators.class == Hash && separators[type].present?
46
+ separators[type]
47
+ else
48
+ key = 'datetime.separators.' + type.to_s
49
+ I18n.translate(key, :locale => @options[:locale])
50
+ end
51
+ end
52
+
44
53
  def separator_tag(type, separators)
45
54
  return '' if use_inline_separator?(separators)
46
55
 
@@ -48,7 +57,7 @@ module ActionView
48
57
  options = (separators.class == Hash) ? default_options.merge!(separators) : default_options
49
58
 
50
59
  if options
51
- name = translated_separator_name(type)
60
+ name = separator_name(type, separators)
52
61
  class_name = options[:class_prefix] + "_#{type}"
53
62
  content_tag(options[:html_tag], name, :class => class_name) + "\n"
54
63
  else
@@ -597,4 +597,38 @@ class DateSelectSeparatorTest < ActionView::TestCase
597
597
 
598
598
  assert_dom_equal expected, datetime_select("post", "updated_at", :use_separators => {:inline => true}, :locale => :ja)
599
599
  end
600
+
601
+ def test_datetime_select_with_custom_separators_and_arguments
602
+ @post = Post.new
603
+ @post.updated_at = Time.local(2004, 6, 15, 16, 35)
604
+
605
+ expected = %{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n}
606
+ expected << %{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n}
607
+ expected << "</select>\n"
608
+ expected << %(<span class="separator_year">foo_year</span>\n)
609
+
610
+ expected << %{<select id="post_updated_at_2i" name="post[updated_at(2i)]">\n}
611
+ expected << %{<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6" selected="selected">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n}
612
+ expected << "</select>\n"
613
+ expected << %(<span class="separator_month">foo_month</span>\n)
614
+
615
+ expected << %{<select id="post_updated_at_3i" name="post[updated_at(3i)]">\n}
616
+ expected << %{<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15" selected="selected">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n}
617
+ expected << "</select>\n"
618
+ expected << %(<span class="separator_day">foo_day</span>\n)
619
+
620
+ expected << " &mdash; "
621
+
622
+ expected << %{<select id="post_updated_at_4i" name="post[updated_at(4i)]">\n}
623
+ expected << %{<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16" selected="selected">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n}
624
+ expected << "</select>\n"
625
+ expected << %(<span class="separator_hour">foo_hour</span>\n)
626
+ expected << " : "
627
+ expected << %{<select id="post_updated_at_5i" name="post[updated_at(5i)]">\n}
628
+ expected << %{<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35" selected="selected">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n}
629
+ expected << "</select>\n"
630
+ expected << %(<span class="separator_minute">foo_minute</span>\n)
631
+
632
+ assert_dom_equal expected, datetime_select("post", "updated_at", :use_separators => {year: 'foo_year', month: 'foo_month', day: 'foo_day', hour: 'foo_hour', minute: 'foo_minute'})
633
+ end
600
634
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: date_select_separator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-05 00:00:00.000000000 Z
12
+ date: 2013-03-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails