simple_form_custom_inputs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +3 -0
  6. data/README.md +78 -0
  7. data/Rakefile +2 -0
  8. data/example/.gitignore +21 -0
  9. data/example/Gemfile +61 -0
  10. data/example/Gemfile.lock +206 -0
  11. data/example/README.md +24 -0
  12. data/example/Rakefile +6 -0
  13. data/example/app/assets/config/manifest.js +3 -0
  14. data/example/app/assets/images/.keep +0 -0
  15. data/example/app/assets/javascripts/application.js +19 -0
  16. data/example/app/assets/javascripts/cable.js +13 -0
  17. data/example/app/assets/javascripts/channels/.keep +0 -0
  18. data/example/app/assets/javascripts/posts.coffee +3 -0
  19. data/example/app/assets/stylesheets/application.scss +7 -0
  20. data/example/app/assets/stylesheets/posts.scss +3 -0
  21. data/example/app/assets/stylesheets/scaffolds.scss +89 -0
  22. data/example/app/channels/application_cable/channel.rb +4 -0
  23. data/example/app/channels/application_cable/connection.rb +4 -0
  24. data/example/app/controllers/application_controller.rb +3 -0
  25. data/example/app/controllers/concerns/.keep +0 -0
  26. data/example/app/controllers/posts_controller.rb +74 -0
  27. data/example/app/helpers/application_helper.rb +2 -0
  28. data/example/app/helpers/posts_helper.rb +2 -0
  29. data/example/app/jobs/application_job.rb +2 -0
  30. data/example/app/mailers/application_mailer.rb +4 -0
  31. data/example/app/models/application_record.rb +3 -0
  32. data/example/app/models/concerns/.keep +0 -0
  33. data/example/app/models/post.rb +2 -0
  34. data/example/app/views/layouts/application.html.erb +14 -0
  35. data/example/app/views/layouts/mailer.html.erb +13 -0
  36. data/example/app/views/layouts/mailer.text.erb +1 -0
  37. data/example/app/views/posts/_form.html.erb +13 -0
  38. data/example/app/views/posts/_post.json.jbuilder +2 -0
  39. data/example/app/views/posts/edit.html.erb +6 -0
  40. data/example/app/views/posts/index.html.erb +31 -0
  41. data/example/app/views/posts/index.json.jbuilder +1 -0
  42. data/example/app/views/posts/new.html.erb +5 -0
  43. data/example/app/views/posts/show.html.erb +19 -0
  44. data/example/app/views/posts/show.json.jbuilder +1 -0
  45. data/example/bin/bundle +3 -0
  46. data/example/bin/rails +9 -0
  47. data/example/bin/rake +9 -0
  48. data/example/bin/setup +34 -0
  49. data/example/bin/spring +17 -0
  50. data/example/bin/update +29 -0
  51. data/example/config.ru +5 -0
  52. data/example/config/application.rb +15 -0
  53. data/example/config/boot.rb +3 -0
  54. data/example/config/cable.yml +9 -0
  55. data/example/config/database.yml +25 -0
  56. data/example/config/environment.rb +5 -0
  57. data/example/config/environments/development.rb +54 -0
  58. data/example/config/environments/production.rb +86 -0
  59. data/example/config/environments/test.rb +42 -0
  60. data/example/config/initializers/application_controller_renderer.rb +6 -0
  61. data/example/config/initializers/assets.rb +11 -0
  62. data/example/config/initializers/backtrace_silencers.rb +7 -0
  63. data/example/config/initializers/cookies_serializer.rb +5 -0
  64. data/example/config/initializers/filter_parameter_logging.rb +4 -0
  65. data/example/config/initializers/inflections.rb +16 -0
  66. data/example/config/initializers/mime_types.rb +4 -0
  67. data/example/config/initializers/new_framework_defaults.rb +24 -0
  68. data/example/config/initializers/session_store.rb +3 -0
  69. data/example/config/initializers/simple_form.rb +169 -0
  70. data/example/config/initializers/simple_form_bootstrap.rb +154 -0
  71. data/example/config/initializers/wrap_parameters.rb +14 -0
  72. data/example/config/locales/en.yml +23 -0
  73. data/example/config/locales/simple_form.en.yml +31 -0
  74. data/example/config/puma.rb +47 -0
  75. data/example/config/routes.rb +4 -0
  76. data/example/config/secrets.yml +22 -0
  77. data/example/config/spring.rb +6 -0
  78. data/example/db/migrate/20170427011041_create_posts.rb +11 -0
  79. data/example/db/schema.rb +23 -0
  80. data/example/db/seeds.rb +7 -0
  81. data/example/lib/assets/.keep +0 -0
  82. data/example/lib/tasks/.keep +0 -0
  83. data/example/lib/templates/erb/scaffold/_form.html.erb +13 -0
  84. data/example/log/.keep +0 -0
  85. data/example/public/404.html +67 -0
  86. data/example/public/422.html +67 -0
  87. data/example/public/500.html +66 -0
  88. data/example/public/apple-touch-icon-precomposed.png +0 -0
  89. data/example/public/apple-touch-icon.png +0 -0
  90. data/example/public/favicon.ico +0 -0
  91. data/example/public/robots.txt +5 -0
  92. data/example/test/controllers/.keep +0 -0
  93. data/example/test/controllers/posts_controller_test.rb +48 -0
  94. data/example/test/fixtures/.keep +0 -0
  95. data/example/test/fixtures/files/.keep +0 -0
  96. data/example/test/fixtures/posts.yml +11 -0
  97. data/example/test/helpers/.keep +0 -0
  98. data/example/test/integration/.keep +0 -0
  99. data/example/test/mailers/.keep +0 -0
  100. data/example/test/models/.keep +0 -0
  101. data/example/test/models/post_test.rb +7 -0
  102. data/example/test/test_helper.rb +10 -0
  103. data/example/tmp/.keep +0 -0
  104. data/example/vendor/assets/javascripts/.keep +0 -0
  105. data/example/vendor/assets/stylesheets/.keep +0 -0
  106. data/lib/simple_form_custom_inputs.rb +7 -0
  107. data/lib/simple_form_custom_inputs/simple_form/switch_input.rb +11 -0
  108. data/lib/simple_form_custom_inputs/version.rb +3 -0
  109. data/screenshot.png +0 -0
  110. data/simple_form_custom_inputs.gemspec +23 -0
  111. data/vendor/assets/javascripts/.keep +0 -0
  112. data/vendor/assets/javascripts/simple_form_custom_inputs.js +22 -0
  113. metadata +182 -0
