chronic_ping 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 00a341b18f12e7118122ac1e44ee5a2a93a84c62
4
- data.tar.gz: c6aa15b0b79dd9b2e0ae638a0bb4949f8b1efbd6
3
+ metadata.gz: 143cbe0c68e871c8f47a827eef09c1d4c77e044e
4
+ data.tar.gz: 13f06faa30da3f82e328b165156b0269987bdc1e
5
5
  SHA512:
6
- metadata.gz: 7ef0447257242e32b04c81ce54d54549d156bba3acb67c3961309fccd6fc8edbffa9ded443739aec11a0afb513a2195637e0ba5afdd900833d798329ace4c4c5
7
- data.tar.gz: 8dd3dddf7365a1e58401c468db38578d2b28577c314e08c333ffcdcd2d34ddd64d4b93e04bcdfbca47fb12ddfefe2a2b8d377893a7038ed978ec95aa04b4db49
6
+ metadata.gz: 412fe5f9a5b68fbdbdbf1d689191eeab44671d3a9590eb7ef37eaa52ea99c86dd9865affb6924ee65e9ba4d63bd5c1b2e9d8e3d02b17e532b4964b9b661b191d
7
+ data.tar.gz: 0e1778b46e198f25d0f42c0016eb392d6c1c6398342ea89c87b66a2289c1aee080e20be2d5aa0b41e00ef9a78a489190477ae3133e91f07008413fe3b87b9403
data/README.markdown CHANGED
@@ -15,16 +15,16 @@ Requirements
15
15
  Usage
16
16
  -----
17
17
  In your `Gemfile`
18
-
18
+
19
19
  gem 'chronic_ping'
20
20
 
21
21
  In your `assets/javascript/application.js`
22
-
22
+
23
23
  //= require chronic_ping
24
24
 
25
25
  In your form
26
-
27
- = f.text_field :birthday, class: 'chronic_ping', value: @student.birth_date.to_s
26
+
27
+ = f.text_field :due_at, class: 'chronic_ping'
28
28
 
29
29
  Customize
30
30
  ---------
@@ -32,9 +32,22 @@ Customize
32
32
  The following values are already set by default, but if you want to customize them, create a file called `config/initializers/chronic_ping.rb` that should look something like this:
33
33
 
34
34
  ChronicPing.configure do |config|
35
- config.datetime_format = "%B %d, %Y at %I:%M%p"
35
+ config.format = {
36
+ default: '%B %d, %Y at %I:%M%p',
37
+ datetime: '%B %d, %Y at %I:%M%p',
38
+ date: '%B %d, %Y',
39
+ my_new_format: '...'
40
+ }
36
41
  end
37
42
 
43
+ To use a custom predefined format just specify it in a `data-format` attribute:
44
+
45
+ = f.text_field :born_on, class: 'chronic_ping', data: {format: 'date'}
46
+
47
+ Or you can put a format string directly into the `data-format` attribute:
48
+
49
+ = f.text_field :born_on, class: 'chronic_ping', data: {format: '%m/%d/%Y'}
50
+
38
51
  License
39
52
  -------
40
53
 
@@ -2,11 +2,11 @@
2
2
  // All this logic will automatically be available in application.js.
3
3
 
4
4
  $('.chronic_ping').focusout(function() {
5
- var input_field = this;
5
+ input_field = this
6
6
  $.ajax({
7
7
  type: "POST",
8
8
  url: "<%= ENV['RAILS_RELATIVE_URL_ROOT'] %>/chronic_ping/parse",
9
- data: { q: this.value },
9
+ data: { q: this.value, f: $(this).data('format') },
10
10
  dataType: "json"
11
11
  }).done(function( msg ) {
12
12
  input_field.value = msg.response;
@@ -2,7 +2,9 @@ class ChronicPingController < ActionController::Base
2
2
  def parse
3
3
  unless params[:q].blank?
4
4
  begin
5
- response = Chronic.parse(params[:q]).strftime(ChronicPing.config.datetime_format)
5
+ format = ChronicPing.config.formats[params[:f] || :default] || params[:f]
6
+ response = Chronic.parse(params[:q]).strftime(format)
7
+
6
8
  render :json => { status: :success, response: response }
7
9
  rescue
8
10
  render :json => { status: :error, response: "" }
@@ -1,9 +1,21 @@
1
1
  module ChronicPing
2
2
  class Configuration
3
- attr_accessor :datetime_format
3
+ attr_accessor :formats
4
4
 
5
5
  def initialize
6
- @datetime_format = '%B %d, %Y at %I:%M%p'
6
+ @formats = {
7
+ default: '%B %d, %Y at %I:%M%p',
8
+ datetime: '%B %d, %Y at %I:%M%p',
9
+ date: '%B %d, %Y'
10
+ }
11
+ end
12
+
13
+ def formats
14
+ @formats.with_indifferent_access
15
+ end
16
+
17
+ def datetime_format=(format)
18
+ warn "[DEPRECATION] `ChronicPing.config.datetime_format=` is deprecated. Use ChronicPing.config.formats= instead."
7
19
  end
8
20
 
9
21
  def relative_root_url=(relative_url_root)
@@ -1,3 +1,3 @@
1
1
  module ChronicPing
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chronic_ping
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Hall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-22 00:00:00.000000000 Z
11
+ date: 2013-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails