bootstrap_forms 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +3 -3
 - data/bootstrap_forms.gemspec +1 -1
 - data/lib/bootstrap_forms/form_builder.rb +36 -47
 - metadata +2 -2
 
    
        data/README.markdown
    CHANGED
    
    | 
         @@ -69,12 +69,12 @@ See description above... 
     | 
|
| 
       69 
69 
     | 
    
         
             
            = f.collection_radio_buttons :primary_category_id, Category.all, :id, :name
         
     | 
| 
       70 
70 
     | 
    
         
             
            ```
         
     | 
| 
       71 
71 
     | 
    
         | 
| 
       72 
     | 
    
         
            -
            Uneditable  
     | 
| 
      
 72 
     | 
    
         
            +
            Uneditable Input
         
     | 
| 
       73 
73 
     | 
    
         
             
            ----------------
         
     | 
| 
       74 
     | 
    
         
            -
            Bootstrap Forms adds another helper method that generates the necessary markup for uneditable  
     | 
| 
      
 74 
     | 
    
         
            +
            Bootstrap Forms adds another helper method that generates the necessary markup for uneditable inputs:
         
     | 
| 
       75 
75 
     | 
    
         | 
| 
       76 
76 
     | 
    
         
             
            ```haml
         
     | 
| 
       77 
     | 
    
         
            -
            = f. 
     | 
| 
      
 77 
     | 
    
         
            +
            = f.uneditable_input :name
         
     | 
| 
       78 
