simple_form_custom_inputs 0.0.2 → 0.0.3

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: 92c5fb23cce41109af5e9501367ca431e3da28e1
4
- data.tar.gz: 979d2579b862e722db590651e8f3511614bd3f93
3
+ metadata.gz: 12e746e0a14477d80aabed40e16f6f81d7cd03f5
4
+ data.tar.gz: 2a2d1cefe64ae5a20705201d3cee4544333c9985
5
5
  SHA512:
6
- metadata.gz: 1b85643e542e90a2a83fea5f086ca715cb0651f88e5283f209218cce152d4602b00ee894f45cf449947f6f6ccce98bd08a91325390e5320a0e4abfae882db9d2
7
- data.tar.gz: be054daae5b8a6c90fd9c1a44a794a5c546122d9c6692bc9f7857ae2ff19847353e5b51c818cb267a17e7b1cded5e1fd06b54f46f696edc7d0e4784530b1e463
6
+ metadata.gz: 3102a8593a2a29feb903e84f6e54e36e583134ad87fac143306d28728838cec66d6bfe4fe3507e418467adbd56130b02500261aedb087d5f257749a9c64207e8
7
+ data.tar.gz: 83952c6245ea7110028c639b3e588a5305ffcb61830dedf655900f1d598bd2def8a812de4e2e7f21921d9162f9b9ac8b0593a67ad85604d3b0a60ec9dc8b03fb
data/README.md CHANGED
@@ -6,8 +6,10 @@
6
6
 
7
7
  - [x] Switch/Toggle with Switchery
8
8
  - [x] Masked inputs
9
- - [ ] Datepicker
9
+ - [x] Datepicker
10
10
  - [ ] Datetimepicker
11
+ - [ ] Timepicker
12
+ - [ ] File
11
13
 
12
14
  ## Installation
13
15
 
@@ -16,10 +18,12 @@ Add the following gems to your application's Gemfile:
16
18
  ```ruby
17
19
  gem 'simple_form'
18
20
  gem 'simple_form_custom_inputs'
21
+ gem 'bootstrap-sass'
19
22
 
20
23
  source 'https://rails-assets.org' do
21
24
  gem 'rails-assets-switchery'
22
25
  gem 'rails-assets-jquery.maskedinput'
26
+ gem 'rails-assets-bootstrap-datepicker'
23
27
  end
24
28
  ```
25
29
 
@@ -38,6 +42,7 @@ In app/assets/javascripts/application.js, you should add as follows:
38
42
  //= require ...
39
43
  //= require switchery
40
44
  //= require jquery.maskedinput
45
+ //= require bootstrap-datepicker
41
46
  //= require simple_form_custom_inputs
42
47
  //= require ...
43
48
  ```
@@ -45,35 +50,45 @@ In app/assets/javascripts/application.js, you should add as follows:
45
50
  Application.scss
46
51
 
47
52
  ```scss
53
+ @import "bootstrap-sprockets";
54
+ @import "bootstrap";
48
55
  @import "switchery";
56
+ @import "bootstrap-datepicker";
49
57
  ```
50
58
 
51
59
  Basic Example:
52
60
 
53
61
  ```erb
54
- <%= simple_form_for :example do |f| %>
55
- ...
56
- <%= f.input :boolean, as: :switch %>
57
- ...
58
- <% end %>
59
62
 
60
63
  <%= simple_form_for :example do |f| %>
61
- ...
64
+ <%= f.input :boolean, as: :switch %>
65
+ <%= f.input :boolean, as: :switch, input_html: {data: {color: '#FF0', secondary_color: '#0F0', jack_color: '#FFF', jack_secondary_color: '#000', size: 'small'}} %>
62
66
  <%= f.input :phone, as: :masked, input_html: {data: {pattern: '(99) 99999-9999'}} %>
63
- ...
67
+ <%= f.input :time, as: :datepicker %>
68
+ <%= f.input :photo, as: :button_file, label: false, class: 'btn btn-info', input_html: {multiple: true, data: {multiple_caption: '{count} files selected'}} %>
64
69
  <% end %>
70
+
65
71
  ```
66
72
 
67
- Want some more customization on Switch?
73
+ ## I18n on datepicker
68
74
 
69
- ```erb
70
- <%= simple_form_for :example do |f| %>
71
- ...
72
- <%= f.input :boolean, as: :switch, input_html: {data: {color: '#FF0', secondary_color: '#0F0', jack_color: '#FFF', jack_secondary_color: '#000', size: 'small'}} %>
73
- ...
74
- <% end %>
75
+ You just need to set your locale to the desired language on application.rb, and import the locale on application.js
76
+
77
+ ```ruby
78
+ # application.rb
79
+ config.i18n.default_locale = 'pt-BR'
75
80
  ```
76
81
 
