formtastic-rails3 0.9.7 → 0.9.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/README.textile +23 -7
  2. data/Rakefile +27 -4
  3. data/generators/formtastic/templates/formtastic.css +9 -7
  4. data/generators/formtastic/templates/formtastic.rb +1 -1
  5. data/generators/formtastic/templates/formtastic_changes.css +4 -0
  6. data/lib/formtastic.rb +190 -142
  7. data/lib/formtastic/i18n.rb +8 -5
  8. data/lib/formtastic/railtie.rb +12 -0
  9. data/lib/formtastic/util.rb +35 -0
  10. data/lib/generators/formtastic/form/form_generator.rb +4 -3
  11. data/lib/generators/formtastic/install/install_generator.rb +2 -1
  12. data/rails/init.rb +5 -0
  13. data/spec/buttons_spec.rb +25 -8
  14. data/spec/commit_button_spec.rb +88 -64
  15. data/spec/custom_builder_spec.rb +1 -1
  16. data/spec/custom_macros.rb +67 -26
  17. data/spec/error_proc_spec.rb +1 -1
  18. data/spec/errors_spec.rb +21 -1
  19. data/spec/form_helper_spec.rb +47 -15
  20. data/spec/i18n_spec.rb +40 -19
  21. data/spec/include_blank_spec.rb +9 -5
  22. data/spec/input_spec.rb +224 -76
  23. data/spec/inputs/boolean_input_spec.rb +22 -11
  24. data/spec/inputs/check_boxes_input_spec.rb +103 -11
  25. data/spec/inputs/country_input_spec.rb +46 -8
  26. data/spec/inputs/date_input_spec.rb +80 -55
  27. data/spec/inputs/datetime_input_spec.rb +134 -83
  28. data/spec/inputs/file_input_spec.rb +4 -3
  29. data/spec/inputs/hidden_input_spec.rb +17 -3
  30. data/spec/inputs/numeric_input_spec.rb +3 -3
  31. data/spec/inputs/password_input_spec.rb +3 -3
  32. data/spec/inputs/radio_input_spec.rb +28 -11
  33. data/spec/inputs/select_input_spec.rb +122 -46
  34. data/spec/inputs/string_input_spec.rb +3 -3
  35. data/spec/inputs/text_input_spec.rb +4 -3
  36. data/spec/inputs/time_input_spec.rb +109 -53
  37. data/spec/inputs/time_zone_input_spec.rb +15 -7
  38. data/spec/inputs_spec.rb +85 -39
  39. data/spec/label_spec.rb +1 -1
  40. data/spec/layout_helper_spec.rb +5 -16
  41. data/spec/semantic_errors_spec.rb +7 -7
  42. data/spec/semantic_fields_for_spec.rb +5 -4
  43. data/spec/spec_helper.rb +102 -36
  44. metadata +11 -14
  45. data/lib/generators/formtastic/form/templates/_form.html.erb +0 -5
  46. data/lib/generators/formtastic/form/templates/_form.html.haml +0 -4
  47. data/lib/generators/formtastic/install/templates/formtastic.css +0 -144
  48. data/lib/generators/formtastic/install/templates/formtastic.rb +0 -58
  49. data/lib/generators/formtastic/install/templates/formtastic_changes.css +0 -10
  50. data/spec/inputs/currency_input_spec.rb +0 -80
