Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions recipes/simple_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,39 @@ module Recipes
class SimpleForm < Base

def gems
# Forms
@template.gem 'simple_form'
end

def init_file
@template.generate 'simple_form:install'
run_generators
add_sample_i18n
end

private

def run_generators
case ask_framework_for_forms
when 'marsman'
@template.initializer 'simple_form.rb', simple_form_template('marsman.rb')
when 'bootstrap'
@template.generate 'simple_form:install --bootstrap'
else
@template.generate 'simple_form:install'
end
end

def add_sample_i18n
@template.run 'rm config/locales/simple_form.en.yml'
@template.append_to_file 'config/locales/en.yml', simple_form_template('en.yml')
end

def ask_framework_for_forms
@template.ask('What framework do you want to use for your forms?',
limited_to: %w(marsman bootstrap default))
end

def simple_form_template(filename)
File.read(File.join(File.dirname(__FILE__), 'simple_form', filename))
end
end
end
20 changes: 20 additions & 0 deletions recipes/simple_form/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
### Simple form examples
# simple_form:
# placeholders:
# user:
# email: 'david.bowie@marsbased.com'
# labels:
# defaults:
# email: 'Email'
# user:
# email: 'Your email'
# options:
# user:
# role:
# admin: 'Administrator'
# prompts:
# user:
# role: 'Select a Role'
# hints:
# user:
# email: 'Must be a valid email'
41 changes: 41 additions & 0 deletions recipes/simple_form/marsman.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
SimpleForm.setup do |config|
config.wrappers :default, tag: 'div',
class: 'form-group',
error_class: :warning do |b|
b.use :html5
b.use :placeholder
b.use :maxlength
b.optional :pattern
b.optional :min_max
b.optional :readonly

b.use :label_input
b.use :hint, wrap_with: { tag: :div, class: 'info-field' }
b.use :error, wrap_with: { tag: :div, class: 'info-field' }
end

config.wrappers :inline_radio_and_checkbox, tag: 'div',
class: 'form-group',
error_class: 'warning' do |b|
b.use :html5
b.optional :readonly

b.use :label
b.use :input
end

config.default_wrapper = :default
config.wrapper_mappings = {
check_boxes: :inline_radio_and_checkbox,
radio_buttons: :inline_radio_and_checkbox
}

config.item_wrapper_tag = false
config.boolean_style = :inline
config.button_class = 'btn'
config.error_notification_tag = :div
config.error_notification_class = 'error_notification'
config.label_text = lambda { |label, _required, _explicit_label| label }
config.browser_validations = false
config.boolean_label_class = 'checkbox'
end