Sha256: 2c4cbf2fe22aaee330249ee148346a1cce9b5690c51b2f88f2aab42346c2d1b9

Contents?: true

Size: 1.28 KB

Versions: 99

Compression:

Stored size: 1.28 KB

Contents

module Effective
  class FormLogic
    attr_accessor :args, :options

    delegate :object, to: :@builder
    delegate :capture, :content_tag, :link_to, :icon, to: :@template

    # So this takes in the options for an entire form group.
    def initialize(*args, builder:)
      @builder = builder
      @template = builder.template
      @options ||= {}

      validate!(args)
      @args = args
    end

    def validate!(args)
      raise 'expected one or more argument' if args.blank?
    end

    # https://github.com/rails/rails/blob/master/actionview/lib/action_view/helpers/tags/base.rb#L108
    def tag_name(name, multiple = false, index = nil)
      sanitized_method_name = name.to_s.sub(/\?$/, "")

      case
      when @builder.object_name.empty?
        "#{sanitized_method_name}#{multiple ? "[]" : ""}"
      when index
        "#{@builder.object_name}[#{index}][#{sanitized_method_name}]#{multiple ? "[]" : ""}"
      else
        "#{@builder.object_name}[#{sanitized_method_name}]#{multiple ? "[]" : ""}"
      end
    end

    def input_js_options
      { 'data-input-js-options' => JSON.generate({method_name: input_js_options_method_name}.merge(logic_options)) }
    end

    def input_js_options_method_name
      "effective_#{self.class.name.split('::').last.underscore}"
    end

  end
end

Version data entries

99 entries across 99 versions & 1 rubygems

Version Path
effective_bootstrap-0.6.25 app/models/effective/form_logic.rb
effective_bootstrap-0.6.24 app/models/effective/form_logic.rb
effective_bootstrap-0.6.23 app/models/effective/form_logic.rb
effective_bootstrap-0.6.22 app/models/effective/form_logic.rb
effective_bootstrap-0.6.21 app/models/effective/form_logic.rb
effective_bootstrap-0.6.20 app/models/effective/form_logic.rb
effective_bootstrap-0.6.19 app/models/effective/form_logic.rb
effective_bootstrap-0.6.18 app/models/effective/form_logic.rb
effective_bootstrap-0.6.17 app/models/effective/form_logic.rb
effective_bootstrap-0.6.16 app/models/effective/form_logic.rb
effective_bootstrap-0.6.15 app/models/effective/form_logic.rb
effective_bootstrap-0.6.14 app/models/effective/form_logic.rb
effective_bootstrap-0.6.13 app/models/effective/form_logic.rb
effective_bootstrap-0.6.12 app/models/effective/form_logic.rb
effective_bootstrap-0.6.11 app/models/effective/form_logic.rb
effective_bootstrap-0.6.10 app/models/effective/form_logic.rb
effective_bootstrap-0.6.9 app/models/effective/form_logic.rb
effective_bootstrap-0.6.8 app/models/effective/form_logic.rb
effective_bootstrap-0.6.7 app/models/effective/form_logic.rb
effective_bootstrap-0.6.6 app/models/effective/form_logic.rb