@@ -0,0 +1,154 @@
1
+ # Use this setup block to configure all options available in SimpleForm.
2
+ SimpleForm.setup do |config|
3
+ config.error_notification_class = 'alert alert-danger'
4
+ config.button_class = 'btn btn-default'
5
+ config.boolean_label_class = nil
6
+
7
+ config.wrappers :vertical_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
8
+ b.use :html5
9
+ b.use :placeholder
10
+ b.optional :maxlength
11
+ b.optional :minlength
12
+ b.optional :pattern
13
+ b.optional :min_max
14
+ b.optional :readonly
15
+ b.use :label, class: 'control-label'
16
+
17
+ b.use :input, class: 'form-control'
18
+ b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
19
+ b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
20
+ end
21
+
22
+ config.wrappers :vertical_file_input, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
23
+ b.use :html5
24
+ b.use :placeholder
25
+ b.optional :maxlength
26
+ b.optional :minlength
27
+ b.optional :readonly
28
+ b.use :label, class: 'control-label'
29
+
30
+ b.use :input
31
+ b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
32
+ b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
33
+ end
34
+
35
+ config.wrappers :vertical_boolean, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
36
+ b.use :html5
37
+ b.optional :readonly
38
+
39
+ b.wrapper tag: 'div', class: 'checkbox' do |ba|
40
+ ba.use :label_input
41
+ end
42
+
43
+ b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
44
+ b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
45
+ end
46
+
47
+ config.wrappers :vertical_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
48
+ b.use :html5
49
+ b.optional :readonly
50
+ b.use :label, class: 'control-label'
51
+ b.use :input
52
+ b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
53
+ b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
54
+ end
55
+
56
+ config.wrappers :horizontal_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
57
+ b.use :html5
58
+ b.use :placeholder
59
+ b.optional :maxlength
60
+ b.optional :minlength
61
+ b.optional :pattern
62
+ b.optional :min_max
63
+ b.optional :readonly
64
+ b.use :label, class: 'col-sm-3 control-label'
65
+
66
+ b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
67
+ ba.use :input, class: 'form-control'
68
+ ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
69
+ ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
70
+ end
71
+ end
72
+
73
+ config.wrappers :horizontal_file_input, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
74
+ b.use :html5
75
+ b.use :placeholder
76
+ b.optional :maxlength
77
+ b.optional :minlength
78
+ b.optional :readonly
79
+ b.use :label, class: 'col-sm-3 control-label'
80
+
81
+ b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
82
+ ba.use :input
83
+ ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
84
+ ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
85
+ end
86
+ end
87
+
88
+ config.wrappers :horizontal_boolean, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
89
+ b.use :html5
90
+ b.optional :readonly
91
+
92
+ b.wrapper tag: 'div', class: 'col-sm-offset-3 col-sm-9' do |wr|
93
+ wr.wrapper tag: 'div', class: 'checkbox' do |ba|
94
+ ba.use :label_input
95
+ end
96
+
97
+ wr.use :error, wrap_with: { tag: 'span', class: 'help-block' }
98
+ wr.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
99
+ end
100
+ end
101
+
102
+ config.wrappers :horizontal_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
103
+ b.use :html5
104
+ b.optional :readonly
105
+
106
+ b.use :label, class: 'col-sm-3 control-label'
107
+
108
+ b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
109
+ ba.use :input
110
+ ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
111
+ ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
112
+ end
113
+ end
114
+
115
+ config.wrappers :inline_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
116
+ b.use :html5
117
+ b.use :placeholder
118
+ b.optional :maxlength
119
+ b.optional :minlength
120
+ b.optional :pattern
121
+ b.optional :min_max
122
+ b.optional :readonly
123
+ b.use :label, class: 'sr-only'
124
+
125
+ b.use :input, class: 'form-control'
126
+ b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
127
+ b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
128
+ end
129
+
130
+ config.wrappers :multi_select, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
131
+ b.use :html5
132
+ b.optional :readonly
133
+ b.use :label, class: 'control-label'
134
+ b.wrapper tag: 'div', class: 'form-inline' do |ba|
135
+ ba.use :input, class: 'form-control'
136
+ ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
137
+ ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
138
+ end
139
+ end
140
+ # Wrappers for forms and inputs using the Bootstrap toolkit.
141
+ # Check the Bootstrap docs (http://getbootstrap.com)
142
+ # to learn about the different styles for forms and inputs,
143
+ # buttons and other elements.
144
+ config.default_wrapper = :vertical_form
145
+ config.wrapper_mappings = {
146
+ check_boxes: :vertical_radio_and_checkboxes,
147
+ radio_buttons: :vertical_radio_and_checkboxes,
148
+ file: :vertical_file_input,
149
+ boolean: :vertical_boolean,
150
+ datetime: :multi_select,
151
+ date: :multi_select,
152
+ time: :multi_select
153
+ }
154
+ end
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters format: [:json]
9
+ end
10
+
11
+ # To enable root element in JSON for ActiveRecord objects.
12
+ # ActiveSupport.on_load(:active_record) do
13
+ # self.include_root_in_json = true
14
+ # end
@@ -0,0 +1,23 @@
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded by Rails. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t 'hello'
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t('hello') %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # To learn more, please read the Rails Internationalization guide
20
+ # available at http://guides.rubyonrails.org/i18n.html.
21
+
22
+ en:
23
+ hello: "Hello world"
@@ -0,0 +1,31 @@
1
+ en:
2
+ simple_form:
3
+ "yes": 'Yes'
4
+ "no": 'No'
5
+ required:
6
+ text: 'required'
7
+ mark: '*'
8
+ # You can uncomment the line below if you need to overwrite the whole required html.
9
+ # When using html, text and mark won't be used.
10
+ # html: '<abbr title="required">*</abbr>'
11
+ error_notification:
12
+ default_message: "Please review the problems below:"
13
+ # Examples
14
+ # labels:
15
+ # defaults:
16
+ # password: 'Password'
17
+ # user:
18
+ # new:
19
+ # email: 'E-mail to sign in.'
20
+ # edit:
21
+ # email: 'E-mail.'
22
+ # hints:
23
+ # defaults:
24
+ # username: 'User name to sign in.'
25
+ # password: 'No special characters, please.'
26
+ # include_blanks:
27
+ # defaults:
28
+ # age: 'Rather not say'
29
+ # prompts:
30
+ # defaults:
31
+ # age: 'Select your age'
@@ -0,0 +1,47 @@
1
+ # Puma can serve each request in a thread from an internal thread pool.
2
+ # The `threads` method setting takes two numbers a minimum and maximum.
3
+ # Any libraries that use thread pools should be configured to match
4
+ # the maximum value specified for Puma. Default is set to 5 threads for minimum
5
+ # and maximum, this matches the default thread size of Active Record.
6
+ #
7
+ threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
8
+ threads threads_count, threads_count
9
+
10
+ # Specifies the `port` that Puma will listen on to receive requests, default is 3000.
11
+ #
12
+ port ENV.fetch("PORT") { 3000 }
13
+
14
+ # Specifies the `environment` that Puma will run in.
15
+ #
16
+ environment ENV.fetch("RAILS_ENV") { "development" }
17
+
18
+ # Specifies the number of `workers` to boot in clustered mode.
19
+ # Workers are forked webserver processes. If using threads and workers together
20
+ # the concurrency of the application would be max `threads` * `workers`.
21
+ # Workers do not work on JRuby or Windows (both of which do not support
22
+ # processes).
23
+ #
24
+ # workers ENV.fetch("WEB_CONCURRENCY") { 2 }
25
+
26
+ # Use the `preload_app!` method when specifying a `workers` number.
27
+ # This directive tells Puma to first boot the application and load code
28
+ # before forking the application. This takes advantage of Copy On Write
29
+ # process behavior so workers use less memory. If you use this option
30
+ # you need to make sure to reconnect any threads in the `on_worker_boot`
31
+ # block.
32
+ #
33
+ # preload_app!
34
+
35
+ # The code in the `on_worker_boot` will be called if you are using
36
+ # clustered mode by specifying a number of `workers`. After each worker
37
+ # process is booted this block will be run, if you are using `preload_app!`
38
+ # option you will want to use this block to reconnect to any threads
39
+ # or connections that may have been created at application boot, Ruby
40
+ # cannot share connections between processes.
41
+ #
42
+ # on_worker_boot do
43
+ # ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
44
+ # end
45
+
46
+ # Allow puma to be restarted by `rails restart` command.
47
+ plugin :tmp_restart
@@ -0,0 +1,4 @@
1
+ Rails.application.routes.draw do
2
+ resources :posts
3
+ # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
4
+ end
@@ -0,0 +1,22 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key is used for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+
6
+ # Make sure the secret is at least 30 characters and all random,
7
+ # no regular words or you'll be exposed to dictionary attacks.
8
+ # You can use `rails secret` to generate a secure secret key.
9
+
10
+ # Make sure the secrets in this file are kept private
11
+ # if you're sharing your code publicly.
12
+
13
+ development:
14
+ secret_key_base: edfac05da6713f9513da7815233131a11b968e8826bf228616e0db014fe6ab7063be2a1a7972d098ac1f29b451fe3a9104b899200dda027d7c9de0bbcb626f85
15
+
16
+ test:
17
+ secret_key_base: ab202568aa57fcf882385c51274bd87fd4d1876f49a139292f0b1d45bfde284f3907d312bcea266e634eb8012ddc878f87b54b1ecd888999529a382aa41c17c3
18
+
19
+ # Do not keep production secrets in the repository,
20
+ # instead read values from the environment.
21
+ production:
22
+ secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
@@ -0,0 +1,6 @@
1
+ %w(
2
+ .ruby-version
3
+ .rbenv-vars
4
+ tmp/restart.txt
5
+ tmp/caching-dev.txt
6
+ ).each { |path| Spring.watch(path) }
@@ -0,0 +1,11 @@
1
+ class CreatePosts < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :posts do |t|
4
+ t.string :title
5
+ t.text :content
6
+ t.boolean :active
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,23 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # Note that this schema.rb definition is the authoritative source for your
6
+ # database schema. If you need to create the application database on another
7
+ # system, you should be using db:schema:load, not running all the migrations
8
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
10
+ #
11
+ # It's strongly recommended that you check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(version: 20170427011041) do
14
+
15
+ create_table "posts", force: :cascade do |t|
16
+ t.string "title"
17
+ t.text "content"
18
+ t.boolean "active"
19
+ t.datetime "created_at", null: false
20
+ t.datetime "updated_at", null: false
21
+ end
22
+
23
+ end
@@ -0,0 +1,7 @@
1
+ # This file should contain all the record creation needed to seed the database with its default values.
2
+ # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
3
+ #
4
+ # Examples:
5
+ #
6
+ # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
7
+ # Character.create(name: 'Luke', movie: movies.first)
File without changes
File without changes
@@ -0,0 +1,13 @@
1
+ <%%= simple_form_for(@<%= singular_table_name %>) do |f| %>
2
+ <%%= f.error_notification %>
3
+
4
+ <div class="form-inputs">
5
+ <%- attributes.each do |attribute| -%>
6
+ <%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> %>
7
+ <%- end -%>
8
+ </div>
9
+
10
+ <div class="form-actions">
11
+ <%%= f.button :submit %>
12
+ </div>
13
+ <%% end %>
data/example/log/.keep ADDED
File without changes
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>