speedo-formstrap 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -1
- data/README.md +4 -4
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/speedo-formstrap/form_builder.rb +7 -5
- data/lib/speedo-formstrap/helpers.rb +3 -1
- data/lib/speedo-formstrap/helpers/buttons_helper.rb +13 -9
- data/lib/speedo-formstrap/helpers/fieldset_wrapper.rb +11 -6
- data/lib/speedo-formstrap/helpers/inputs_helper.rb +4 -4
- data/lib/speedo-formstrap/inputs/base.rb +2 -1
- data/lib/speedo-formstrap/inputs/base/choices.rb +12 -23
- data/lib/speedo-formstrap/inputs/base/labelling.rb +16 -6
- data/lib/speedo-formstrap/inputs/base/timeish.rb +5 -12
- data/lib/speedo-formstrap/inputs/base/wrapping.rb +32 -14
- data/lib/speedo-formstrap/inputs/number_input.rb +2 -2
- data/lib/speedo-formstrap/inputs/radio_input.rb +13 -12
- data/lib/speedo-formstrap/inputs/range_input.rb +2 -2
- data/spec/builder/semantic_fields_for_spec.rb +16 -16
- data/spec/helpers/buttons_helper_spec.rb +56 -46
- data/spec/helpers/input_helper_spec.rb +209 -209
- data/spec/helpers/inputs_helper_spec.rb +117 -103
- data/spec/inputs/boolean_input_spec.rb +74 -46
- data/spec/inputs/check_boxes_input_spec.rb +110 -82
- data/spec/inputs/date_input_spec.rb +81 -15
- data/spec/inputs/datetime_input_spec.rb +13 -13
- data/spec/inputs/email_input_spec.rb +34 -6
- data/spec/inputs/file_input_spec.rb +34 -6
- data/spec/inputs/hidden_input_spec.rb +41 -13
- data/spec/inputs/number_input_spec.rb +127 -97
- data/spec/inputs/password_input_spec.rb +34 -6
- data/spec/inputs/phone_input_spec.rb +34 -6
- data/spec/inputs/radio_input_spec.rb +73 -45
- data/spec/inputs/range_input_spec.rb +94 -66
- data/spec/inputs/search_input_spec.rb +33 -6
- data/spec/inputs/select_input_spec.rb +124 -78
- data/spec/inputs/string_input_spec.rb +67 -22
- data/spec/inputs/text_input_spec.rb +42 -15
- data/spec/inputs/time_input_spec.rb +23 -23
- data/spec/inputs/time_zone_input_spec.rb +20 -20
- data/spec/inputs/url_input_spec.rb +34 -6
- data/spec/support/custom_macros.rb +67 -196
- data/spec/support/formtastic_spec_helper.rb +22 -6
- data/speedo-formstrap.gemspec +2 -2
- metadata +17 -17
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -8,7 +8,7 @@ You can follow [FormBoot on twitter](http://twitter.com/FormBoot) for update ann
|
|
8
8
|
|
9
9
|
### Dependencies
|
10
10
|
|
11
|
-
|
11
|
+
Formtastic Bootstrap has only been tested with Ruby 1.9.2, Rails 3.1, Formtastic 2.0 and Twitter Bootstrap 1.3.
|
12
12
|
|
13
13
|
#### Installation
|
14
14
|
|
@@ -27,7 +27,7 @@ And install it with <tt>bundle install</tt>.
|
|
27
27
|
Add the following line to your Formtastic initialization file:
|
28
28
|
|
29
29
|
# config/initializers/formtastic.rb
|
30
|
-
Formtastic::Helpers::FormHelper.builder =
|
30
|
+
Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
|
31
31
|
|
32
32
|
Make sure the CSS `.hidden {display:none;}` is in your project.
|
33
33
|
|
@@ -75,7 +75,7 @@ made to generate the HTML expected by Bootstrap while still generating the rich
|
|
75
75
|
</fieldset>
|
76
76
|
</form>
|
77
77
|
|
78
|
-
####
|
78
|
+
#### Formtastic Bootstrap
|
79
79
|
|
80
80
|
<form accept-charset="UTF-8" action="/posts" class="formtastic post" id="new_post" method="post">
|
81
81
|
<fieldset class="inputs">
|
@@ -141,7 +141,7 @@ To create a Prepended Text field, use the ```:prepend``` option. This works on
|
|
141
141
|
|
142
142
|
### Contributors
|
143
143
|
|
144
|
-
A big thank you [to all contributors](https://github.com/mjbellantoni/
|
144
|
+
A big thank you [to all contributors](https://github.com/mjbellantoni/formtastic-bootstrap/contributors)!
|
145
145
|
|
146
146
|
### Submitting Issues
|
147
147
|
|
data/Rakefile
CHANGED
@@ -19,7 +19,7 @@ Jeweler::Tasks.new do |gem|
|
|
19
19
|
gem.license = "MIT"
|
20
20
|
gem.summary = %Q{Formtastic form builder to generate Twitter Bootstrap-friendly markup.}
|
21
21
|
gem.description = gem.summary
|
22
|
-
gem.email = "
|
22
|
+
gem.email = "stu@t.apio.ca"
|
23
23
|
gem.authors = ["Matthew Bellantoni", "Stu Basden"]
|
24
24
|
# dependencies defined in Gemfile
|
25
25
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.3
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module SpeedoFormstrap
|
2
|
-
|
2
|
+
|
3
3
|
class FormBuilder < Formtastic::FormBuilder
|
4
4
|
|
5
5
|
configure :default_inline_error_class, 'help-inline'
|
@@ -11,18 +11,18 @@ module SpeedoFormstrap
|
|
11
11
|
# self.default_inline_error_class
|
12
12
|
raise
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def self.default_error_class=(error_class)
|
16
16
|
# self.default_inline_error_class = error_class
|
17
17
|
# self.default_block_error_class = error_class
|
18
18
|
raise
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def self.default_hint_class
|
22
22
|
# self.default_inline_hint_class
|
23
23
|
raise
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def self.default_hint_class=(hint_class)
|
27
27
|
# self.default_inline_hint_class = hint_class
|
28
28
|
# self.default_block_hint_class = hint_class
|
@@ -32,7 +32,9 @@ module SpeedoFormstrap
|
|
32
32
|
include SpeedoFormstrap::Helpers::InputHelper
|
33
33
|
include SpeedoFormstrap::Helpers::InputsHelper
|
34
34
|
include SpeedoFormstrap::Helpers::ButtonsHelper
|
35
|
+
include SpeedoFormstrap::Helpers::ActionHelper
|
36
|
+
include SpeedoFormstrap::Helpers::ActionsHelper
|
35
37
|
|
36
38
|
end
|
37
39
|
|
38
|
-
end
|
40
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require "speedo-formstrap/helpers/buttons_helper"
|
2
2
|
require "speedo-formstrap/helpers/fieldset_wrapper"
|
3
|
+
require "speedo-formstrap/helpers/action_helper"
|
4
|
+
require "speedo-formstrap/helpers/actions_helper"
|
3
5
|
require "speedo-formstrap/helpers/input_helper"
|
4
6
|
require "speedo-formstrap/helpers/inputs_helper"
|
5
7
|
|
@@ -11,7 +13,7 @@ module SpeedoFormstrap
|
|
11
13
|
# autoload :FormHelper, 'formtastic/helpers/form_helper'
|
12
14
|
# autoload :InputHelper, 'formtastic/helpers/input_helper'
|
13
15
|
# autoload :InputsHelper, 'formtastic/helpers/inputs_helper'
|
14
|
-
# autoload :LabelHelper, 'formtastic/helpers/label_helper'
|
16
|
+
# autoload :LabelHelper, 'formtastic/helpers/label_helper'
|
15
17
|
# autoload :SemanticFormHelper, 'formtastic/helpers/semantic_form_helper'
|
16
18
|
# autoload :Reflection, 'formtastic/helpers/reflection'
|
17
19
|
end
|
@@ -5,10 +5,11 @@ module SpeedoFormstrap
|
|
5
5
|
include Formtastic::Helpers::ButtonsHelper
|
6
6
|
|
7
7
|
def buttons(*args, &block)
|
8
|
+
::ActiveSupport::Deprecation.warn("f.buttons is deprecated in favour of f.actions and will be removed from Formtastic after 2.1. Please see ActionsHelper and InputAction or ButtonAction for more information")
|
8
9
|
|
9
10
|
html_options = args.extract_options!
|
10
|
-
html_options[:class] ||= "actions"
|
11
|
-
|
11
|
+
html_options[:class] ||= "form-actions"
|
12
|
+
|
12
13
|
if html_options.has_key?(:name)
|
13
14
|
ActiveSupport::Deprecation.warn('The :name option is not supported')
|
14
15
|
end
|
@@ -16,7 +17,7 @@ module SpeedoFormstrap
|
|
16
17
|
if block_given?
|
17
18
|
template.content_tag(:div, html_options) do
|
18
19
|
yield
|
19
|
-
end
|
20
|
+
end
|
20
21
|
else
|
21
22
|
args = [:commit] if args.empty?
|
22
23
|
contents = args.map { |button_name| send(:"#{button_name}_button") }
|
@@ -28,25 +29,28 @@ module SpeedoFormstrap
|
|
28
29
|
end
|
29
30
|
|
30
31
|
def commit_button(*args)
|
32
|
+
::ActiveSupport::Deprecation.warn("f.commit_button is deprecated in favour of f.action(:submit) and will be removed from Formtastic after 2.1. Please see ActionsHelper and InputAction or ButtonAction for more information")
|
33
|
+
|
31
34
|
options = args.extract_options!
|
32
35
|
text = options.delete(:label) || args.shift
|
33
|
-
|
36
|
+
|
34
37
|
text = (localized_string(commit_button_i18n_key, text, :action, :model => commit_button_object_name) ||
|
35
38
|
Formtastic::I18n.t(commit_button_i18n_key, :model => commit_button_object_name)) unless text.is_a?(::String)
|
36
|
-
|
39
|
+
|
37
40
|
button_html = options.delete(:button_html) || {}
|
41
|
+
button_html[:id] ||= "#{@object_name}_submit"
|
38
42
|
button_html.merge!(:class => [button_html[:class], "btn commit", commit_button_i18n_key].compact.join(' '))
|
39
|
-
|
43
|
+
|
40
44
|
# TODO We don't have a wrapper. Add deprecation message.
|
41
45
|
# wrapper_html = options.delete(:wrapper_html) || {}
|
42
46
|
# wrapper_html[:class] = (commit_button_wrapper_html_class << wrapper_html[:class]).flatten.compact.join(' ')
|
43
|
-
|
47
|
+
|
44
48
|
accesskey = (options.delete(:accesskey) || default_commit_button_accesskey) unless button_html.has_key?(:accesskey)
|
45
49
|
button_html = button_html.merge(:accesskey => accesskey) if accesskey
|
46
|
-
|
50
|
+
|
47
51
|
Formtastic::Util.html_safe(submit(text, button_html))
|
48
52
|
end
|
49
53
|
|
50
54
|
end
|
51
55
|
end
|
52
|
-
end
|
56
|
+
end
|
@@ -3,17 +3,13 @@ module SpeedoFormstrap
|
|
3
3
|
module FieldsetWrapper
|
4
4
|
|
5
5
|
include Formtastic::Helpers::FieldsetWrapper
|
6
|
-
|
6
|
+
|
7
7
|
protected
|
8
8
|
|
9
9
|
def field_set_and_list_wrapping(*args, &block) #:nodoc:
|
10
10
|
contents = args.last.is_a?(::Hash) ? '' : args.pop.flatten
|
11
11
|
html_options = args.extract_options!
|
12
12
|
|
13
|
-
legend = (html_options[:name] || '').to_s
|
14
|
-
legend %= parent_child_index(html_options[:parent]) if html_options[:parent]
|
15
|
-
legend = template.content_tag(:legend, Formtastic::Util.html_safe(legend)) unless legend.blank?
|
16
|
-
|
17
13
|
if block_given?
|
18
14
|
contents = if template.respond_to?(:is_haml?) && template.is_haml?
|
19
15
|
template.capture_haml(&block)
|
@@ -24,6 +20,8 @@ module SpeedoFormstrap
|
|
24
20
|
|
25
21
|
# Ruby 1.9: String#to_s behavior changed, need to make an explicit join.
|
26
22
|
contents = contents.join if contents.respond_to?(:join)
|
23
|
+
|
24
|
+
legend = field_set_legend(html_options)
|
27
25
|
fieldset = template.content_tag(:fieldset,
|
28
26
|
Formtastic::Util.html_safe(legend) << Formtastic::Util.html_safe(contents),
|
29
27
|
html_options.except(:builder, :parent, :name)
|
@@ -32,6 +30,13 @@ module SpeedoFormstrap
|
|
32
30
|
fieldset
|
33
31
|
end
|
34
32
|
|
33
|
+
def field_set_legend(html_options)
|
34
|
+
legend = (html_options[:name] || '').to_s
|
35
|
+
legend %= parent_child_index(html_options[:parent]) if html_options[:parent]
|
36
|
+
legend = template.content_tag(:legend, Formtastic::Util.html_safe(legend)) unless legend.blank?
|
37
|
+
legend
|
38
|
+
end
|
39
|
+
|
35
40
|
end
|
36
41
|
end
|
37
|
-
end
|
42
|
+
end
|
@@ -6,7 +6,7 @@ module SpeedoFormstrap
|
|
6
6
|
def inputs(*args, &block)
|
7
7
|
wrap_it = @already_in_an_inputs_block ? true : false
|
8
8
|
@already_in_an_inputs_block = true
|
9
|
-
|
9
|
+
|
10
10
|
title = field_set_title_from_args(*args)
|
11
11
|
html_options = args.extract_options!
|
12
12
|
html_options[:class] ||= "inputs"
|
@@ -25,12 +25,12 @@ module SpeedoFormstrap
|
|
25
25
|
field_set_and_list_wrapping(*((args << html_options) << contents))
|
26
26
|
end
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
# out = template.content_tag(:li, out, :class => "input") if wrap_it
|
30
|
-
@already_in_an_inputs_block =
|
30
|
+
@already_in_an_inputs_block = wrap_it
|
31
31
|
out
|
32
32
|
end
|
33
33
|
|
34
34
|
end
|
35
35
|
end
|
36
|
-
end
|
36
|
+
end
|
@@ -3,6 +3,7 @@ require "speedo-formstrap/inputs/base/errors"
|
|
3
3
|
require "speedo-formstrap/inputs/base/hints"
|
4
4
|
require "speedo-formstrap/inputs/base/html"
|
5
5
|
require "speedo-formstrap/inputs/base/labelling"
|
6
|
+
require "speedo-formstrap/inputs/base/numeric"
|
6
7
|
require "speedo-formstrap/inputs/base/stringish"
|
7
8
|
require "speedo-formstrap/inputs/base/timeish"
|
8
9
|
require "speedo-formstrap/inputs/base/wrapping"
|
@@ -16,7 +17,7 @@ module SpeedoFormstrap
|
|
16
17
|
include Html
|
17
18
|
include Labelling
|
18
19
|
include Wrapping
|
19
|
-
|
20
|
+
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
@@ -5,45 +5,34 @@ module SpeedoFormstrap
|
|
5
5
|
|
6
6
|
def input_div_wrapping(&block)
|
7
7
|
template.content_tag(:div, choices_wrapping_html_options) do
|
8
|
-
[yield, error_html(:block), hint_html(:block)].join("\n").html_safe
|
8
|
+
[yield, error_html(:block), hint_html(:block)].join("\n").html_safe
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
def choices_wrapping_html_options
|
13
|
-
|
14
|
-
|
13
|
+
new_class = [super[:class], "controls"].compact.join(" ")
|
14
|
+
super.merge(:class => new_class)
|
15
15
|
end
|
16
16
|
|
17
|
-
def choices_group_wrapping(&block)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
def choices_group_wrapping_html_options
|
25
|
-
{ :class => "choices-group inputs-list" }
|
26
|
-
end
|
27
|
-
|
28
|
-
def choice_label(choice)
|
29
|
-
"\n".html_safe + template.content_tag(:span) do
|
30
|
-
# (choice.is_a?(Array) ? choice.first : choice).to_s
|
31
|
-
(choice.is_a?(Array) ? choice.first : choice).to_s
|
32
|
-
end
|
33
|
-
end
|
17
|
+
#def choices_group_wrapping(&block)
|
18
|
+
# template.content_tag(:ul,
|
19
|
+
# template.capture(&block),
|
20
|
+
# choices_group_wrapping_html_options
|
21
|
+
# )
|
22
|
+
#end
|
34
23
|
|
35
24
|
# This is actually a label in Bootstrap.
|
36
25
|
def legend_html
|
37
|
-
template.content_tag(:label,
|
26
|
+
template.content_tag(:label, control_label_html_options) do
|
38
27
|
render_label? ? label_text : "".html_safe
|
39
28
|
end
|
40
29
|
end
|
41
30
|
|
42
|
-
def
|
31
|
+
def control_label_html_options
|
43
32
|
super.merge(:for => nil)
|
44
33
|
end
|
45
34
|
|
46
35
|
end
|
47
36
|
end
|
48
37
|
end
|
49
|
-
end
|
38
|
+
end
|
@@ -5,14 +5,24 @@ module SpeedoFormstrap
|
|
5
5
|
|
6
6
|
include Formtastic::Inputs::Base::Labelling
|
7
7
|
|
8
|
+
def label_html
|
9
|
+
render_label? ? builder.label(input_name, label_text, control_label_html_options) : "".html_safe
|
10
|
+
end
|
11
|
+
|
8
12
|
def label_html_options
|
9
|
-
{}
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
+
opts = {}
|
14
|
+
opts[:for] ||= input_html_options[:id]
|
15
|
+
opts[:class] = [opts[:class]]
|
16
|
+
|
17
|
+
opts
|
13
18
|
end
|
14
|
-
|
19
|
+
|
20
|
+
def control_label_html_options
|
21
|
+
new_class = [label_html_options[:class], "control-label"].compact.join(" ")
|
22
|
+
label_html_options.merge(:class => new_class)
|
23
|
+
end
|
24
|
+
|
15
25
|
end
|
16
26
|
end
|
17
27
|
end
|
18
|
-
end
|
28
|
+
end
|
@@ -3,13 +3,6 @@ module SpeedoFormstrap
|
|
3
3
|
module Base
|
4
4
|
module Timeish
|
5
5
|
|
6
|
-
def label_html
|
7
|
-
# TODO Supress the "for" field?
|
8
|
-
template.content_tag(:label, label_html_options) do
|
9
|
-
render_label? ? label_text : "".html_safe
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
6
|
def date_input_html
|
14
7
|
fragment_input_html(:date, "small")
|
15
8
|
end
|
@@ -17,19 +10,19 @@ module SpeedoFormstrap
|
|
17
10
|
def time_input_html
|
18
11
|
fragment_input_html(:time, "mini")
|
19
12
|
end
|
20
|
-
|
13
|
+
|
21
14
|
def fragment_id(fragment)
|
22
15
|
# TODO is this right?
|
23
16
|
# "#{input_html_options[:id]}_#{position(fragment)}i"
|
24
17
|
"#{input_html_options[:id]}[#{fragment}]"
|
25
18
|
end
|
26
|
-
|
19
|
+
|
27
20
|
def fragment_input_html(fragment, klass)
|
28
|
-
opts = input_options.merge(:prefix =>
|
21
|
+
opts = input_options.merge(:prefix => fragment_prefix, :field_name => fragment_name(fragment), :default => value, :include_blank => include_blank?)
|
29
22
|
template.send(:"text_field_#{fragment}", value, opts, input_html_options.merge(:id => fragment_id(fragment), :class => klass))
|
30
23
|
end
|
31
|
-
|
24
|
+
|
32
25
|
end
|
33
26
|
end
|
34
27
|
end
|
35
|
-
end
|
28
|
+
end
|
@@ -6,23 +6,29 @@ module SpeedoFormstrap
|
|
6
6
|
include Formtastic::Inputs::Base::Wrapping
|
7
7
|
|
8
8
|
def generic_input_wrapping(&block)
|
9
|
-
|
9
|
+
control_group_div_wrapping do
|
10
10
|
label_html <<
|
11
11
|
input_div_wrapping do
|
12
|
-
|
12
|
+
if options[:prepend]
|
13
|
+
prepended_input_wrapping do
|
14
|
+
[template.content_tag(:span, options[:prepend], :class => 'add-on'), yield].join("\n").html_safe
|
15
|
+
end
|
16
|
+
else
|
17
|
+
yield
|
18
|
+
end
|
13
19
|
end
|
14
20
|
end
|
15
21
|
end
|
16
22
|
|
17
|
-
def
|
23
|
+
def control_group_div_wrapping(&block)
|
18
24
|
template.content_tag(:div, wrapper_html_options) do
|
19
25
|
yield
|
20
26
|
end
|
21
27
|
end
|
22
28
|
|
23
29
|
def input_div_wrapping(inline_or_block_errors = :inline)
|
24
|
-
template.content_tag(:div, :class => "
|
25
|
-
[yield, error_html(inline_or_block_errors), hint_html(inline_or_block_errors)].join("\n").html_safe
|
30
|
+
template.content_tag(:div, :class => "controls") do
|
31
|
+
[yield, error_html(inline_or_block_errors), hint_html(inline_or_block_errors)].join("\n").html_safe
|
26
32
|
end
|
27
33
|
end
|
28
34
|
|
@@ -33,24 +39,36 @@ module SpeedoFormstrap
|
|
33
39
|
end
|
34
40
|
|
35
41
|
def wrapper_html_options
|
36
|
-
opts = options[:wrapper_html] || {}
|
37
|
-
opts[:class]
|
38
|
-
|
39
|
-
|
40
|
-
|
42
|
+
opts = (options[:wrapper_html] || {}).dup
|
43
|
+
opts[:class] =
|
44
|
+
case opts[:class]
|
45
|
+
when Array
|
46
|
+
opts[:class].dup
|
47
|
+
when nil
|
48
|
+
[]
|
49
|
+
else
|
50
|
+
[opts[:class].to_s]
|
51
|
+
end
|
52
|
+
opts[:class] << "#{as}-wrapper"
|
53
|
+
opts[:class] << "control-group"
|
41
54
|
# opts[:class] << "input"
|
42
55
|
opts[:class] << "error" if errors?
|
43
56
|
opts[:class] << "optional" if optional?
|
44
57
|
opts[:class] << "required" if required?
|
45
58
|
opts[:class] << "autofocus" if autofocus?
|
46
59
|
opts[:class] = opts[:class].join(' ')
|
47
|
-
|
60
|
+
|
48
61
|
opts[:id] ||= wrapper_dom_id
|
49
|
-
|
62
|
+
|
50
63
|
opts
|
51
64
|
end
|
52
|
-
|
65
|
+
|
66
|
+
def prepended_input_wrapping(&block)
|
67
|
+
template.content_tag(:div, :class => 'input-prepend') do
|
68
|
+
yield
|
69
|
+
end
|
70
|
+
end
|
53
71
|
end
|
54
72
|
end
|
55
73
|
end
|
56
|
-
end
|
74
|
+
end
|