effective_form_inputs 0.1.2 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dfb139ee0ac3bdd08159e9eb79359d31bad07c27
4
- data.tar.gz: 38c3ea428c5d9c184f8a7bc143705b3b6eb5e581
3
+ metadata.gz: 11b76163fed4145fb5cd13cb4ada4c849d79b827
4
+ data.tar.gz: eb0ec003718c67485121f6552104012f9aee6893
5
5
  SHA512:
6
- metadata.gz: fb0cb297acd58a2d45024bb5906cec6825261bbaefdc6aea4b3030c9c84617db288f51c8d408d8ec9de2818f1ff4492c108e8725add0d6e4aea2f457a9ef2a65
7
- data.tar.gz: d9254902a855f0abf74936cdbbd26338386b0216f748b42ef1537b706b15e261437b32cbb694eb65205c2fa8449ded1e071c29781a829b107f98008cf6149d3e
6
+ metadata.gz: 177afe359f6345cbeaeaa18bcdf89ff0ba29c00b226cf6e39c53c934e7d773c177ba7895e28bd95bead643ec0e751ca7c54f68a178b52b3c3f4b1e87b68a9896
7
+ data.tar.gz: d32d328529515106b360f3986aa0474d2689e10498dff171c9e3a319e1dfe3d7a6ee210eeb7680c9baa6c778eff5b04635b251432001821ef06205f5ce5e6f6a
data/README.md CHANGED
@@ -84,15 +84,64 @@ and as a SimpleForm input:
84
84
  = f.input :updated_at, :as => :effective_date_time_picker
85
85
  ```
86
86
 
87
- ### Passing Options to JavaScript
87
+ ### Options
88
88
 
89
- Any options passed to the form input will be used to initialize the Bootstrap3 DateTimePicker
89
+ The default options used to initialize this form input are as follows:
90
90
 
91
- For example (and this works just the same with the SimpleForm input):
91
+ ```ruby
92
+ :format => 'YYYY-MM-DD h:mm A', :sideBySide => true
93
+ ```
94
+
95
+ For a full list of options, please refer to:
96
+
97
+ http://eonasdan.github.io/bootstrap-datetimepicker/Options/
98
+
99
+
100
+ ## Bootstrap3 DatePicker
101
+
102
+ This custom form input is based on the following awesome project:
103
+
104
+ Bootstrap 3 Datepicker (https://github.com/Eonasdan/bootstrap-datetimepicker)
105
+
106
+
107
+ ### Installation
108
+
109
+ If you've already installed the 'All Form Inputs' assets (see above), there are no additional installation steps.
110
+
111
+ To install this form input individually, add the following to your application.js:
112
+
113
+ ```ruby
114
+ //= require effective_date_picker/input
115
+ ```
116
+
117
+ and add the following to your application.css:
118
+
119
+ ```ruby
120
+ *= require effective_date_picker/input
121
+ ```
122
+
123
+ ### Usage
124
+
125
+ As a Rails Form Helper input:
92
126
 
93
127
  ```ruby
94
128
  = form_for @user do |f|
