simple_form_bootstrap_inputs 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 43c8782148ba5917fdb390aee07cb23f4f57aeeb135c9d3ff6cb0a7eccc8132c
4
+ data.tar.gz: 6579f51aeaefda6267905d48aec3f58cddeb40941e7cb83d6d00e957f2ed71f4
5
+ SHA512:
6
+ metadata.gz: d9715ca8c364d3d93772ef2f82e3f1e2110200a3e03332a785e96170d0d2399eec59f5fe0d70c1451a1c520ff819f2da8885a5c3cd287efbf557d2e321da50fe
7
+ data.tar.gz: 97f02e8dd2f84cc03b5e418a390e9f7c9bae8f4db60dcc7843d268ff41eb4ed988877589d40fed1c40194e39ff86cb954e4faa34c06ebdc22730cdd3ec2591e8
@@ -0,0 +1,20 @@
1
+ Copyright 2018 ValentinAndreev
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.
@@ -0,0 +1,38 @@
1
+ # SimpleFormBootstrapInputs
2
+
3
+ ## Установка
4
+
5
+ ```ruby
6
+ gem 'simple_form_bootstrap_inputs', github: 'BrandyMint/simple_form_bootstrap_inputs'
7
+ ```
8
+
9
+ ```bash
10
+ $ bundle
11
+ ```
12
+
13
+ Необходим bootstrap и bootstrap-datetimepicker\
14
+ В application.js:\
15
+ //= require bootstrap\
16
+ //= require bootstrap-datetimepicker
17
+ ```javascript
18
+ document.addEventListener("turbolinks:load", function() {
19
+ $('div.datetimepicker').datetimepicker({ locale: 'ru', format: 'DD-MM-YYYY' });
20
+ });
21
+ ```
22
+
23
+ ## Использование
24
+ Пример
25
+ ```ruby
26
+ = simple_form_for model do |f|
27
+ = f.input :date, as: 'simple_form_bootstrap_inputs/date_picker'
28
+ = f.input :currency, as: 'simple_form_bootstrap_inputs/currency'
29
+ = f.input :datetime, as: 'simple_form_bootstrap_inputs/datetime_picker'
30
+ ...
31
+ ```
32
+ date - дата по умолчанию в формате: 'YYYY-MM-DD'\
33
+ ![date](/doc/date.png)\
34
+ datetime - дата и время в формате: 'YYYY-MM-DD' + ' ' + 'HH:mm'\
35
+ ![datetime](/doc/datetime.png)\
36
+ currency:\
37
+ у model должны быть 2 аттрибута, например - value и value_currency - string\
38
+ ![currency](/doc/currency.png)
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'SimpleFormBootstrapInputs'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ require 'bundler/gem_tasks'
18
+
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << 'test'
23
+ t.pattern = 'test/**/*_test.rb'
24
+ t.verbose = false
25
+ end
26
+
27
+ task default: :test
@@ -0,0 +1,8 @@
1
+ require 'simple_form'
2
+ require "simple_form_bootstrap_inputs/railtie"
3
+ require "simple_form_bootstrap_inputs/currency_input"
4
+ require "simple_form_bootstrap_inputs/date_picker_input"
5
+ require "simple_form_bootstrap_inputs/datetime_picker_input"
6
+
7
+ module SimpleFormBootstrapInputs
8
+ end
@@ -0,0 +1,21 @@
1
+ # rubocop:disable all
2
+ require 'simple_form'
3
+
4
+ module SimpleFormBootstrapInputs
5
+ class CurrencyInput < SimpleForm::Inputs::Base
6
+ def input(wrapper_options)
7
+ merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
8
+ "<div class=\"input-group\">#{@builder.text_field(attribute_name, merged_input_options)}<div class=\"input-group-addon\">#{currency_addon}</div></div>"
9
+ .html_safe
10
+ end
11
+
12
+ private
13
+
14
+ def currency_addon
15
+ currency_attribute_name = attribute_name.to_s + '_currency'
16
+ # currency = object.send(attribute_name).currency
17
+ value = object.send(currency_attribute_name)
18
+ "<input type=\"hidden\" value=\"#{value}\" name=\"#{object_name}[#{currency_attribute_name}]\">#{value.presence || '???'}"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,66 @@
1
+ module SimpleFormBootstrapInputs
2
+ class DatePickerInput < SimpleForm::Inputs::StringInput
3
+ def input(wrapper_options)
4
+ set_html_options
5
+ set_value_html_option
6
+
7
+ template.content_tag :div, class: 'input-group date datetimepicker' do
8
+ input = super(wrapper_options) # leave StringInput do the real rendering
9
+ input + input_button
10
+ end
11
+ end
12
+
13
+ def input_html_classes
14
+ super.push '' # 'form-control'
15
+ end
16
+
17
+ private
18
+
19
+ def input_button
20
+ template.content_tag :span, class: 'input-group-addon' do
21
+ template.content_tag :span, '', class: 'fa fa-calendar'
22
+ end
23
+ end
24
+
25
+ def set_html_options
26
+ input_html_options[:type] = 'text'
27
+ input_html_options[:data] ||= {}
28
+ input_html_options[:data].merge!(date_options: date_options)
29
+ end
30
+
31
+ def set_value_html_option
32
+ return if value.blank?
33
+
34
+ input_html_options[:value] ||= I18n.localize(value, format: display_pattern)
35
+ end
36
+
37
+ def value
38
+ object.send(attribute_name) if object.respond_to? attribute_name
39
+ end
40
+
41
+ def display_pattern
42
+ I18n.t('datepicker.dformat', default: '%d-%m-%Y')
43
+ end
44
+
45
+ def picker_pattern
46
+ I18n.t('datepicker.pformat', default: 'DD-MM-YYYY')
47
+ end
48
+
49
+ def date_view_header_format
50
+ I18n.t('dayViewHeaderFormat', default: 'MMMM YYYY')
51
+ end
52
+
53
+ def date_options_base
54
+ {
55
+ locale: I18n.locale.to_s,
56
+ format: picker_pattern,
57
+ dayViewHeaderFormat: date_view_header_format
58
+ }
59
+ end
60
+
61
+ def date_options
62
+ custom_options = input_html_options[:data][:date_options] || {}
63
+ date_options_base.merge!(custom_options)
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,18 @@
1
+ # Этот input перекрывает input из formtastic и поэтому его не возможно использовать в админке
2
+ # Пример как это обходится https://github.com/activeadmin/activeadmin/issues/2703
3
+
4
+ module SimpleFormBootstrapInputs
5
+ class DatetimePickerInput < DatePickerInput
6
+ private
7
+
8
+ def display_pattern
9
+ I18n.t('datepicker.dformat', default: '%Y-%m-%d') + ' ' +
10
+ I18n.t('timepicker.dformat', default: '%R')
11
+ end
12
+
13
+ def picker_pattern
14
+ I18n.t('datepicker.pformat', default: 'YYYY-MM-DD') + ' ' +
15
+ I18n.t('timepicker.pformat', default: 'HH:mm')
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ module SimpleFormBootstrapInputs
2
+ class Railtie < ::Rails::Railtie
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleFormBootstrapInputs
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :simple_form_bootstrap_inputs do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_form_bootstrap_inputs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Valentin Andreev
8
+ - Danil Pismenny
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2018-12-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails-i18n
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bootstrap-sass
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '3.2'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '3.2'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bootstrap3-datetimepicker-rails
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: 4.17.47
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: 4.17.47
56
+ - !ruby/object:Gem::Dependency
57
+ name: jquery-rails
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: jquery-ui-rails
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: simple_form
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ description: Provides date, currency and date_time inputs for SimpleForm and Bootstrap
99
+ email:
100
+ - valentinandreev80@gmail.com
101
+ - danil@brandymint.ru
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - MIT-LICENSE
107
+ - README.md
108
+ - Rakefile
109
+ - lib/simple_form_bootstrap_inputs.rb
110
+ - lib/simple_form_bootstrap_inputs/currency_input.rb
111
+ - lib/simple_form_bootstrap_inputs/date_picker_input.rb
112
+ - lib/simple_form_bootstrap_inputs/datetime_picker_input.rb
113
+ - lib/simple_form_bootstrap_inputs/railtie.rb
114
+ - lib/simple_form_bootstrap_inputs/version.rb
115
+ - lib/tasks/simple_form_bootstrap_inputs_tasks.rake
116
+ homepage: https://github.com/brandymint/simple_form_bootstrap_inputs
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.7.7
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: date, currency and date_time inputs for SimpleForm and Bootstrap
140
+ test_files: []