82
+ ```js
83
+ ...
84
+ //= require bootstrap-datepicker
85
+ //= require I18n/pt-BR
86
+ ...
87
+ ```
88
+ ## Help wanted
89
+
90
+ Please, help with I18n for datepicker!
91
+
77
92
  ## Sample projects
78
93
 
79
94
  For an example, take a look at the `example` folder in this repository.
data/example/Gemfile CHANGED
@@ -42,6 +42,7 @@ gem 'bootstrap-sass'
42
42
  source 'https://rails-assets.org' do
43
43
  gem 'rails-assets-switchery'
44
44
  gem 'rails-assets-jquery.maskedinput'
45
+ gem 'rails-assets-bootstrap-datepicker'
45
46
  end
46
47
 
47
48
  group :development, :test do
data/example/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- simple_form_custom_inputs (0.0.1)
4
+ simple_form_custom_inputs (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -114,6 +114,8 @@ GEM
114
114
  bundler (>= 1.3.0, < 2.0)
115
115
  railties (= 5.0.2)
116
116
  sprockets-rails (>= 2.0.0)
117
+ rails-assets-bootstrap-datepicker (1.6.4)
118
+ rails-assets-jquery (>= 1.7.1)
117
119
  rails-assets-fastclick (0.6.11)
118
120
  rails-assets-jquery (3.2.1)
119
121
  rails-assets-jquery.maskedinput (1.4.1)
@@ -193,6 +195,7 @@ DEPENDENCIES
193
195
  pry-rails
194
196
  puma (~> 3.0)
195
197
  rails (~> 5.0.2)
198
+ rails-assets-bootstrap-datepicker!
196
199
  rails-assets-jquery.maskedinput!
197
200
  rails-assets-switchery!
198
201
  sass-rails (~> 5.0)
@@ -16,5 +16,7 @@
16
16
  //= require turbolinks
17
17
  //= require switchery
18
18
  //= require jquery.maskedinput
19
+ //= require bootstrap-datepicker
20
+ //= require I18n/pt-BR
19
21
  //= require simple_form_custom_inputs
20
22
  //= require_tree .
@@ -1,6 +1,7 @@
1
1
  @import "bootstrap-sprockets";
2
2
  @import "bootstrap";
3
3
  @import "switchery";
4
+ @import "bootstrap-datepicker";
4
5
 
5
6
  body {
6
7
  padding: 30px;
@@ -1,10 +1,11 @@
1
- <%= simple_form_for(@contact) do |f| %>
1
+ <%= simple_form_for(@contact, html_options: {multipart: true}) do |f| %>
2
2
  <%= f.error_notification %>
3
3
 
4
4
  <div class="form-inputs">
5
5
  <%= f.input :name %>
6
6
  <%= f.input :phone, as: :masked, input_html: {data: {pattern: br_phone_mask_pattern}} %>
7
7
  <%= f.input :email %>
8
+ <%= f.input :created_at, as: :datepicker %>
8
9
  </div>
9
10
 
10
11
  <div class="form-actions">
@@ -11,5 +11,7 @@ module Example
11
11
  # Settings in config/environments/* take precedence over those specified here.
12
12
  # Application configuration should go into files in config/initializers
13
13
  # -- all .rb files in that directory are automatically loaded.
14
+ config.time_zone = 'Brasilia'
15
+ config.i18n.default_locale = 'pt-BR'
14
16
  end
15
17
  end
@@ -0,0 +1,2 @@
1
+ pt-BR:
2
+ hello: Olá
@@ -2,6 +2,8 @@ require "simple_form_custom_inputs/version"
2
2
 
3
3
  autoload :SwitchInput, "simple_form_custom_inputs/simple_form/switch_input"
4
4
  autoload :MaskedInput, "simple_form_custom_inputs/simple_form/masked_input"
5
+ autoload :DatepickerInput, "simple_form_custom_inputs/simple_form/datepicker_input"
6
+ autoload :ButtonFileInput, "simple_form_custom_inputs/simple_form/button_file_input"
5
7
 
6
8
  module SimpleFormCustomInputs
7
9
  class Engine < ::Rails::Engine; end
@@ -0,0 +1,24 @@
1
+ require 'active_support/core_ext/string/output_safety'
2
+
3
+ class ButtonFileInput < SimpleForm::Inputs::FileInput
4
+ attr_accessor :output_buffer
5
+
6
+ def input(wrapper_options = nil)
7
+ input_html_options[:class] << 'hidden inputfile'
8
+ merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
9
+
10
+ (@builder.file_field(attribute_name, merged_input_options) + button).html_safe
11
+ end
12
+
13
+ private
14
+
15
+ def button
16
+ content_tag(:div) do
17
+ content_tag(:label, for: input_class) do
18
+ content_tag(:span, class: options[:class]) do
19
+ label_text.present? ? label_text : I18n.t("simple_form.labels.defaults.#{attribute_name}")
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,8 @@
1
+ class DatepickerInput < SimpleForm::Inputs::StringInput
2
+ def input(wrapper_options)
3
+ input_html_options[:data] ||= {}
4
+ input_html_options[:class] << 'datepicker'
5
+ input_html_options[:data].merge!({ locale: I18n.locale })
6
+ super
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module SimpleFormCustomInputs
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,10 @@
1
+ (function($){
2
+ $.fn.datepicker.dates['pt-BR'] = {
3
+ days: ["Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado", "Domingo"],
4
+ daysShort: ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sáb", "Dom"],
5
+ daysMin: ["Do", "Se", "Te", "Qu", "Qu", "Se", "Sa", "Do"],
6
+ months: ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"],
7
+ monthsShort: ["Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"],
8
+ today: "Hoje"
9
+ };
10
+ }(jQuery));
@@ -1,25 +1,56 @@
1
1
  var initSwitchery = function() {
2
- var elem = $('.js-switch')
2
+ var elem = $(".js-switch")
3
3
  if (elem[0]){
4
4
  var init = new Switchery(elem[0], {
5
- color: elem.data('color'),
6
- secondaryColor: elem.data('secondaryColor'),
7
- jackColor: elem.data('jackColor'),
8
- jackSecondaryColor: elem.data('jackSecondaryColor'),
9
- size: elem.data('size')
5
+ color: elem.data("color"),
6
+ secondaryColor: elem.data("secondaryColor"),
7
+ jackColor: elem.data("jackColor"),
8
+ jackSecondaryColor: elem.data("jackSecondaryColor"),
9
+ size: elem.data("size")
10
10
  });
11
- }
12
- }
11
+ };
12
+ };
13
13
 
