Module: GovukAdminTemplate
- Defined in:
- lib/govuk_admin_template.rb,
lib/govuk_admin_template/config.rb,
lib/govuk_admin_template/engine.rb,
lib/govuk_admin_template/version.rb,
lib/govuk_admin_template/simple_form.rb,
lib/govuk_admin_template/view_helpers.rb,
app/controllers/govuk_admin_template/style_guide_controller.rb
Defined Under Namespace
Modules: Config, ViewHelpers Classes: ApplicationController, Engine, StyleGuideController
Constant Summary collapse
- VERSION =
"7.0.0".freeze
Class Method Summary collapse
- .configure {|Config| ... } ⇒ Object
- .environment_label ⇒ Object
- .environment_style ⇒ Object
- .setup_simple_form(config) ⇒ Object
Class Method Details
.configure {|Config| ... } ⇒ Object
2 3 4 |
# File 'lib/govuk_admin_template/config.rb', line 2 def self.configure yield(Config) end |
.environment_label ⇒ Object
14 15 16 |
# File 'lib/govuk_admin_template.rb', line 14 def self.environment_label @environment_label ||= ENV.fetch("GOVUK_ENVIRONMENT", "development").titleize end |
.environment_style ⇒ Object
10 11 12 |
# File 'lib/govuk_admin_template.rb', line 10 def self.environment_style @environment_style ||= ENV["GOVUK_ENVIRONMENT"] == "production" ? "production" : "preview" end |
.setup_simple_form(config) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/govuk_admin_template/simple_form.rb', line 2 def self.setup_simple_form(config) # Wrappers are used by the form builder to generate a complete input. # You can remove any component from the wrapper, change the order or # even add your own to the stack. # The options given below are used to wrap the whole input. config.wrappers :default, class: :input, hint_class: :field_with_hint, error_class: :field_with_errors do |b| # Determines whether to use HTML5 (:email, :url, ...) # and required attributes b.use :html5 # Calculates placeholders automatically from I18n # You can also pass a string as f.input placeholder: "Placeholder" b.use :placeholder ## Optional extensions # They are disabled unless you pass `f.input EXTENSION_NAME => :lookup` # to the input. If so, they will retrieve the values from the model # if any exists. If you want to enable the lookup for any of those # extensions by default, you can change `b.optional` to `b.use`. # Calculates maxlength from length validations for string inputs b.optional :maxlength # Calculates pattern from format validations for string inputs b.optional :pattern # Calculates min and max from length validations for numeric inputs b.optional :min_max # Calculates readonly automatically from readonly attributes b.optional :readonly ## Inputs b.use :label_input b.use :hint, wrap_with: { tag: :span, class: :hint } b.use :error, wrap_with: { tag: :span, class: :error } end config.wrappers :bootstrap, tag: "div", class: "form-group", error_class: "has-error" do |b| b.use :html5 b.use :placeholder b.use :label, class: "control-label" b.wrapper tag: "div" do |ba| ba.use :input ba.use :error, wrap_with: { tag: "span", class: "help-inline" } ba.use :hint, wrap_with: { tag: "p", class: "help-block" } end end config.wrappers :prepend, tag: "div", class: "form-group", error_class: "has-error" do |b| b.use :html5 b.use :placeholder b.use :label b.wrapper tag: "div", class: "controls" do |input| input.wrapper tag: "div", class: "input-prepend" do |prepend| prepend.use :input end input.use :hint, wrap_with: { tag: "span", class: "help-block" } input.use :error, wrap_with: { tag: "span", class: "help-inline" } end end config.wrappers :append, tag: "div", class: "form-group", error_class: "has-error" do |b| b.use :html5 b.use :placeholder b.use :label b.wrapper tag: "div", class: "controls" do |input| input.wrapper tag: "div", class: "input-append" do |append| append.use :input end input.use :hint, wrap_with: { tag: "span", class: "help-block" } input.use :error, wrap_with: { tag: "span", class: "help-inline" } end end # The default wrapper to be used by the FormBuilder. config.default_wrapper = :bootstrap # Define the way to render check boxes / radio buttons with labels. # Defaults to :nested for bootstrap config. # inline: input + label # nested: label > input config.boolean_style = :inline # Default class for buttons config. = "btn" # Default tag used for error notification helper. config.error_notification_tag = :div # CSS class to add for error notification helper. config.error_notification_class = "alert alert-danger" # Tell browsers whether to use default HTML5 validations (novalidate option). # Default is enabled. config.browser_validations = false end |