@@ -1,5 +0,0 @@
1
- <%% f.inputs do %>
2
- <% columns.each do |column| -%>
3
- <%%= f.input :<%= column.name %>, :label => '<%= column.name.humanize %>' %>
4
- <% end -%>
5
- <%% end %>
@@ -1,4 +0,0 @@
1
- - f.inputs do
2
- <% columns.each do |column| -%>
3
- = f.input :<%= column.name %>, :label => '<%= column.name.humanize %>'
4
- <% end -%>
@@ -1,144 +0,0 @@
1
- /* -------------------------------------------------------------------------------------------------
2
-
3
- It's *strongly* suggested that you don't modify this file. Instead, load a new stylesheet after
4
- this one in your layouts (eg formtastic_changes.css) and override the styles to suit your needs.
5
- This will allow you to update formtastic.css with new releases without clobbering your own changes.
6
-
7
- This stylesheet forms part of the Formtastic Rails Plugin
8
- (c) 2008 Justin French
9
-
10
- --------------------------------------------------------------------------------------------------*/
11
-
12
-
13
- /* NORMALIZE AND RESET - obviously inspired by Yahoo's reset.css, but scoped to just form.formtastic
14
- --------------------------------------------------------------------------------------------------*/
15
- form.formtastic, form.formtastic ul, form.formtastic ol, form.formtastic li, form.formtastic fieldset, form.formtastic legend, form.formtastic input, form.formtastic textarea, form.formtastic select, form.formtastic p { margin:0; padding:0; }
16
- form.formtastic fieldset { border:0; }
17
- form.formtastic em, form.formtastic strong { font-style:normal; font-weight:normal; }
18
- form.formtastic ol, form.formtastic ul { list-style:none; }
19
- form.formtastic abbr, form.formtastic acronym { border:0; font-variant:normal; }
20
- form.formtastic input, form.formtastic textarea, form.formtastic select { font-family:inherit; font-size:inherit; font-weight:inherit; }
21
- form.formtastic input, form.formtastic textarea, form.formtastic select { font-size:100%; }
22
- form.formtastic legend { color:#000; }
23
-
24
-
25
- /* SEMANTIC ERRORS
26
- --------------------------------------------------------------------------------------------------*/
27
- form.formtastic ul.errors { color:#cc0000; margin:0.5em 0 1.5em 25%; list-style:square; }
28
- form.formtastic ul.errors li { padding:0; border:none; display:list-item; }
29
-
30
-
31
- /* FIELDSETS & LISTS
32
- --------------------------------------------------------------------------------------------------*/
33
- form.formtastic fieldset { }
34
- form.formtastic fieldset.inputs { }
35
- form.formtastic fieldset.buttons { padding-left:25%; }
36
- form.formtastic fieldset ol { }
37
- form.formtastic fieldset.buttons li { float:left; padding-right:0.5em; }
38
-
39
- /* clearfixing the fieldsets */
40
- form.formtastic fieldset { display: inline-block; }
41
- form.formtastic fieldset:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
42
- html[xmlns] form.formtastic fieldset { display: block; }
43
- * html form.formtastic fieldset { height: 1%; }
44
-
45
-
46
- /* INPUT LIs
47
- --------------------------------------------------------------------------------------------------*/
48
- form.formtastic fieldset ol li { margin-bottom:1.5em; }
49
-
50
- /* clearfixing the li's */
51
- form.formtastic fieldset ol li { display: inline-block; }
52
- form.formtastic fieldset ol li:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
53
- html[xmlns] form.formtastic fieldset ol li { display: block; }
54
- * html form.formtastic fieldset ol li { height: 1%; }
55
-
56
- form.formtastic fieldset ol li.required { }
57
- form.formtastic fieldset ol li.optional { }
58
- form.formtastic fieldset ol li.error { }
59
-
60
-
61
- /* LABELS
62
- --------------------------------------------------------------------------------------------------*/
63
- form.formtastic fieldset ol li label { display:block; width:25%; float:left; padding-top:.2em; }
64
- form.formtastic fieldset ol li li label { line-height:100%; padding-top:0; }
65
- form.formtastic fieldset ol li li label input { line-height:100%; vertical-align:middle; margin-top:-0.1em;}
66
-
67
-
68
- /* NESTED FIELDSETS AND LEGENDS (radio, check boxes and date/time inputs use nested fieldsets)
69
- --------------------------------------------------------------------------------------------------*/
70
- form.formtastic fieldset ol li fieldset { position:relative; }
71
- form.formtastic fieldset ol li fieldset legend { position:absolute; width:25%; padding-top:0.1em; }
72
- form.formtastic fieldset ol li fieldset legend span { position:absolute; }
73
- form.formtastic fieldset ol li fieldset legend.label label { position:absolute; }
74
- form.formtastic fieldset ol li fieldset ol { float:left; width:74%; margin:0; padding:0 0 0 25%; }
75
- form.formtastic fieldset ol li fieldset ol li { padding:0; border:0; }
76
-
77
-
78
- /* INLINE HINTS
79
- --------------------------------------------------------------------------------------------------*/
80
- form.formtastic fieldset ol li p.inline-hints { color:#666; margin:0.5em 0 0 25%; }
81
-
82
-
83
- /* INLINE ERRORS
84
- --------------------------------------------------------------------------------------------------*/
85
- form.formtastic fieldset ol li p.inline-errors { color:#cc0000; margin:0.5em 0 0 25%; }
86
- form.formtastic fieldset ol li ul.errors { color:#cc0000; margin:0.5em 0 0 25%; list-style:square; }
87
- form.formtastic fieldset ol li ul.errors li { padding:0; border:none; display:list-item; }
88
-
89
-
90
- /* STRING & NUMERIC OVERRIDES
91
- --------------------------------------------------------------------------------------------------*/
92
- form.formtastic fieldset ol li.string input { width:74%; }
93
- form.formtastic fieldset ol li.password input { width:74%; }
94
- form.formtastic fieldset ol li.numeric input { width:74%; }
95
-
96
-
97
- /* TEXTAREA OVERRIDES
98
- --------------------------------------------------------------------------------------------------*/
99
- form.formtastic fieldset ol li.text textarea { width:74%; }
100
-
101
-
102
- /* HIDDEN OVERRIDES
103
- --------------------------------------------------------------------------------------------------*/
104
- form.formtastic fieldset ol li.hidden { display:none; }
105
-
106
-
107
- /* BOOLEAN OVERRIDES
108
- --------------------------------------------------------------------------------------------------*/
109
- form.formtastic fieldset ol li.boolean label { padding-left:25%; width:auto; }
110
- form.formtastic fieldset ol li.boolean label input { margin:0 0.5em 0 0.2em; }
111
-
112
-
113
- /* RADIO OVERRIDES
114
- --------------------------------------------------------------------------------------------------*/
115
- form.formtastic fieldset ol li.radio { }
116
- form.formtastic fieldset ol li.radio fieldset ol { margin-bottom:-0.6em; }
117
- form.formtastic fieldset ol li.radio fieldset ol li { margin:0.1em 0 0.5em 0; }
118
- form.formtastic fieldset ol li.radio fieldset ol li label { float:none; width:100%; }
119
- form.formtastic fieldset ol li.radio fieldset ol li label input { margin-right:0.2em; }
120
-
121
-
122
- /* CHECK BOXES (COLLECTION) OVERRIDES
123
- --------------------------------------------------------------------------------------------------*/
124
- form.formtastic fieldset ol li.check_boxes { }
125
- form.formtastic fieldset ol li.check_boxes fieldset ol { margin-bottom:-0.6em; }
126
- form.formtastic fieldset ol li.check_boxes fieldset ol li { margin:0.1em 0 0.5em 0; }
127
- form.formtastic fieldset ol li.check_boxes fieldset ol li label { float:none; width:100%; }
128
- form.formtastic fieldset ol li.check_boxes fieldset ol li label input { margin-right:0.2em; }
129
-
130
-
131
-
132
- /* DATE & TIME OVERRIDES
133
- --------------------------------------------------------------------------------------------------*/
134
- form.formtastic fieldset ol li.date fieldset ol li,
135
- form.formtastic fieldset ol li.time fieldset ol li,
136
- form.formtastic fieldset ol li.datetime fieldset ol li { float:left; width:auto; margin:0 .3em 0 0; }
137
-
138
- form.formtastic fieldset ol li.date fieldset ol li label,
139
- form.formtastic fieldset ol li.time fieldset ol li label,
140
- form.formtastic fieldset ol li.datetime fieldset ol li label { display:none; }
141
-
142
- form.formtastic fieldset ol li.date fieldset ol li label input,
143
- form.formtastic fieldset ol li.time fieldset ol li label input,
144
- form.formtastic fieldset ol li.datetime fieldset ol li label input { display:inline; margin:0; padding:0; }
@@ -1,58 +0,0 @@
1
- # Set the default text field size when input is a string. Default is 50.
2
- # Formtastic::SemanticFormBuilder.default_text_field_size = 50
3
-
4
- # Set the default text area height when input is a text. Default is 20.
5
- # Formtastic::SemanticFormBuilder.default_text_area_height = 5
6
-
7
- # Should all fields be considered "required" by default?
8
- # Defaults to true, see ValidationReflection notes below.
9
- # Formtastic::SemanticFormBuilder.all_fields_required_by_default = true
10
-
11
- # Should select fields have a blank option/prompt by default?
12
- # Defaults to true.
13
- # Formtastic::SemanticFormBuilder.include_blank_for_select_by_default = true
14
-
15
- # Set the string that will be appended to the labels/fieldsets which are required
16
- # It accepts string or procs and the default is a localized version of
17
- # '<abbr title="required">*</abbr>'. In other words, if you configure formtastic.required
18
- # in your locale, it will replace the abbr title properly. But if you don't want to use
19
- # abbr tag, you can simply give a string as below
20
- # Formtastic::SemanticFormBuilder.required_string = "(required)"
21
-
22
- # Set the string that will be appended to the labels/fieldsets which are optional
23
- # Defaults to an empty string ("") and also accepts procs (see required_string above)
24
- # Formtastic::SemanticFormBuilder.optional_string = "(optional)"
25
-
26
- # Set the way inline errors will be displayed.
27
- # Defaults to :sentence, valid options are :sentence, :list and :none
28
- # Formtastic::SemanticFormBuilder.inline_errors = :sentence
29
-
30
- # Set the method to call on label text to transform or format it for human-friendly
31
- # reading when formtastic is user without object. Defaults to :humanize.
32
- # Formtastic::SemanticFormBuilder.label_str_method = :humanize
33
-
34
- # Set the array of methods to try calling on parent objects in :select and :radio inputs
35
- # for the text inside each @<option>@ tag or alongside each radio @<input>@. The first method
36
- # that is found on the object will be used.
37
- # Defaults to ["to_label", "display_name", "full_name", "name", "title", "username", "login", "value", "to_s"]
38
- # Formtastic::SemanticFormBuilder.collection_label_methods = [
39
- # "to_label", "display_name", "full_name", "name", "title", "username", "login", "value", "to_s"]
40
-
41
- # Formtastic by default renders inside li tags the input, hints and then
42
- # errors messages. Sometimes you want the hints to be rendered first than
43
- # the input, in the following order: hints, input and errors. You can
44
- # customize it doing just as below:
45
- # Formtastic::SemanticFormBuilder.inline_order = [:input, :hints, :errors]
46
-
47
- # Formtastic by default renders inside li tags you can customize it to render
48
- # with div tags if required
49
- # Formtastic::SemanticFormBuilder.item_separator = :div
50
-
51
- # Specifies if labels/hints for input fields automatically be looked up using I18n.
52
- # Default value: false. Overridden for specific fields by setting value to true,
53
- # i.e. :label => true, or :hint => true (or opposite depending on initialized value)
54
- # Formtastic::SemanticFormBuilder.i18n_lookups_by_default = false
55
-
56
- # You can add custom inputs or override parts of Formtastic by subclassing SemanticFormBuilder and
57
- # specifying that class here. Defaults to SemanticFormBuilder.
58
- # Formtastic::SemanticFormHelper.builder = MyCustomBuilder
@@ -1,10 +0,0 @@
1
- /* -------------------------------------------------------------------------------------------------
2
-
3
- Load this stylesheet after formtastic.css in your layouts to override the CSS to suit your needs.
4
- This will allow you to update formtastic.css with new releases without clobbering your own changes.
5
-
6
- For example, to make the inline hint paragraphs a little darker in color than the standard #666:
7
-
8
- form.formtastic fieldset ol li p.inline-hints { color:#333; }
9
-
10
- --------------------------------------------------------------------------------------------------*/
@@ -1,80 +0,0 @@
1
- # coding: utf-8
2
- require File.dirname(__FILE__) + '/../spec_helper'
3
-
4
- describe 'currency input' do
5
-
6
- include FormtasticSpecHelper
7
-
8
- before do
9
- @output_buffer = ActiveSupport::SafeBuffer.new
10
- mock_everything
11
- end
12
-
13
- describe "when currency_select is not available as a helper from a plugin" do
14
-
15
- it "should raise an error, sugesting the author installs a plugin" do
16
- lambda {
17
- semantic_form_for(@new_post) do |builder|
18
- concat(builder.input(:currency, :as => :currency))
19
- end
20
- }.should raise_error
21
- end
22
-
23
- end
24
-
25
- describe "when currency_select is available as a helper (from a plugin)" do
26
-
27
- before do
28
- semantic_form_for(@new_post) do |builder|
29
- builder.stub!(:currency_select).and_return(ActiveSupport::SafeBuffer.new("<select><option>...</option></select>"))
30
- concat(builder.input(:currency, :as => :currency))
31
- end
32
- end
33
-
34
- it_should_have_input_wrapper_with_class("currency")
35
- it_should_have_input_wrapper_with_id("post_currency_input")
36
-
37
- # TODO -- needs stubbing inside the builder block, tricky!
38
- #it_should_apply_error_logic_for_input_type(:currency)
39
-
40
- it 'should generate a label for the input' do
41
- output_buffer.should have_tag('form li label')
42
- output_buffer.should have_tag('form li label[@for="post_currency"]')
43
- output_buffer.should have_tag('form li label', /Currency/)
44
- end
45
-
46
- it "should generate a select" do
47
- output_buffer.should have_tag("form li select")
48
- end
49
-
50
- end
51
-
52
- describe ":priority_currencies option" do
53
-
54
- it "should be passed down to the currency_select helper when provided" do
55
- priority_currencies = ["Foo", "Bah"]
56
- semantic_form_for(@new_post) do |builder|
57
- builder.stub!(:currency_select).and_return(ActiveSupport::SafeBuffer.new("<select><option>...</option></select>"))
58
- builder.should_receive(:currency_select).with(:currency, priority_currencies, {}, {}).and_return("<select><option>...</option></select>")
59
-
60
- concat(builder.input(:currency, :as => :currency, :priority_currencies => priority_currencies))
61
- end
62
- end
63
-
64
- it "should default to the @@priority_currencies config when absent" do
65
- priority_currencies = ::Formtastic::SemanticFormBuilder.priority_currencies
66
- priority_currencies.should_not be_empty
67
- priority_currencies.should_not be_nil
68
-
69
- semantic_form_for(@new_post) do |builder|
70
- builder.stub!(:currency_select).and_return("<select><option>...</option></select>")
71
- builder.should_receive(:currency_select).with(:currency, priority_currencies, {}, {}).and_return("<select><option>...</option></select>")
72
-
73
- concat(builder.input(:currency, :as => :currency))
74
- end
75
- end
76
-
77
- end
78
-
79
- end
80
-