simple_form-theme 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: 5e275530d19251b93ce0131fa8f50fde91594a5dc39cc5d3cc6a9e120218d86f
4
- data.tar.gz: d1c5054ad31b75e7275773414d3fc773bf51b18b8a03ee33bf887fdb3f0887f4
3
+ metadata.gz: 437ec70587ba8a60a1c4d2dc5e8c3b02298439dc55ef904d5c71115c8cd1da48
4
+ data.tar.gz: 3d042a0e47a5ff75365a08dfd242134d7e8dfae4b75437afe70b95a1fd641da5
5
5
  SHA512:
6
- metadata.gz: 32bf9ba67047d0309dff1b7265a295f382067f605fc9112bb1a7a58960d62e2b94e25435994659750e2c68801049964b06250e527b8fad49a7b55490ecb53420
7
- data.tar.gz: 43c9616ac3ae8c74bd5a76e273d4dce6093d8e6c54c38775b672ca51be9c3d605d9870938f24f8ceeec012ee837a1c542f4d21c2712a841d6aa258abe04e3dee
6
+ metadata.gz: cfe2bbe85d5ba2ae74c8aea94f789028d0e42325c47a6a2e5fe490f9d5a005eaafdac420fc266656946dbb2af820e63cfa3291864ffdfa05b6d2cfe1612a1c9b
7
+ data.tar.gz: 9be70bb643d0cd348a5c91ff66c0820d7c7dce37b9dc6bbc8c6219f4080563ee1da85f37e188fc48f69bd68e4e29741f76ba015072ffd516e83ffe3f447209ad
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # SimpleForm::Theme
2
2
  Short description and motivation.
3
3
 
