Sha256: f1368cb2615929877b546936acccada2fcb4935380e7769ab4add7d375c845c9

Contents?: true

Size: 1.84 KB

Versions: 51

Compression:

Stored size: 1.84 KB

Contents

class Bootstrap
  class Component
    class HorizontalForm < Form
      def left_col_width
        @child_args.last && @child_args.last[0] || 2
      end

      def right_col_width
        @child_args.last && @child_args.last[1] || 10
      end

      def_tag_method :form, "form-horizontal"

      def_tag_method :label, "control-label" do |opts, _extra_args|
        prepend_class opts, "col-sm-#{left_col_width}"
        opts
      end

      # def_div_method :input, nil do |opts, extra_args, &block|
      #   type, label = extra_args
      #   prepend { tag(:label, nil, for: opts[:id]) { label } } if label
      #   insert { inner_input opts.merge(type: type) }
      #   { class: "col-sm-#{right_col_width}" }
      # end

      def label_col label, id:
        @html.label label, for: id, class: "col-sm-#{left_col_width} control-label"
      end

      def input type, label:, id:, &block
        label_col label, id: id
        @html.div class: "col-sm-#{right_col_width}" do
          @html.input type: type, id: id, class: "form-control"
        end
        # block.call class: "col-sm-#{right_col_width}" do
        #   inner_input opts.merge(type: type)
        # end
      end

      def_tag_method :inner_input, "form-control", tag: :input
      def_div_method :inner_checkbox, "checkbox"

      def_div_method :checkbox, nil do |opts, extra_args|
        inner_checkbox do
          label do
            inner_input "checkbox", extra_args.first, opts
          end
        end
        { class: "col-sm-offset-#{left_col_width} col-sm-#{right_col_width}" }
      end

      def checkbox text, extra_args
        @html.div class: "col-sm-offset-#{left_col_width} col-sm-#{right_col_width}" do
          @html.div class: "checkbox" do
            label_cllabel do
              inner_input "checkbox"
            end
          end
        end
      end
    end
  end
end

Version data entries

51 entries across 51 versions & 2 rubygems

Version Path
card-mod-bootstrap-0.11.4 lib/bootstrap/component/horizontal_form.rb
card-mod-bootstrap-0.11.3 lib/bootstrap/component/horizontal_form.rb
card-mod-bootstrap-0.11.2 lib/bootstrap/component/horizontal_form.rb
card-mod-bootstrap-0.11.1 lib/bootstrap/component/horizontal_form.rb
card-mod-bootstrap-0.11.0 lib/bootstrap/component/horizontal_form.rb
card-1.100.0 mod/bootstrap/lib/bootstrap/component/horizontal_form.rb
card-1.99.6 mod/bootstrap/lib/bootstrap/component/horizontal_form.rb
card-1.99.5 mod/bootstrap/lib/bootstrap/component/horizontal_form.rb
card-1.99.4 mod/bootstrap/lib/bootstrap/component/horizontal_form.rb
card-1.99.3 mod/bootstrap/lib/bootstrap/component/horizontal_form.rb
card-1.99.2 mod/bootstrap/lib/bootstrap/component/horizontal_form.rb
card-1.99.1 mod/bootstrap/lib/bootstrap/component/horizontal_form.rb
card-1.99.0 mod/bootstrap/lib/bootstrap/component/horizontal_form.rb
card-1.98.3 mod/bootstrap/lib/bootstrap/component/horizontal_form.rb
card-1.98.2 mod/bootstrap/lib/bootstrap/component/horizontal_form.rb
card-1.98.1 mod/bootstrap/lib/bootstrap/component/horizontal_form.rb
card-1.98.0 mod/bootstrap/lib/bootstrap/component/horizontal_form.rb
card-1.97.0.1 mod/bootstrap/lib/bootstrap/component/horizontal_form.rb
card-1.97.0 mod/bootstrap/lib/bootstrap/component/horizontal_form.rb
card-1.96.8 mod/bootstrap/lib/bootstrap/component/horizontal_form.rb