bjeanes-livedate 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Bodaniel Jeanes
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,35 @@
1
+ = Livedate
2
+
3
+ A simple Rack middleware that parses a dates using Chronic, and
4
+ returns the result in a standardized manner. The idea is to use
5
+ this to verify the input in date input fields using AJAX, to
6
+ provide immediate feedback to the user.
7
+
8
+
9
+ == Usage
10
+
11
+ Include Livedate in your middleware stack. In Rails, this
12
+ is done in environment.rb
13
+
14
+ config.gem 'livedate'
15
+ config.middleware.use "Livedate"
16
+
17
+ This will catch requests to /parsedate. Use GET requests and
18
+ provide a parameter 'date' or 'datetime'. The value will be
19
+ parsed by Chronic and returned formatted as 2009-01-01 or
20
+ 2009-01-01 12:45, depending on the parameter name.
21
+
22
+
23
+ == Scripts
24
+
25
+ There are two generators available to get simple javascripts
26
+ that use livedate. Both will replace the contents on input
27
+ elements with classes .date or .datetime on change with the
28
+ result from the Chronic parse.
29
+
30
+ script/generate livedate_jquery
31
+ script/generate livedate_prototype
32
+
33
+ Will put the appropriate version of the script in your
34
+ public/javascripts directory. Feel free to change these
35
+ if you need a different behavior.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,10 @@
1
+ class LivedateJqueryGenerator < Rails::Generator::Base
2
+
3
+ def manifest
4
+ record do |m|
5
+ m.directory "public/javascripts"
6
+ m.file "javascript/jquery.js", "public/javascripts/livedate.js"
7
+ end
8
+ end
9
+
10
+ end
@@ -0,0 +1,10 @@
1
+ class LivedatePrototypeGenerator < Rails::Generator::Base
2
+
3
+ def manifest
4
+ record do |m|
5
+ m.directory "public/javascripts"
6
+ m.file "javascript/prototype.js", "public/javascripts/livedate.js"
7
+ end
8
+ end
9
+
10
+ end
@@ -0,0 +1,15 @@
1
+ $(document).ready(function() {
2
+ $('input.date').live("change", function() {
3
+ input = this;
4
+ $.get('/parsedate', { date: this.value }, function(result) {
5
+ input.value = result;
6
+ });
7
+ });
8
+
9
+ $('input.datetime').live("change", function() {
10
+ input = this;
11
+ $.get('/parsedate', { datetime: this.value }, function(result) {
12
+ input.value = result;
13
+ });
14
+ });
15
+ });
@@ -0,0 +1,23 @@
1
+ document.observe("dom:loaded", function() {
2
+ function checkDate(input, params) {
3
+ new Ajax.Request('/parsedate', {
4
+ parameters: params,
5
+ method: 'GET',
6
+ onSuccess: function(response) {
7
+ input.value = response.responseText;
8
+ }
9
+ });
10
+ }
11
+
12
+ $$("input.date").each(function(input) {
13
+ input.observe('change', function() {
14
+ checkDate(input, { date: this.value });
15
+ });
16
+ });
17
+
18
+ $$("input.datetime").each(function(input) {
19
+ input.observe('change', function() {
20
+ checkDate(input, { datetime: this.value });
21
+ });
22
+ });
23
+ });
data/lib/livedate.rb ADDED
@@ -0,0 +1,29 @@
1
+ class Livedate
2
+
3
+ VERSION = File.read(File.dirname(__FILE__) + "/../VERSION").strip
4
+
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ if env["PATH_INFO"] =~ /^\/parsedate/
11
+ params = Rack::Utils.parse_query env["QUERY_STRING"]
12
+ [200, {"Content-Type" => "text/plain"}, [respond_to_params(params)]]
13
+ else
14
+ @app.call env
15
+ end
16
+ end
17
+
18
+
19
+ def respond_to_params(params)
20
+ params['date'] ? parse_date(params['date'], '%Y-%m-%d') : parse_date(params['datetime'], '%Y-%m-%d %H:%M')
21
+ end
22
+
23
+ def parse_date(input, format)
24
+ require 'chronic'
25
+
26
+ t = Chronic.parse(input)
27
+ (t ? t.strftime(format) : '')
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bjeanes-livedate
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Erik Hansson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-17 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: chronic
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.2.3
24
+ version:
25
+ description: = Livedate A simple Rack middleware that parses a dates using Chronic, and returns the result in a standardized manner. The idea is to use this to verify the input in date input fields using AJAX, to provide immediate feedback to the user. == Usage Include Livedate in your middleware stack. In Rails, this is done in environment.rb config.gem 'livedate' config.middleware.use "Livedate" This will catch requests to /parsedate. Use GET requests and provide a parameter 'date' or 'datetime'. The value will be parsed by Chronic and returned formatted as 2009-01-01 or 2009-01-01 12:45, depending on the parameter name. == Scripts There are two generators available to get simple javascripts that use livedate. Both will replace the contents on input elements with classes .date or .datetime on change with the result from the Chronic parse. script/generate livedate_jquery script/generate livedate_prototype Will put the appropriate version of the script in your public/javascripts directory. Feel free to change these if you need a different behavior.
26
+ email: erik@bits2life.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - README.rdoc
36
+ - VERSION
37
+ - generators/livedate_jquery_generator.rb
38
+ - generators/livedate_prototype_generator.rb
39
+ - generators/templates/javascript/jquery.js
40
+ - generators/templates/javascript/prototype.js
41
+ - lib/livedate.rb
42
+ - LICENSE
43
+ has_rdoc: false
44
+ homepage: http://www.erikhansson.com
45
+ licenses:
46
+ post_install_message:
47
+ rdoc_options:
48
+ - --charset=UTF-8
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "1.8"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements:
64
+ - chronic
65
+ rubyforge_project: livedate
66
+ rubygems_version: 1.3.5
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: A simple Rack-middleware for parsing dates with Chronic
70
+ test_files: []
71
+