jquery_datepicker 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -2,33 +2,52 @@
2
2
 
3
3
  This simple gem allows you to add a date picker field into your views.
4
4
 
5
- == Installation
5
+ == Getting Started
6
6
 
7
- As this gem is using jQuery Ui plugin, be sure that you are already using jquery into your project. In order to install it:
7
+ 1. Add into your Gemfile:
8
8
 
9
- * Add into your Gemfile
10
- gem 'jquery-rails'
9
+ gem 'jquery-rails'
11
10
 
12
- * Execute this command to install the needed js files
11
+ 2. Execute this command to install the needed js files:
13
12
 
14
- rails generate jquery:install --ui
13
+ rails generate jquery:install --ui
15
14
 
16
- * Insert into your Gemfile:
17
15
 
18
- gem 'jquery_datepicker'
16
+ 3. Insert into your Gemfile:
17
+
18
+ gem 'jquery_datepicker'
19
+
19
20
 
20
21
  == Usage
21
22
 
22
23
  Add this to your view.
23
24
 
24
- <%= datepicker_input "user","birthday" %>
25
+ <%= datepicker_input "user","birthday" %>
26
+
25
27
 
26
28
  Where "user" is your model name and "birthday" the name of the datefield.
27
29
 
28
30
  You can also use it with the form helper like:
29
31
 
30
- <% form_for(@user) do |f| %>
31
- <%= f.datepicker 'birthday' %>
32
- <%= f.submit 'Create' %>
33
- <% end %>
32
+ <% form_for(@user) do |f| %>
33
+ <%= f.datepicker 'birthday' %>
34
+ <%= f.submit 'Create' %>
35
+ <% end %>
36
+
37
+ Nested attributes are permitted as well:
38
+
39
+ <% form_for(@user) do |f| %>
40
+ <% f.fields_for(@nested) do |f2| %>
41
+ <%= f2.datepicker 'birthday' %>
42
+ <% end %>
43
+ <%= f.submit 'Create' %>
44
+ <% end %>
45
+
46
+ You can pass options as it would be a normal text_field, plus all the datepicker options available (http://jqueryui.com/demos/datepicker/#options)
47
+
48
+ <%= datepicker_input(:foo, :att1, :minDate => -20, :maxDate => "+1M +10D", :tabindex => 70) %>
49
+
50
+
51
+ == Support
34
52
 
53
+ Open an issue in https://github.com/albertopq/jquery_datepicker if you need further support or want to report a bug
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rake'
3
3
  require 'echoe'
4
4
  require 'rspec/core/rake_task'
5
5
 
6
- Echoe.new('jquery_datepicker', '0.3.1') do |p|
6
+ Echoe.new('jquery_datepicker', '0.3.2') do |p|
7
7
  p.description = "View helper that allows to select dates from a calendar (using jQuery Ui plugin)"
8
8
  p.url = "http://github.com/albertopq/jquery_datepicker"
9
9
  p.author = "Alberto Pastor"
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "jquery_datepicker"
5
- s.version = "0.3.1"
5
+ s.version = "0.3.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Alberto Pastor"]
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.description = "View helper that allows to select dates from a calendar (using jQuery Ui plugin)"
11
11
  s.email = "albert.pastor@gmail.com"
12
12
  s.extra_rdoc_files = ["README.rdoc", "lib/app/helpers/datepicker_helper.rb", "lib/app/helpers/form_helper.rb", "lib/jquery_datepicker.rb"]
13
- s.files = ["README.rdoc", "Rakefile", "init.rb", "jquery_datepicker.gemspec", "lib/app/helpers/datepicker_helper.rb", "lib/app/helpers/form_helper.rb", "lib/jquery_datepicker.rb", "Manifest"]
13
+ s.files = ["README.rdoc", "Rakefile", "init.rb", "jquery_datepicker.gemspec", "lib/app/helpers/datepicker_helper.rb", "lib/app/helpers/form_helper.rb", "lib/jquery_datepicker.rb"]
14
14
  s.homepage = "http://github.com/albertopq/jquery_datepicker"
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Jquery_datepicker", "--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
@@ -1,3 +1,4 @@
1
+ require 'date'
1
2
 
2
3
  module JqueryDatepicker
3
4
  module FormHelper
@@ -7,7 +8,8 @@ module JqueryDatepicker
7
8
  # Mehtod that generates datepicker input field inside a form
8
9
  def datepicker(object_name, method, options = {})
9
10
  input_tag = JqueryDatepicker::InstanceTag.new(object_name, method, self, options.delete(:object))
10
- dp_options, tf_options = input_tag.split_options(options);
11
+ dp_options, tf_options = input_tag.split_options(options)
12
+ tf_options[:value] = input_tag.format_date(tf_options[:value], String.new(dp_options[:dateFormat])) if tf_options.has_key?(:value) && dp_options.has_key?(:dateFormat)
11
13
  html = input_tag.to_input_field_tag("text", tf_options)
12
14
  html += javascript_tag("jQuery(document).ready(function(){$('##{input_tag.get_name_and_id["id"]}').datepicker(#{dp_options.to_json})});")
13
15
  html.html_safe
@@ -25,6 +27,8 @@ end
25
27
 
26
28
  class JqueryDatepicker::InstanceTag < ActionView::Helpers::InstanceTag
27
29
 
30
+ FORMAT_REPLACEMENTES = { "yy" => "%Y", "mm" => "%m", "dd" => "%d", "d" => "%-d", "m" => "%-m", "y" => "%y"}
31
+
28
32
  # Extending ActionView::Helpers::InstanceTag module to make Rails build the name and id
29
33
  # Just returns the options before generate the HTML in order to use the same id and name (see to_input_field_tag mehtod)
30
34
 
@@ -41,5 +45,18 @@ class JqueryDatepicker::InstanceTag < ActionView::Helpers::InstanceTag
41
45
  tf_options = options.slice!(*available_datepicker_options)
42
46
  return options, tf_options
43
47
  end
48
+
49
+ def format_date(tb_formatted, format)
50
+ new_format = translate_format(format)
51
+ Date.parse(tb_formatted).strftime(new_format)
52
+ end
53
+
54
+ # Method that translates the datepicker date formats, defined in (http://docs.jquery.com/UI/Datepicker/formatDate)
55
+ # to the ruby standard format (http://www.ruby-doc.org/core-1.9.3/Time.html#method-i-strftime).
56
+ # This gem is not going to support all the options, just the most used.
57
+
58
+ def translate_format(format)
59
+ format.gsub!(/#{FORMAT_REPLACEMENTES.keys.join("|")}/) { |match| FORMAT_REPLACEMENTES[match] }
60
+ end
44
61
 
45
62
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jquery_datepicker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -29,7 +29,6 @@ files:
29
29
  - lib/app/helpers/datepicker_helper.rb
30
30
  - lib/app/helpers/form_helper.rb
31
31
  - lib/jquery_datepicker.rb
32
- - Manifest
33
32
  homepage: http://github.com/albertopq/jquery_datepicker
34
33
  licenses: []
35
34
  post_install_message:
data/Manifest DELETED
@@ -1,8 +0,0 @@
1
- README.rdoc
2
- Rakefile
3
- init.rb
4
- jquery_datepicker.gemspec
5
- lib/app/helpers/datepicker_helper.rb
6
- lib/app/helpers/form_helper.rb
7
- lib/jquery_datepicker.rb
8
- Manifest