14
14
  var initMasks = function() {
15
- var input = $('.masked input');
16
- var pattern = input.data('pattern');
15
+ var input = $(".masked input");
16
+ var pattern = input.data("pattern");
17
17
  input.mask(pattern);
18
+ };
19
+
20
+ var initDatepicker = function() {
21
+ $(".datepicker input").datepicker({
22
+ autoclose: true,
23
+ todayHighlight: true,
24
+ language: $(".datepicker input").data("locale")
25
+ });
26
+ };
27
+
28
+ var handleAttachementLabel = function() {
29
+ var inputs = document.querySelectorAll( '.inputfile' );
30
+ Array.prototype.forEach.call(inputs, function(input) {
31
+ var label = input.nextElementSibling,
32
+ labelVal = label.innerHTML;
33
+
34
+ input.addEventListener( 'change', function(e) {
35
+ var fileName = '';
36
+ if( this.files && this.files.length > 1 )
37
+ fileName = (this.getAttribute('data-multiple-caption' ) || '').replace('{count}', this.files.length);
38
+ else
39
+ fileName = e.target.value.split( '\\' ).pop();
40
+
41
+ if( fileName )
42
+ label.querySelector('span').innerHTML = fileName;
43
+ else
44
+ label.innerHTML = labelVal;
45
+ });
46
+ });
18
47
  }
19
48
 
20
49
  var ready = function() {
21
50
  initSwitchery();
22
51
  initMasks();
52
+ initDatepicker();
53
+ handleAttachementLabel();
23
54
  };
24
55
 
25
56
  if (typeof Turbolinks == "undefined") {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form_custom_inputs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Barreto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-27 00:00:00.000000000 Z
11
+ date: 2017-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -129,6 +129,7 @@ files:
129
129
  - example/config/initializers/simple_form_bootstrap.rb
130
130
  - example/config/initializers/wrap_parameters.rb
131
131
  - example/config/locales/en.yml
132
+ - example/config/locales/pt-BR.yml
132
133
  - example/config/locales/simple_form.en.yml
133
134
  - example/config/puma.rb
134
135
  - example/config/routes.rb
@@ -167,12 +168,15 @@ files:
167
168
  - example/vendor/assets/javascripts/.keep
168
169
  - example/vendor/assets/stylesheets/.keep
169
170
  - lib/simple_form_custom_inputs.rb
171
+ - lib/simple_form_custom_inputs/simple_form/button_file_input.rb
172
+ - lib/simple_form_custom_inputs/simple_form/datepicker_input.rb
170
173
  - lib/simple_form_custom_inputs/simple_form/masked_input.rb
171
174
  - lib/simple_form_custom_inputs/simple_form/switch_input.rb
172
175
  - lib/simple_form_custom_inputs/version.rb
173
176
  - screenshot.png
174
177
  - simple_form_custom_inputs.gemspec
175
178
  - vendor/assets/javascripts/.keep
179
+ - vendor/assets/javascripts/I18n/pt-BR.js
176
180
  - vendor/assets/javascripts/simple_form_custom_inputs.js
177
181
  homepage: https://github.com/marcelobarreto/simple_form_custom_inputs
178
182
  licenses: []