jquery_datepicker 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +1 -1
- data/Rakefile +5 -3
- data/jquery_datepicker.gemspec +3 -3
- data/lib/app/helpers/datepicker_helper.rb +11 -7
- data/lib/app/helpers/form_helper.rb +41 -8
- data/lib/jquery_datepicker.rb +10 -4
- metadata +3 -3
data/Manifest
CHANGED
data/Rakefile
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
|
+
require 'rspec/core/rake_task'
|
4
5
|
|
5
|
-
Echoe.new('jquery_datepicker', '0.
|
6
|
+
Echoe.new('jquery_datepicker', '0.2.0') do |p|
|
6
7
|
p.description = "View helper that allows to select dates from a calendar (using jQuery Ui plugin)"
|
7
8
|
p.url = "http://github.com/albertopq/jquery_datepicker"
|
8
9
|
p.author = "Alberto Pastor"
|
9
10
|
p.email = "albert.pastor@gmail.com"
|
10
|
-
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
p.ignore_pattern = ["tmp/*", "script/*", "spec/*"]
|
11
12
|
p.development_dependencies = []
|
12
13
|
end
|
13
14
|
|
14
|
-
|
15
|
+
RSpec::Core::RakeTask.new(:spec)
|
16
|
+
task :default => :spec
|
data/jquery_datepicker.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "jquery_datepicker"
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.2.0"
|
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"]
|
9
|
-
s.date = "2011-
|
9
|
+
s.date = "2011-11-05"
|
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 = ["
|
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"]
|
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,10 +1,14 @@
|
|
1
|
-
|
1
|
+
require 'app/helpers/form_helper'
|
2
|
+
|
3
|
+
module JqueryDatepicker
|
4
|
+
module DatepickerHelper
|
5
|
+
|
6
|
+
include JqueryDatepicker::FormHelper
|
7
|
+
|
8
|
+
# Helper method that creates a datepicker input field
|
9
|
+
def datepicker_input(object_name, method, options = {})
|
10
|
+
datepicker(object_name, method, options)
|
11
|
+
end
|
2
12
|
|
3
|
-
# Helper method that creates a datepicker input field
|
4
|
-
def datepicker_input(model, att)
|
5
|
-
html = text_field(model,att)
|
6
|
-
html += javascript_tag 'jQuery(document).ready(function(){$("#'+model.to_s+'_'+att.to_s+'").datepicker()});'
|
7
|
-
return html
|
8
13
|
end
|
9
|
-
|
10
14
|
end
|
@@ -1,11 +1,44 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
|
2
|
+
module JqueryDatepicker
|
3
|
+
module FormHelper
|
4
|
+
|
5
|
+
include ActionView::Helpers::JavaScriptHelper
|
6
|
+
|
7
|
+
# Mehtod that generates datepicker input field inside a form
|
8
|
+
def datepicker(object_name, method, options = {})
|
9
|
+
input_tag = JqueryDatepicker::InstanceTag.new(object_name, method, self, options.delete(:object))
|
10
|
+
new_options = input_tag.get_to_input_field_tag_options("text", options)
|
11
|
+
html = input_tag.tag("input", new_options)
|
12
|
+
html += javascript_tag("jQuery(document).ready(function(){$('##{new_options["id"]}').datepicker()});")
|
13
|
+
html.html_safe
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module JqueryDatepicker::FormBuilder
|
20
|
+
def datepicker(method, options = {})
|
21
|
+
@template.datepicker(@object_name, method, objectify_options(options))
|
9
22
|
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class JqueryDatepicker::InstanceTag < ActionView::Helpers::InstanceTag
|
26
|
+
|
27
|
+
# Extending ActionView::Helpers::InstanceTag module to make Rails build the name and id
|
28
|
+
# Just returns the options before generate the HTML in order to use the same id and name (see to_input_field_tag mehtod)
|
10
29
|
|
30
|
+
def get_to_input_field_tag_options(field_type, options = {})
|
31
|
+
options = options.stringify_keys
|
32
|
+
options["size"] = options["maxlength"] || DEFAULT_FIELD_OPTIONS["size"] unless options.key?("size")
|
33
|
+
options = DEFAULT_FIELD_OPTIONS.merge(options)
|
34
|
+
if field_type == "hidden"
|
35
|
+
options.delete("size")
|
36
|
+
end
|
37
|
+
options["type"] ||= field_type
|
38
|
+
options["value"] = options.fetch("value"){ value_before_type_cast(object) } unless field_type == "file"
|
39
|
+
options["value"] &&= html_escape(options["value"])
|
40
|
+
add_default_name_and_id(options)
|
41
|
+
options
|
42
|
+
end
|
43
|
+
|
11
44
|
end
|
data/lib/jquery_datepicker.rb
CHANGED
@@ -2,7 +2,13 @@
|
|
2
2
|
require "app/helpers/datepicker_helper.rb"
|
3
3
|
require "app/helpers/form_helper.rb"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
module JqueryDatepicker
|
6
|
+
class Railtie < Rails::Railtie
|
7
|
+
initializer "JqueryDatepicker" do
|
8
|
+
ActionController::Base.helper(JqueryDatepicker::DatepickerHelper)
|
9
|
+
ActionView::Helpers::FormHelper.send(:include, JqueryDatepicker::FormHelper)
|
10
|
+
ActionView::Base.send(:include, JqueryDatepicker::DatepickerHelper)
|
11
|
+
ActionView::Helpers::FormBuilder.send(:include,JqueryDatepicker::FormBuilder)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
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.
|
4
|
+
version: 0.2.0
|
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: 2011-
|
12
|
+
date: 2011-11-05 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: View helper that allows to select dates from a calendar (using jQuery
|
15
15
|
Ui plugin)
|
@@ -22,7 +22,6 @@ extra_rdoc_files:
|
|
22
22
|
- lib/app/helpers/form_helper.rb
|
23
23
|
- lib/jquery_datepicker.rb
|
24
24
|
files:
|
25
|
-
- Manifest
|
26
25
|
- README.rdoc
|
27
26
|
- Rakefile
|
28
27
|
- init.rb
|
@@ -30,6 +29,7 @@ files:
|
|
30
29
|
- lib/app/helpers/datepicker_helper.rb
|
31
30
|
- lib/app/helpers/form_helper.rb
|
32
31
|
- lib/jquery_datepicker.rb
|
32
|
+
- Manifest
|
33
33
|
homepage: http://github.com/albertopq/jquery_datepicker
|
34
34
|
licenses: []
|
35
35
|
post_install_message:
|