4
- ## Usage
5
- How to use my plugin.
4
+ ### Supported CSS Frameworks
5
+ * [Tailwind CSS](https://tailwindcss.com/docs/installation)
6
+ * [Bulma](https://bulma.io/documentation/start/installation)
6
7
 
7
8
  ## Installation
8
9
  Add this line to your application's Gemfile:
@@ -13,16 +14,40 @@ gem 'simple_form-theme'
13
14
 
14
15
  And then execute:
15
16
  ```bash
16
- $ bundle
17
+ bundle
18
+ ```
19
+
20
+ As an alternative instead of adding an additional dependency to your project,
21
+ you can copy the initializer file to your project from the GitHub repository.
22
+
23
+ Example:
24
+ ```bash
25
+ cp lib/generators/simple_form/theme/templates/config/initializers/simple_form_tailwindcss.rb yourapp/config/initializers/simple_form_tailwindcss.rb
17
26
  ```
18
27
 
19
- Or install it yourself as:
28
+ However, if you install the gem, you will get the latest updates and improvements.
29
+
30
+ ## Requirements
31
+
32
+ * Make sure you have installed [simple_form](https://github.com/heartcombo/simple_form) gem.
33
+ * Make sure you have installed the decired css framework.
34
+
35
+ ## Usage
36
+
37
+ ### Install Tailwind CSS initializer
38
+
39
+ ```bash
40
+ bin/rails generate simple_form:theme:tailwind install
41
+ ```
42
+
43
+ ### Install Bulma CSS initializer
44
+
20
45
  ```bash
21
- $ gem install simple_form-theme
46
+ bin/rails generate simple_form:theme:bulma install
22
47
  ```
23
48
 
24
49
  ## Contributing
25
- Contribution directions go here.
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/JuanVqz/simple_form-theme
26
51
 
27
52
  ## License
28
53
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Install the simple form bulma config file in your app.
3
+
4
+ Example:
5
+ bin/rails generate simple_form:theme:bulma install
6
+
7
+ This will create:
8
+ config/initializers/simple_form_bulma.rb
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SimpleForm::Theme::BulmaGenerator < Rails::Generators::NamedBase
4
+ source_root File.expand_path('templates', __dir__)
5
+
6
+ desc 'Copy the bulma initializer file for simple_form'
7
+ def copy_initializer_file
8
+ template 'config/initializers/simple_form_bulma.rb', 'config/initializers/simple_form_bulma.rb'
9
+ end
10
+ end
@@ -0,0 +1,126 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Use this setup block to configure all options available in SimpleForm.
4
+ SimpleForm.setup do |config|
5
+ # Default class for buttons
6
+ config.button_class = 'button'
7
+
8
+ # Define the default class of the input wrapper of the boolean input.
9
+ config.boolean_label_class = 'checkbox'
10
+
11
+ # How the label text should be generated altogether with the required text.
12
+ config.label_text = ->(label, required, _explicit_label) { "#{label} #{required}" }
13
+
14
+ # Define the way to render check boxes / radio buttons with labels.
15
+ config.boolean_style = :inline
16
+
17
+ # You can wrap each item in a collection of radio/check boxes with a tag
18
+ config.item_wrapper_tag = :div
19
+
20
+ # Defines if the default input wrapper class should be included in radio
21
+ # collection wrappers.
22
+ config.include_default_input_wrapper_class = false
23
+
24
+ # CSS class to add for error notification helper.
25
+ config.error_notification_class = 'notification is-danger'
26
+
27
+ # Method used to tidy up errors. Specify any Rails Array method.
28
+ # :first lists the first message for each field.
29
+ # :to_sentence to list all errors for each field.
30
+ config.error_method = :to_sentence
31
+
32
+ # add validation classes to `input_field`
33
+ config.input_field_error_class = 'is-danger'
34
+ config.input_field_valid_class = 'is-success'
35
+
36
+ # vertical forms
37
+ #
38
+ # bulma vertical default_wrapper
39
+ config.wrappers :vertical_form, tag: 'div', class: 'field' do |b|
40
+ b.use :html5
41
+ b.use :placeholder
42
+ b.optional :maxlength
43
+ b.optional :minlength
44
+ b.optional :pattern
45
+ b.optional :min_max
46
+ b.optional :readonly
47
+ b.use :label, class: 'label'
48
+ b.use :input, class: 'input', wrap_with: { tag: 'div', class: 'control' }, error_class: 'is-danger', valid_class: 'is-success'
49
+ b.use :full_error, wrap_with: { tag: 'div', class: 'help is-danger' }
50
+ b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
51
+ end
52
+
53
+ # bulma vertical select_form
54
+ config.wrappers :select_form, tag: 'div', class: 'control' do |b|
55
+ b.use :html5
56
+ b.use :placeholder
57
+ b.optional :pattern
58
+ b.optional :readonly
59
+ b.use :input, wrap_with: { tag: 'div', class: 'select' }
60
+ b.use :full_error, wrap_with: { tag: 'div', class: 'help is-danger' }
61
+ b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
62
+ end
63
+
64
+ # bulma extension vertical input for boolean
65
+ config.wrappers :vertical_boolean, tag: 'div', class: 'field' do |b|
66
+ b.use :html5
67
+ b.optional :readonly
68
+ b.use :input, class: 'is-checkradio is-info'
69
+ b.use :label
70
+ # b.wrapper :form_check_wrapper, tag: 'div', class: 'control' do |bb|
71
+ # bb.use :input, wrap_with: { tag: 'label', class: 'checkbox' }
72
+ # bb.use :label, class: 'checkbox'
73
+ # bb.use :full_error, wrap_with: { tag: 'div', class: 'help is-danger' }
74
+ # bb.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
75
+ # end
76
+ end
77
+
78
+ ## vertical input for radio buttons and check boxes
79
+ config.wrappers :vertical_collection, item_wrapper_class: 'form-check', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
80
+ b.use :html5
81
+ b.optional :readonly
82
+ b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba|
83
+ ba.use :label_text
84
+ end
85
+ b.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
86
+ b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
87
+ b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
88
+ end
89
+
90
+ ## bulma vertical file input
91
+ config.wrappers :vertical_file, tag: 'div', class: 'file' do |b|
92
+ b.use :html5
93
+ b.optional :readonly
94
+ b.use :input, class: 'file-input', wrap_with: { tag: 'label', class: 'file-label' }
95
+ b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
96
+ b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
97
+ end
98
+
99
+ ## bulma vertical multi select
100
+ config.wrappers :vertical_multi_select, tag: 'div', class: 'field' do |b|
101
+ b.use :html5
102
+ b.optional :readonly
103
+ b.use :label, class: 'label'
104
+ b.wrapper tag: 'div', class: 'control' do |ba|
105
+ ba.use :input, class: 'input', error_class: 'is-danger', valid_class: 'is-success'
106
+ end
107
+ b.use :full_error, wrap_with: { tag: 'div', class: 'is-danger' }
108
+ b.use :hint, wrap_with: { tag: 'small', class: 'help' }
109
+ end
110
+
111
+ # The default wrapper to be used by the FormBuilder.
112
+ config.default_wrapper = :vertical_form
113
+
114
+ # Custom wrappers for input types. This should be a hash containing an input
115
+ # type as key and the wrapper that will be used for all inputs with specified type.
116
+ config.wrapper_mappings = {
117
+ boolean: :vertical_boolean,
118
+ check_boxes: :vertical_collection,
119
+ date: :vertical_multi_select,
120
+ datetime: :vertical_multi_select,
121
+ file: :vertical_file,
122
+ radio_buttons: :vertical_collection,
123
+ range: :vertical_range,
124
+ time: :vertical_multi_select
125
+ }
126
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Install the simple form tailwindcss config file in your app.
3
+
4
+ Example:
5
+ bin/rails generate simple_form:theme:tailwind install
6
+
7
+ This will create:
8
+ config/initializers/simple_form_tailwindcss.rb
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SimpleForm::Theme::TailwindGenerator < Rails::Generators::NamedBase
4
+ source_root File.expand_path('templates', __dir__)
5
+
6
+ desc 'Copy the tailwindcss initializer file for simple_form'
7
+ def copy_initializer_file
8
+ template 'config/initializers/simple_form_tailwindcss.rb', 'config/initializers/simple_form_tailwindcss.rb'
9
+ end
10
+ end
@@ -0,0 +1,161 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Use this setup block to configure all options available in SimpleForm.
4
+ SimpleForm.setup do |config|
5
+ config.wrappers :vertical_form, tag: :div, class: 'mb-4' do |b|
6
+ b.use :html5
7
+ b.use :placeholder
8
+ b.optional :maxlength
9
+ b.optional :minlength
10
+ b.optional :pattern
11
+ b.optional :min_max
12
+ b.optional :readonly
13
+ b.use :label, class: 'block mb-2 text-sm font-medium text-gray-900 dark:text-white'
14
+ b.use :input,
15
+ class: 'bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500',
16
+ error_class: 'bg-red-50 border-red-500 text-red-900 placeholder-red-700 focus:ring-red-500 dark:bg-gray-700 focus:border-red-500 dark:text-red-500 dark:placeholder-red-500 dark:border-red-500',
17
+ valid_class: 'bg-green-50 border-green-500 text-green-900 dark:text-green-400 placeholder-green-700 dark:placeholder-green-500 focus:ring-green-500 focus:border-green-500 dark:bg-gray-700 dark:border-green-500'
18
+ b.use :full_error, wrap_with: { tag: :p, class: 'mt-2 text-sm text-red-600 dark:text-red-600' }
19
+ b.use :hint, wrap_with: { tag: :small, class: 'text-sm text-gray-400 dark:text-gray-400' }
20
+ end
21
+
22
+ # vertical input for radio buttons and check boxes
23
+ config.wrappers :vertical_collection, item_wrapper_class: 'form-check',
24
+ item_label_class: 'form-check-label',
25
+ tag: :fieldset,
26
+ class: 'form-group mb-3',
27
+ error_class: 'form-group-invalid',
28
+ valid_class: 'form-group-valid' do |b|
29
+ b.use :html5
30
+ b.optional :readonly
31
+ b.wrapper :legend_tag, tag: :legend, class: 'col-form-label pt-0' do |ba|
32
+ ba.use :label_text, class: 'ml-3 block text-sm font-medium text-gray-700'
33
+ end
34
+ b.use :input, class: 'focus:ring-indigo-500 h-4 w-4 text-sky-600 border-gray-300 mr-2',
35
+ error_class: 'is-invalid border-red-400',
36
+ valid_class: 'is-valid'
37
+ b.use :full_error, wrap_with: { tag: :p, class: 'mt-2 text-sm text-red-600 dark:text-red-600' }
38
+ b.use :hint, wrap_with: { tag: :small, class: 'text-gray-400' }
39
+ end
40
+
41
+ # vertical input for radio buttons and check boxes
42
+ # config.wrappers :vertical_check_boxes_collection, item_wrapper_class: 'form-check',
43
+ # item_label_class: 'form-check-label',
44
+ # tag: 'fieldset', class: 'form-group mb-3',
45
+ # error_class: 'form-group-invalid',
46
+ # valid_class: 'form-group-valid' do |b|
47
+ # b.use :html5
48
+ # b.optional :readonly
49
+ # b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba|
50
+ # ba.use :label_text, class: 'ml-3 block text-sm font-medium text-gray-700'
51
+ # end
52
+ # b.use :input, class: 'focus:ring-indigo-500 h-4 w-4 text-sky-600 border-gray-300 rounded mr-2',
53
+ # error_class: 'is-invalid border-red-400',
54
+ # valid_class: 'is-valid'
55
+ # b.use :full_error, wrap_with: {tag: :p, class: "mt-2 text-sm text-red-600 dark:text-red-600"}
56
+ # b.use :hint, wrap_with: { tag: :small, class: 'text-gray-400' }
57
+ # end
58
+
59
+ # horizontal input for inline radio buttons and check boxes
60
+ config.wrappers :horizontal_collection_inline, item_wrapper_class: 'form-check form-check-inline',
61
+ item_label_class: 'form-check-label',
62
+ tag: :div,
63
+ class: 'form-group flex flex-row-reverse w-fit mb-3',
64
+ error_class: 'form-group-invalid',
65
+ valid_class: 'form-group-valid' do |b|
66
+ b.use :html5
67
+ b.optional :readonly
68
+ b.use :label, class: 'pt-0 mb-2'
69
+ b.wrapper :grid_wrapper, tag: :div do |ba|
70
+ ba.use :input, class: 'focus:ring-indigo-500 h-4 w-4 text-sky-600 border-gray-300 rounded mr-2',
71
+ error_class: 'is-invalid', valid_class: 'is-valid'
72
+ ba.use :full_error, wrap_with: { tag: :p, class: 'mt-2 text-sm text-red-600 dark:text-red-600' }
73
+ ba.use :hint, wrap_with: { tag: :small, class: 'text-gray-400' }
74
+ end
75
+ end
76
+
77
+ # vertical multi select
78
+ config.wrappers :vertical_multi_select, tag: :div, class: 'mb-4' do |b|
79
+ b.use :html5
80
+ b.optional :readonly
81
+ b.use :label, class: 'block mb-2 text-sm font-medium text-gray-900 dark:text-white'
82
+ b.wrapper tag: :div, class: 'flex flex-col md:flex-row gap-1 justify-between items-center' do |ba|
83
+ ba.use :input,
84
+ class: 'bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500',
85
+ error_class: 'bg-red-50 border-red-500 text-red-900 placeholder-red-700 focus:ring-red-500 dark:bg-gray-700 focus:border-red-500 dark:text-red-500 dark:placeholder-red-500 dark:border-red-500',
86
+ valid_class: 'bg-green-50 border-green-500 text-green-900 dark:text-green-400 placeholder-green-700 dark:placeholder-green-500 focus:ring-green-500 focus:border-green-500 dark:bg-gray-700 dark:border-green-500'
87
+ end
88
+ b.use :full_error, wrap_with: { tag: :p, class: 'mt-2 text-sm text-red-600 dark:text-red-600' }
89
+ b.use :hint, wrap_with: { tag: :small, class: 'text-gray-400' }
90
+ end
91
+
92
+ # vertical input for boolean
93
+ config.wrappers :vertical_boolean, tag: :fieldset, class: 'mb-3',
94
+ error_class: 'form-group-invalid',
95
+ valid_class: 'form-group-valid' do |b|
96
+ b.use :html5
97
+ b.optional :readonly
98
+ b.wrapper :form_check_wrapper, tag: 'div' do |bb|
99
+ bb.use :input, class: 'focus:ring-indigo-500 h-4 w-4 text-sky-600 border-gray-300 rounded mr-2',
100
+ error_class: '!border-red-500',
101
+ valid_class: 'is-valid'
102
+ bb.use :label, class: 'mb-2'
103
+ end
104
+ b.use :full_error, wrap_with: { tag: :p, class: 'mt-2 text-sm text-red-600 dark:text-red-600' }
105
+ b.use :hint, wrap_with: { tag: :small, class: 'text-gray-400' }
106
+ end
107
+
108
+ # vertical file input
109
+ config.wrappers :vertical_file, tag: :div, class: 'mb-4' do |b|
110
+ b.use :html5
111
+ b.use :placeholder
112
+ b.optional :maxlength
113
+ b.optional :minlength
114
+ b.optional :readonly
115
+ b.use :label, class: 'block mb-2 text-sm font-medium text-gray-900 dark:text-white'
116
+ b.use :input,
117
+ class: 'block w-full text-sm text-gray-900 border border-gray-300 rounded-lg cursor-pointer bg-gray-50 dark:text-gray-400 focus:outline-none dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400',
118
+ error_class: 'bg-red-50 border-red-500 text-red-900 placeholder-red-700 focus:ring-red-500 dark:bg-gray-700 focus:border-red-500 dark:text-red-500 dark:placeholder-red-500 dark:border-red-500',
119
+ valid_class: 'bg-green-50 border-green-500 text-green-900 dark:text-green-400 placeholder-green-700 dark:placeholder-green-500 focus:ring-green-500 focus:border-green-500 dark:bg-gray-700 dark:border-green-500'
120
+ b.use :full_error, wrap_with: { tag: :p, class: 'mt-2 text-sm text-red-600 dark:text-red-600' }
121
+ b.use :hint, wrap_with: { tag: :small, class: 'text-sm text-gray-400 dark:text-gray-400' }
122
+ end
123
+
124
+ # Custom wrappers for input types. This should be a hash containing an input
125
+ # type as key and the wrapper that will be used for all inputs with specified type.
126
+ config.wrapper_mappings = {
127
+ boolean: :vertical_boolean,
128
+ check_boxes: :vertical_collection,
129
+ date: :vertical_multi_select,
130
+ file: :vertical_file,
131
+ datetime: :vertical_multi_select,
132
+ radio_buttons: :vertical_collection,
133
+ time: :vertical_multi_select
134
+ }
135
+
136
+ # How the label text should be generated altogether with the required text.
137
+ config.label_text = ->(label, required, _explicit_label) { "#{label} #{required}" }
138
+
139
+ # CSS class for buttons
140
+ config.button_class = 'text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800'
141
+
142
+ # Set this to div to make the checkbox and radio properly work
143
+ # otherwise simple_form adds a label tag instead of a div around
144
+ # the nested label
145
+ config.item_wrapper_tag = :div
146
+
147
+ # CSS class to add for error notification helper.
148
+ config.error_notification_class = 'bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded'
149
+
150
+ # Method used to tidy up errors. Specify any Rails Array method.
151
+ # :first lists the first message for each field.
152
+ # :to_sentence to list all errors for each field.
153
+ config.error_method = :to_sentence
154
+
155
+ # The default wrapper to be used by the FormBuilder.
156
+ config.default_wrapper = :vertical_form
157
+
158
+ # add validation classes to `input_field`
159
+ config.input_field_error_class = 'bg-red-50'
160
+ config.input_field_valid_class = 'bg-green-50'
161
+ end
@@ -1,5 +1,5 @@
1
1
  module SimpleForm
2
2
  module Theme
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form-theme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Vasquez
@@ -63,6 +63,12 @@ files:
63
63
  - app/models/simple_form/theme/application_record.rb
64
64
  - app/views/layouts/simple_form/theme/application.html.erb
65
65
  - config/routes.rb
66
+ - lib/generators/simple_form/theme/bulma/USAGE
67
+ - lib/generators/simple_form/theme/bulma/bulma_generator.rb
68
+ - lib/generators/simple_form/theme/bulma/templates/config/initializers/simple_form_bulma.rb
69
+ - lib/generators/simple_form/theme/tailwind/USAGE
70
+ - lib/generators/simple_form/theme/tailwind/tailwind_generator.rb
71
+ - lib/generators/simple_form/theme/tailwind/templates/config/initializers/simple_form_tailwindcss.rb
66
72
  - lib/simple_form/theme.rb
67
73
  - lib/simple_form/theme/engine.rb
68
74
  - lib/simple_form/theme/version.rb
@@ -89,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
95
  - !ruby/object:Gem::Version
90
96
  version: '0'
91
97
  requirements: []
92
- rubygems_version: 3.2.3
98
+ rubygems_version: 3.1.6
93
99
  signing_key:
94
100
  specification_version: 4
95
101
  summary: The most modern themes for SimpleForm gem.