bjornblomqvist-input_chronic 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Erik Hansson,Bjorn Blomqvist
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,23 @@
1
+ = input_chronic
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
+ == Usage
9
+
10
+ Include "input_chronic" in your middleware stack. In Rails, this
11
+ is done in environment.rb
12
+
13
+ config.gem 'bjornblomqvist-input_chronic', :lib => 'input_chronic', :source => 'http://gems.github.com'
14
+ config.middleware.use "input_chronic"
15
+
16
+ This will catch requests to /gems.github.com/bjornblomqvist/input_chronic. Use GET requests and
17
+ provide a parameter 'date' or 'datetime'. The value will be
18
+ parsed by Chronic and returned formatted as 2009-01-01 or
19
+ 2009-01-01 12:45, depending on the parameter name.
20
+
21
+ == Copyright
22
+
23
+ Copyright (c) 2009 Erik Hansson, Bjorn Blomqvist. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "input_chronic"
8
+ gem.summary = "A simple Rack-middleware for parsing dates with Chronic"
9
+ gem.description = File.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
10
+ gem.email = "darwin.git@marianna.se"
11
+ gem.homepage = "http://github.com/bjornblomqvist/input_chronic"
12
+ gem.authors = ["Darwin"]
13
+ gem.add_development_dependency "rspec"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'spec/rake/spectask'
21
+ Spec::Rake::SpecTask.new(:spec) do |spec|
22
+ spec.libs << 'lib' << 'spec'
23
+ spec.spec_files = FileList['spec/**/*_spec.rb']
24
+ end
25
+
26
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
27
+ spec.libs << 'lib' << 'spec'
28
+ spec.pattern = 'spec/**/*_spec.rb'
29
+ spec.rcov = true
30
+ end
31
+
32
+ task :spec => :check_dependencies
33
+
34
+ task :default => :spec
35
+
36
+ require 'rake/rdoctask'
37
+ Rake::RDocTask.new do |rdoc|
38
+ if File.exist?('VERSION')
39
+ version = File.read('VERSION')
40
+ else
41
+ version = ""
42
+ end
43
+
44
+ rdoc.rdoc_dir = 'rdoc'
45
+ rdoc.title = "input_chronic #{version}"
46
+ rdoc.rdoc_files.include('README*')
47
+ rdoc.rdoc_files.include('lib/**/*.rb')
48
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,54 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{input_chronic}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Darwin"]
12
+ s.date = %q{2009-09-04}
13
+ s.description = %q{= input_chronic 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 "input_chronic" in your middleware stack. In Rails, this is done in environment.rb config.gem 'bjornblomqvist-input_chronic', :lib => 'input_chronic', :source => 'http://gems.github.com' config.middleware.use "input_chronic" This will catch requests to /gems.github.com/bjornblomqvist/input_chronic. 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. == Copyright Copyright (c) 2009 Erik Hansson, Bjorn Blomqvist. See LICENSE for details.}
14
+ s.email = %q{darwin.git@marianna.se}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "input_chronic.gemspec",
27
+ "lib/input_chronic.rb",
28
+ "spec/input_chronic_spec.rb",
29
+ "spec/spec_helper.rb"
30
+ ]
31
+ s.has_rdoc = true
32
+ s.homepage = %q{http://github.com/bjornblomqvist/input_chronic}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.1}
36
+ s.summary = %q{A simple Rack-middleware for parsing dates with Chronic}
37
+ s.test_files = [
38
+ "spec/input_chronic_spec.rb",
39
+ "spec/spec_helper.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 2
45
+
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ s.add_development_dependency(%q<rspec>, [">= 0"])
48
+ else
49
+ s.add_dependency(%q<rspec>, [">= 0"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<rspec>, [">= 0"])
53
+ end
54
+ end
@@ -0,0 +1,98 @@
1
+ require 'chronic'
2
+
3
+ class InputChronic
4
+
5
+ module VERSION #:nodoc:
6
+ MAJOR = 0
7
+ MINOR = 0
8
+ TINY = 1
9
+
10
+ STRING = [MAJOR, MINOR, TINY].join('.')
11
+ end
12
+
13
+
14
+ def initialize(app)
15
+ @app = app
16
+
17
+ @javascript = %Q{
18
+
19
+ if (jQuery) {
20
+ $(document).ready(function() {
21
+
22
+ $('input.date').live("change", function() {
23
+ input = this;
24
+ $.get('/gems.github.com/bjornblomqvist/input_chronic/parse', { date: this.value }, function(result) {
25
+ $(input).removeClass("chronic_error")
26
+ if(result)
27
+ input.value = result;
28
+ else
29
+ $(input).addClass("chronic_error");
30
+ });
31
+ });
32
+
33
+ $('input.datetime').live("change", function() {
34
+ input = this;
35
+ $.get('/gems.github.com/bjornblomqvist/input_chronic/parse', { datetime: this.value }, function(result) {
36
+ $(input).removeClass("chronic_error")
37
+ if(result)
38
+ input.value = result;
39
+ else
40
+ $(input).addClass("chronic_error");
41
+ });
42
+ });
43
+
44
+ });
45
+ } else {
46
+ document.observe("dom:loaded", function() {
47
+ function checkDate(input, params) {
48
+ new Ajax.Request('/gems.github.com/bjornblomqvist/input_chronic/parse', {
49
+ parameters: params,
50
+ method: 'GET',
51
+ onSuccess: function(response) {
52
+ input.removeClassName("chronic_error")
53
+ if(result)
54
+ input.value = response.responseText;
55
+ else
56
+ input.addClassName("chronic_error");
57
+ }
58
+ });
59
+ }
60
+
61
+ $$("input.date").each(function(input) {
62
+ input.observe('change', function() {
63
+ checkDate(input, { date: this.value });
64
+ });
65
+ });
66
+
67
+ $$("input.datetime").each(function(input) {
68
+ input.observe('change', function() {
69
+ checkDate(input, { datetime: this.value });
70
+ });
71
+ });
72
+ });
73
+ }
74
+
75
+ }
76
+ end
77
+
78
+ def call(env)
79
+ if env["PATH_INFO"].index("/gems.github.com/bjornblomqvist/input_chronic/parse")
80
+ params = Rack::Utils.parse_query env["QUERY_STRING"]
81
+ [200, {"Content-Type" => "text/plain"}, [respond_to_params(params)]]
82
+ elsif env["PATH_INFO"].index("/javascripts/input_chronic.js")
83
+ [200, {"Content-Type" => "text/javascript"}, [@javascript]]
84
+ else
85
+ @app.call env
86
+ end
87
+ end
88
+
89
+
90
+ def respond_to_params(params)
91
+ params['date'] ? parse_date(params['date'], '%Y-%m-%d') : parse_date(params['datetime'], '%Y-%m-%d %H:%M')
92
+ end
93
+
94
+ def parse_date(input, format)
95
+ t = Chronic.parse(input)
96
+ (t ? t.strftime(format) : '')
97
+ end
98
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "InputChronic" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'input_chronic'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bjornblomqvist-input_chronic
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Darwin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-04 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: = input_chronic 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 "input_chronic" in your middleware stack. In Rails, this is done in environment.rb config.gem 'bjornblomqvist-input_chronic', :lib => 'input_chronic', :source => 'http://gems.github.com' config.middleware.use "input_chronic" This will catch requests to /gems.github.com/bjornblomqvist/input_chronic. 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. == Copyright Copyright (c) 2009 Erik Hansson, Bjorn Blomqvist. See LICENSE for details.
26
+ email: darwin.git@marianna.se
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - input_chronic.gemspec
42
+ - lib/input_chronic.rb
43
+ - spec/input_chronic_spec.rb
44
+ - spec/spec_helper.rb
45
+ has_rdoc: true
46
+ homepage: http://github.com/bjornblomqvist/input_chronic
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --charset=UTF-8
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.2.0
68
+ signing_key:
69
+ specification_version: 2
70
+ summary: A simple Rack-middleware for parsing dates with Chronic
71
+ test_files:
72
+ - spec/input_chronic_spec.rb
73
+ - spec/spec_helper.rb