78 
     | 
    
         
             
            ```
         
     | 
| 
       79 
79 
     | 
    
         | 
| 
       80 
80 
     | 
    
         
             
            yields:
         
     | 
    
        data/bootstrap_forms.gemspec
    CHANGED
    
    | 
         @@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__) 
     | 
|
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
            Gem::Specification.new do |s|
         
     | 
| 
       5 
5 
     | 
    
         
             
              s.name        = "bootstrap_forms"
         
     | 
| 
       6 
     | 
    
         
            -
              s.version     = "1.0. 
     | 
| 
      
 6 
     | 
    
         
            +
              s.version     = "1.0.3"
         
     | 
| 
       7 
7 
     | 
    
         
             
              s.author      = "Seth Vargo"
         
     | 
| 
       8 
8 
     | 
    
         
             
              s.email       = "sethvargo@gmail.com"
         
     | 
| 
       9 
9 
     | 
    
         
             
              s.homepage    = "https://github.com/sethvargo/bootstrap_forms"
         
     | 
| 
         @@ -1,12 +1,12 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module BootstrapForms
         
     | 
| 
       2 
2 
     | 
    
         
             
              class FormBuilder < ActionView::Helpers::FormBuilder
         
     | 
| 
       3 
     | 
    
         
            -
                delegate :content_tag, :hidden_field_tag, :check_box_tag, :radio_button_tag, :link_to, :to => :@template
         
     | 
| 
      
 3 
     | 
    
         
            +
                delegate :content_tag, :hidden_field_tag, :check_box_tag, :radio_button_tag, :button_tag, :link_to, :to => :@template
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
                def error_messages
         
     | 
| 
       6 
6 
     | 
    
         
             
                  if object.errors.full_messages.any?
         
     | 
| 
       7 
     | 
    
         
            -
                    content_tag(:div, :class => 'alert alert-error') do
         
     | 
| 
       8 
     | 
    
         
            -
                      link_to('×'.html_safe, '#', {:class => 'close', :data => { :dismiss =>  
     | 
| 
       9 
     | 
    
         
            -
                      content_tag(: 
     | 
| 
      
 7 
     | 
    
         
            +
                    content_tag(:div, :class => 'alert alert-block alert-error') do
         
     | 
| 
      
 8 
     | 
    
         
            +
                      link_to('×'.html_safe, '#', {:class => 'close', :data => { :dismiss => 'alert' }}) +
         
     | 
| 
      
 9 
     | 
    
         
            +
                      content_tag(:h4, I18n.t('bootstrap_forms.errors.header', :model => object.class.model_name.humanize), :class => 'alert-heading') +
         
     | 
| 
       10 
10 
     | 
    
         
             
                      content_tag(:ul) do
         
     | 
| 
       11 
11 
     | 
    
         
             
                        object.errors.full_messages.map do |message|
         
     | 
| 
       12 
12 
     | 
    
         
             
                          content_tag(:li, message)
         
     | 
| 
         @@ -29,7 +29,7 @@ module BootstrapForms 
     | 
|
| 
       29 
29 
     | 
    
         
             
                    @options = args.extract_options!
         
     | 
| 
       30 
30 
     | 
    
         
             
                    @args = args
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
       32 
     | 
    
         
            -
                     
     | 
| 
      
 32 
     | 
    
         
            +
                    control_group_div do
         
     | 
| 
       33 
33 
     | 
    
         
             
                      label_field + input_div do
         
     | 
| 
       34 
34 
     | 
    
         
             
                        extras { super(name, *(@args << @options)) }
         
     | 
| 
       35 
35 
     | 
    
         
             
                      end
         
     | 
| 
         @@ -42,7 +42,7 @@ module BootstrapForms 
     | 
|
| 
       42 
42 
     | 
    
         
             
                  @options = args.extract_options!
         
     | 
| 
       43 
43 
     | 
    
         
             
                  @args = args
         
     | 
| 
       44 
44 
     | 
    
         | 
| 
       45 
     | 
    
         
            -
                   
     | 
| 
      
 45 
     | 
    
         
            +
                  control_group_div do
         
     | 
| 
       46 
46 
     | 
    
         
             
                    input_div do
         
     | 
| 
       47 
47 
     | 
    
         
             
                      label(@name, :class => [ 'checkbox', required_class ].compact.join(' ')) do
         
     | 
| 
       48 
48 
     | 
    
         
             
                        extras { super(name, *(@args << @options)) + object.class.human_attribute_name(name) }
         
     | 
| 
         @@ -56,23 +56,19 @@ module BootstrapForms 
     | 
|
| 
       56 
56 
     | 
    
         
             
                  @options = args.extract_options!
         
     | 
| 
       57 
57 
     | 
    
         
             
                  @args = args
         
     | 
| 
       58 
58 
     | 
    
         | 
| 
       59 
     | 
    
         
            -
                   
     | 
| 
       60 
     | 
    
         
            -
                    label_field +  
     | 
| 
       61 
     | 
    
         
            -
                       
     | 
| 
       62 
     | 
    
         
            -
                         
     | 
| 
       63 
     | 
    
         
            -
                           
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
                            content_tag(: 
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
                              end
         
     | 
| 
       71 
     | 
    
         
            -
                            end
         
     | 
| 
       72 
     | 
    
         
            -
                          end.join('').html_safe
         
     | 
| 
       73 
     | 
    
         
            -
                        end
         
     | 
| 
      
 59 
     | 
    
         
            +
                  control_group_div do
         
     | 
| 
      
 60 
     | 
    
         
            +
                    label_field + extras do
         
     | 
| 
      
 61 
     | 
    
         
            +
                      content_tag(:div, :class => 'controls') do
         
     | 
| 
      
 62 
     | 
    
         
            +
                        records.collect do |record|
         
     | 
| 
      
 63 
     | 
    
         
            +
                          element_id = "#{object_name}_#{attribute}_#{record.send(record_id)}"
         
     | 
| 
      
 64 
     | 
    
         
            +
                          checkbox = check_box_tag("#{object_name}[#{attribute}][]", record.send(record_id), [object.send(attribute)].flatten.include?(record.send(record_id)), @options.merge({:id => element_id}))
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                          content_tag(:label, :class => ['checkbox', ('inline' if @options[:inline])].compact.join(' ')) do
         
     | 
| 
      
 67 
     | 
    
         
            +
                            checkbox + content_tag(:span, record.send(record_name))
         
     | 
| 
      
 68 
     | 
    
         
            +
                          end
         
     | 
| 
      
 69 
     | 
    
         
            +
                        end.join('').html_safe
         
     | 
| 
       74 
70 
     | 
    
         
             
                      end
         
     | 
| 
       75 
     | 
    
         
            -
                    end 
     | 
| 
      
 71 
     | 
    
         
            +
                    end
         
     | 
| 
       76 
72 
     | 
    
         
             
                  end
         
     | 
| 
       77 
73 
     | 
    
         
             
                end
         
     | 
| 
       78 
74 
     | 
    
         | 
| 
         @@ -81,32 +77,28 @@ module BootstrapForms 
     | 
|
| 
       81 
77 
     | 
    
         
             
                  @options = args.extract_options!
         
     | 
| 
       82 
78 
     | 
    
         
             
                  @args = args
         
     | 
| 
       83 
79 
     | 
    
         | 
| 
       84 
     | 
    
         
            -
                   
     | 
| 
       85 
     | 
    
         
            -
                    label_field +  
     | 
| 
       86 
     | 
    
         
            -
                       
     | 
| 
       87 
     | 
    
         
            -
                         
     | 
| 
       88 
     | 
    
         
            -
                           
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
                            content_tag(: 
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
                              end
         
     | 
| 
       96 
     | 
    
         
            -
                            end
         
     | 
| 
       97 
     | 
    
         
            -
                          end.join('').html_safe
         
     | 
| 
       98 
     | 
    
         
            -
                        end
         
     | 
| 
      
 80 
     | 
    
         
            +
                  control_group_div do
         
     | 
| 
      
 81 
     | 
    
         
            +
                    label_field + extras do
         
     | 
| 
      
 82 
     | 
    
         
            +
                      content_tag(:div, :class => 'controls') do
         
     | 
| 
      
 83 
     | 
    
         
            +
                        records.collect do |record|
         
     | 
| 
      
 84 
     | 
    
         
            +
                          element_id = "#{object_name}_#{attribute}_#{record.send(record_id)}"
         
     | 
| 
      
 85 
     | 
    
         
            +
                          radiobutton = radio_button_tag("#{object_name}[#{attribute}][]", record.send(record_id), object.send(attribute) == record.send(record_id), @options.merge({:id => element_id}))
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
                          content_tag(:label, :class => ['radio', ('inline' if @options[:inline])].compact.join(' ')) do
         
     | 
| 
      
 88 
     | 
    
         
            +
                            radiobutton + content_tag(:span, record.send(record_name))
         
     | 
| 
      
 89 
     | 
    
         
            +
                          end
         
     | 
| 
      
 90 
     | 
    
         
            +
                        end.join('').html_safe
         
     | 
| 
       99 
91 
     | 
    
         
             
                      end
         
     | 
| 
       100 
92 
     | 
    
         
             
                    end
         
     | 
| 
       101 
93 
     | 
    
         
             
                  end
         
     | 
| 
       102 
94 
     | 
    
         
             
                end
         
     | 
| 
       103 
95 
     | 
    
         | 
| 
       104 
     | 
    
         
            -
                def  
     | 
| 
      
 96 
     | 
    
         
            +
                def uneditable_input(name, *args)
         
     | 
| 
       105 
97 
     | 
    
         
             
                  @name = name
         
     | 
| 
       106 
98 
     | 
    
         
             
                  @options = args.extract_options!
         
     | 
| 
       107 
99 
     | 
    
         
             
                  @args = args
         
     | 
| 
       108 
100 
     | 
    
         | 
| 
       109 
     | 
    
         
            -
                   
     | 
| 
      
 101 
     | 
    
         
            +
                  control_group_div do
         
     | 
| 
       110 
102 
     | 
    
         
             
                    label_field + input_div do
         
     | 
| 
       111 
103 
     | 
    
         
             
                      extras do
         
     | 
| 
       112 
104 
     | 
    
         
             
                        content_tag(:span, :class => 'uneditable-input') do
         
     | 
| 
         @@ -125,12 +117,12 @@ module BootstrapForms 
     | 
|
| 
       125 
117 
     | 
    
         
             
                  @options[:class] = 'btn btn-primary'
         
     | 
| 
       126 
118 
     | 
    
         | 
| 
       127 
119 
     | 
    
         
             
                  content_tag(:div, :class => 'form-actions') do
         
     | 
| 
       128 
     | 
    
         
            -
                    super(name, *(args << @options)) + ' ' +  
     | 
| 
      
 120 
     | 
    
         
            +
                    super(name, *(args << @options)) + ' ' + button_tag(I18n.t('bootstrap_forms.buttons.cancel'), :type => 'reset', :class => 'btn cancel')
         
     | 
| 
       129 
121 
     | 
    
         
             
                  end
         
     | 
| 
       130 
122 
     | 
    
         
             
                end
         
     | 
| 
       131 
123 
     | 
    
         | 
| 
       132 
124 
     | 
    
         
             
                private
         
     | 
| 
       133 
     | 
    
         
            -
                def  
     | 
| 
      
 125 
     | 
    
         
            +
                def control_group_div(&block)
         
     | 
| 
       134 
126 
     | 
    
         
             
                  @options[:error] = object.errors[@name].collect{|e| "#{@options[:label] || @name} #{e}".humanize}.join(', ') unless object.errors[@name].empty?
         
     | 
| 
       135 
127 
     | 
    
         | 
| 
       136 
128 
     | 
    
         
             
                  klasses = ['control-group']
         
     | 
| 
         @@ -155,15 +147,12 @@ module BootstrapForms 
     | 
|
| 
       155 
147 
     | 
    
         
             
                end
         
     | 
| 
       156 
148 
     | 
    
         | 
| 
       157 
149 
     | 
    
         
             
                def label_field(&block)
         
     | 
| 
       158 
     | 
    
         
            -
                  label(@name, block_given? ? block : @options[:label], :class => [ 
     | 
| 
      
 150 
     | 
    
         
            +
                  label(@name, block_given? ? block : @options[:label], :class => ['control-label', required_class].compact.join(' '))
         
     | 
| 
       159 
151 
     | 
    
         
             
                end
         
     | 
| 
       160 
152 
     | 
    
         | 
| 
       161 
153 
     | 
    
         
             
                def required_class
         
     | 
| 
       162 
     | 
    
         
            -
                  if object.class.validators_on(@name).any? { |v| v.kind_of? ActiveModel::Validations::PresenceValidator }
         
     | 
| 
       163 
     | 
    
         
            -
             
     | 
| 
       164 
     | 
    
         
            -
                  else
         
     | 
| 
       165 
     | 
    
         
            -
                    nil
         
     | 
| 
       166 
     | 
    
         
            -
                  end
         
     | 
| 
      
 154 
     | 
    
         
            +
                  'required' if object.class.validators_on(@name).any? { |v| v.kind_of? ActiveModel::Validations::PresenceValidator }
         
     | 
| 
      
 155 
     | 
    
         
            +
                  nil
         
     | 
| 
       167 
156 
     | 
    
         
             
                end
         
     | 
| 
       168 
157 
     | 
    
         | 
| 
       169 
158 
     | 
    
         
             
                %w(help_inline error success warning help_block append prepend).each do |method_name|
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: bootstrap_forms
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.0.3
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -9,7 +9,7 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2012-02- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2012-02-08 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       14 
14 
     | 
    
         
             
            description: Bootstrap Forms makes Twitter's Bootstrap on Rails easy to use by creating
         
     | 
| 
       15 
15 
     | 
    
         
             
              helpful form builders that minimize markup in your views.
         
     |