Sha256: fe02b633b1972a061ec3192a74a652b579e50dbeddaccf465c4befa16330a0c5

Contents?: true

Size: 1.04 KB

Versions: 6

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

# Creates a much prettier version of the file input field
class KepplerBooleanInput < SimpleForm::Inputs::Base
  def input(_wrapper_options)
    initializers
    template.content_tag(:label, '', class: 'keppler-switch') do
      input_switch + span_slider_round + label_switch
    end
  end

  def label_switch
    template.content_tag(
      :label,
      try_boolean.to_s,
      class: "inline-label #{'active' if try_boolean}"
    )
  end

  def input_switch
    template.tag(
      :input,
      class: ('active' if try_boolean),
      name: @input_name,
      type: 'checkbox',
      checked: true,
      value: try_boolean.to_s
    )
  end

  def span_slider_round
    template.content_tag(:span, '', class: 'slider round')
  end

  private

  def try_boolean
    object.try(attribute_name) ? true : false
  end

  protected

  def initializers
    @model = lookup_model_names.join('_')
    @attribute = reflection_or_attribute_name
    @input_id = "#{@model}_#{@attribute}"
    @input_name = "#{@model}[#{@attribute}]"
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
keppler-2.0.7 installer/core/app/inputs/keppler_boolean_input.rb
keppler-2.0.6 installer/core/app/inputs/keppler_boolean_input.rb
keppler-2.0.5 installer/core/app/inputs/keppler_boolean_input.rb
keppler-2.0.4.p1 installer/core/app/inputs/keppler_boolean_input.rb
keppler-2.0.4.pre.p1 installer/core/app/inputs/keppler_boolean_input.rb
keppler-2.0.4 installer/core/app/inputs/keppler_boolean_input.rb