95
- = f.effective_date_time_picker :updated_at, :format => 'YYYY-MM-DD', :showTodayButton => true
129
+ = f.effective_date_picker :started_on
130
+ ```
131
+
132
+ and as a SimpleForm input:
133
+
134
+ ```ruby
135
+ = simple_form_for @user do |f|
136
+ = f.input :started_on, :as => :effective_date_picker
137
+ ```
138
+
139
+ ### Options
140
+
141
+ The default options used to initialize this form input are as follows:
142
+
143
+ ```ruby
144
+ :format => 'YYYY-MM-DD'
96
145
  ```
97
146
 
98
147
  For a full list of options, please refer to:
@@ -100,6 +149,34 @@ For a full list of options, please refer to:
100
149
  http://eonasdan.github.io/bootstrap-datetimepicker/Options/
101
150
 
102
151
 
152
+ ## Passing Options to JavaScript
153
+
154
+ All appropriate options passed to any effective_form_input will be used to initialize the Javascript library
155
+
156
+ For example:
157
+
158
+ ```ruby
159
+ = form_for @user do |f|
160
+ = f.effective_date_time_picker :updated_at, :format => 'dddd, MMMM Do YYYY', :showTodayButton => true
161
+ ```
162
+
163
+ or
164
+
165
+ ```ruby
166
+ = simple_form_for @user do |f|
167
+ = f.input :updated_at, :as => :effective_date_time_picker, :format => 'dddd, MMMM Do YYYY', :showTodayButton => true
168
+ ```
169
+
170
+ will result in the following call to the Javascript library:
171
+
172
+ ```coffee
173
+ $('input.effective_date_time_picker').datetimepicker
174
+ format: 'dddd, MMMM Do YYYY',
175
+ showTodayButton: true
176
+ ```
177
+
178
+ Any option not recognized as a Rails Form Helper or SimpleForm option will be passed in this way to Javascript.
179
+
103
180
  ## License
104
181
 
105
182
  MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
@@ -0,0 +1,12 @@
1
+ # http://eonasdan.github.io/bootstrap-datetimepicker/Options/
2
+
3
+ initialize = ->
4
+ $('input.effective_date_picker:not(.initialized)').each (i, element) ->
5
+ element = $(element)
6
+ options = element.data('input-js-options') || {}
7
+
8
+ element.addClass('initialized').datetimepicker(options)
9
+
10
+ $ -> initialize()
11
+ $(document).on 'page:change', -> initialize()
12
+ $(document).on 'cocoon:after-insert', -> initialize()
@@ -0,0 +1,3 @@
1
+ //= require ../effective_date_time_picker/moment
2
+ //= require ../effective_date_time_picker/bootstrap-datetimepicker
3
+ //= require ./initialize
@@ -1 +1,2 @@
1
1
  //= require ./effective_date_time_picker/input
2
+ //= require ./effective_date_picker/input
@@ -0,0 +1 @@
1
+ @import '../effective_date_time_picker/bootstrap-datetimepicker';
@@ -1,7 +1,11 @@
1
- module EffectiveFormInputs
2
- module FormInputs
1
+ module Effective
2
+ module FormBuilderInputs
3
3
  def effective_date_time_picker(method, options = {})
4
- Inputs::EffectiveDateTimePicker::Field.new(@object, @object_name, @template, method, merged_input_js_options(options)).to_html
4
+ Inputs::EffectiveDateTimePicker::Input.new(@object, @object_name, @template, method, merged_input_js_options(options)).to_html
5
+ end
6
+
7
+ def effective_date_picker(method, options = {})
8
+ Inputs::EffectiveDatePicker::Input.new(@object, @object_name, @template, method, merged_input_js_options(options)).to_html
5
9
  end
6
10
 
7
11
  private
@@ -1,5 +1,5 @@
1
1
  module Effective
2
- class FormInputField
2
+ class FormInput
3
3
 
4
4
  def initialize(object, object_name, template, method, opts)
5
5
  @object = object
@@ -0,0 +1,34 @@
1
+ module Inputs
2
+ module EffectiveDatePicker
3
+ class Input < Effective::FormInput
4
+ delegate :content_tag, :text_field_tag, :to => :@template
5
+
6
+ def default_input_js_options
7
+ {:format => 'YYYY-MM-DD'}
8
+ end
9
+
10
+ def default_input_classes
11
+ [:effective_date_picker, :date]
12
+ end
13
+
14
+ def to_html
15
+ content_tag(:div, :class => 'input-group') do
16
+ content_tag(:span, :class => 'input-group-addon') do
17
+ content_tag(:i, '', :class => 'glyphicon glyphicon-calendar').html_safe
18
+ end +
19
+ text_field_tag(field_name, value, options)
20
+ end
21
+ end
22
+
23
+ def options
24
+ super do |options|
25
+ unless options['data-input-js-options'][:format].present?
26
+ options[:pattern] = '\d{4}-\d{2}-\d{2}'
27
+ end
28
+ end
29
+ end
30
+
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,15 @@
1
+ # = simple_form_for @thing do |f|
2
+ # = f.input :updated_at, :as => :effective_date_picker
3
+
4
+ if defined?(SimpleForm)
5
+
6
+ class EffectiveDatePickerInput < SimpleForm::Inputs::StringInput
7
+ def input(wrapper_options = nil)
8
+ options = merge_wrapper_options(input_html_options, wrapper_options) || {}
9
+ options['data-input-js-options'] = input_options.reject { |k, _| EffectiveFormInputs::REJECTED_INPUT_JS_OPTIONS.include?(k) }
10
+
11
+ Inputs::EffectiveDatePicker::Input.new(object, object_name, template, attribute_name, options).to_html
12
+ end
13
+ end
14
+
15
+ end
@@ -1,6 +1,6 @@
1
1
  module Inputs
2
2
  module EffectiveDateTimePicker
3
- class Field < Effective::FormInputField
3
+ class Input < Effective::FormInput
4
4
  delegate :content_tag, :text_field_tag, :to => :@template
5
5
 
6
6
  def default_input_js_options
@@ -0,0 +1,15 @@
1
+ # = simple_form_for @thing do |f|
2
+ # = f.input :updated_at, :as => :effective_date_time_picker
3
+
4
+ if defined?(SimpleForm)
5
+
6
+ class EffectiveDateTimePickerInput < SimpleForm::Inputs::StringInput
7
+ def input(wrapper_options = nil)
8
+ options = merge_wrapper_options(input_html_options, wrapper_options) || {}
9
+ options['data-input-js-options'] = input_options.reject { |k, _| EffectiveFormInputs::REJECTED_INPUT_JS_OPTIONS.include?(k) }
10
+
11
+ Inputs::EffectiveDateTimePicker::Input.new(object, object_name, template, attribute_name, options).to_html
12
+ end
13
+ end
14
+
15
+ end
@@ -2,3 +2,4 @@
2
2
 
3
3
  = form_for Effective::StyleGuide.new(), :url => '/' do |f|
4
4
  = f.effective_date_time_picker :updated_at
5
+ = f.effective_date_picker :updated_at
@@ -1,4 +1,3 @@
1
- require "effective_form_inputs/form_inputs"
2
1
  require "effective_form_inputs/engine"
3
2
  require "effective_form_inputs/version"
4
3
 
@@ -6,15 +6,7 @@ module EffectiveFormInputs
6
6
 
7
7
  initializer 'effective_orders.action_view' do |app|
8
8
  ActiveSupport.on_load :action_view do
9
- ActionView::Helpers::FormBuilder.send(:include, EffectiveFormInputs::FormInputs)
10
-
11
- # Going to have to add each custom namespace to SimpleForm
12
- if defined?(SimpleForm)
13
- SimpleForm.setup do |config|
14
- config.custom_inputs_namespaces << 'EffectiveDateTimePicker'
15
- end
16
- end
17
-
9
+ ActionView::Helpers::FormBuilder.send(:include, Effective::FormBuilderInputs)
18
10
  end
19
11
  end
20
12
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveFormInputs
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_form_inputs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-29 00:00:00.000000000 Z
11
+ date: 2015-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -34,21 +34,26 @@ files:
34
34
  - MIT-LICENSE
35
35
  - README.md
36
36
  - Rakefile
37
+ - app/assets/javascripts/effective_date_picker/initialize.js.coffee
38
+ - app/assets/javascripts/effective_date_picker/input.js
37
39
  - app/assets/javascripts/effective_date_time_picker/bootstrap-datetimepicker.js
38
40
  - app/assets/javascripts/effective_date_time_picker/initialize.js.coffee
39
41
  - app/assets/javascripts/effective_date_time_picker/input.js
40
42
  - app/assets/javascripts/effective_date_time_picker/moment.js
41
43
  - app/assets/javascripts/effective_form_inputs.js
44
+ - app/assets/stylesheets/effective_date_picker/input.scss
42
45
  - app/assets/stylesheets/effective_date_time_picker/bootstrap-datetimepicker.scss
43
46
  - app/assets/stylesheets/effective_date_time_picker/input.scss
44
47
  - app/assets/stylesheets/effective_form_inputs.scss
45
- - app/models/effective/form_input_field.rb
46
- - app/models/inputs/effective_date_time_picker/effective_date_time_picker_input.rb
47
- - app/models/inputs/effective_date_time_picker/field.rb
48
+ - app/models/effective/form_builder_inputs.rb
49
+ - app/models/effective/form_input.rb
50
+ - app/models/inputs/effective_date_picker/input.rb
51
+ - app/models/inputs/effective_date_picker_input.rb
52
+ - app/models/inputs/effective_date_time_picker/input.rb
53
+ - app/models/inputs/effective_date_time_picker_input.rb
48
54
  - app/views/effective/style_guide/_form_default.html.haml
49
55
  - lib/effective_form_inputs.rb
50
56
  - lib/effective_form_inputs/engine.rb
51
- - lib/effective_form_inputs/form_inputs.rb
52
57
  - lib/effective_form_inputs/version.rb
53
58
  homepage: https://github.com/code-and-effect/effective_form_inputs
54
59
  licenses:
@@ -1,18 +0,0 @@
1
- # In simple_form:
2
- #
3
- # = f.input :updated_at, :as => :effective_date_time_picker
4
-
5
- if defined?(SimpleForm)
6
-
7
- module EffectiveDateTimePicker
8
- class EffectiveDateTimePickerInput < SimpleForm::Inputs::StringInput
9
- def input(wrapper_options = nil)
10
- options = merge_wrapper_options(input_html_options, wrapper_options) || {}
11
- options['data-input-js-options'] = input_options.reject { |k, _| EffectiveFormInputs::REJECTED_INPUT_JS_OPTIONS.include?(k) }
12
-
13
- Inputs::EffectiveDateTimePicker::Field.new(object, object_name, template, attribute_name, options).to_html
14
- end
15
- end
16
- end
17
-
18
- end