File: submit.rb

package info (click to toggle)
ruby-bootstrap-form 5.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 512 kB
  • sloc: ruby: 1,350; makefile: 4
file content (42 lines) | stat: -rw-r--r-- 1,105 bytes parent folder | download
1
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
module BootstrapForm
  module Inputs
    module Submit
      def button(value=nil, options={}, &block)
        value = setup_css_class "btn btn-secondary", value, options
        super
      end

      def submit(value=nil, options={})
        value = setup_css_class "btn btn-secondary", value, options
        layout == :inline ? form_group { super } : super
      end

      def primary(value=nil, options={}, &block)
        value = setup_css_class "btn btn-primary", value, options

        if options[:render_as_button] || block
          options.except! :render_as_button
          button(value, options, &block)
        else
          submit(value, options)
        end
      end

      private

      def setup_css_class(the_class, value, options)
        if value.is_a?(Hash)
          options.merge!(value)
          value = nil
        end
        unless options.key? :class
          if (extra_class = options.delete(:extra_class))
            the_class = "#{the_class} #{extra_class}"
          end
          options[:class] = the_class
        end
        value
      end
    end
  end
end