Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.

Commit b46a191

Browse files
authored
Add marsman/boostrap/default styles for simple form (#38)
1 parent 63e4e90 commit b46a191

File tree

3 files changed

+90
-2
lines changed

3 files changed

+90
-2
lines changed

recipes/simple_form.rb

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,39 @@ module Recipes
22
class SimpleForm < Base
33

44
def gems
5-
# Forms
65
@template.gem 'simple_form'
76
end
87

98
def init_file
10-
@template.generate 'simple_form:install'
9+
run_generators
10+
add_sample_i18n
11+
end
12+
13+
private
14+
15+
def run_generators
16+
case ask_framework_for_forms
17+
when 'marsman'
18+
@template.initializer 'simple_form.rb', simple_form_template('marsman.rb')
19+
when 'bootstrap'
20+
@template.generate 'simple_form:install --bootstrap'
21+
else
22+
@template.generate 'simple_form:install'
23+
end
24+
end
25+
26+
def add_sample_i18n
27+
@template.run 'rm config/locales/simple_form.en.yml'
28+
@template.append_to_file 'config/locales/en.yml', simple_form_template('en.yml')
29+
end
30+
31+
def ask_framework_for_forms
32+
@template.ask('What framework do you want to use for your forms?',
33+
limited_to: %w(marsman bootstrap default))
34+
end
35+
36+
def simple_form_template(filename)
37+
File.read(File.join(File.dirname(__FILE__), 'simple_form', filename))
1138
end
1239
end
1340
end

recipes/simple_form/en.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
### Simple form examples
2+
# simple_form:
3+
# placeholders:
4+
# user:
5+
# email: 'david.bowie@marsbased.com'
6+
# labels:
7+
# defaults:
8+
# email: 'Email'
9+
# user:
10+
# email: 'Your email'
11+
# options:
12+
# user:
13+
# role:
14+
# admin: 'Administrator'
15+
# prompts:
16+
# user:
17+
# role: 'Select a Role'
18+
# hints:
19+
# user:
20+
# email: 'Must be a valid email'

recipes/simple_form/marsman.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
SimpleForm.setup do |config|
2+
config.wrappers :default, tag: 'div',
3+
class: 'form-group',
4+
error_class: :warning do |b|
5+
b.use :html5
6+
b.use :placeholder
7+
b.use :maxlength
8+
b.optional :pattern
9+
b.optional :min_max
10+
b.optional :readonly
11+
12+
b.use :label_input
13+
b.use :hint, wrap_with: { tag: :div, class: 'info-field' }
14+
b.use :error, wrap_with: { tag: :div, class: 'info-field' }
15+
end
16+
17+
config.wrappers :inline_radio_and_checkbox, tag: 'div',
18+
class: 'form-group',
19+
error_class: 'warning' do |b|
20+
b.use :html5
21+
b.optional :readonly
22+
23+
b.use :label
24+
b.use :input
25+
end
26+
27+
config.default_wrapper = :default
28+
config.wrapper_mappings = {
29+
check_boxes: :inline_radio_and_checkbox,
30+
radio_buttons: :inline_radio_and_checkbox
31+
}
32+
33+
config.item_wrapper_tag = false
34+
config.boolean_style = :inline
35+
config.button_class = 'btn'
36+
config.error_notification_tag = :div
37+
config.error_notification_class = 'error_notification'
38+
config.label_text = lambda { |label, _required, _explicit_label| label }
39+
config.browser_validations = false
40+
config.boolean_label_class = 'checkbox'
41+
end

0 commit comments

Comments
 (0)