drogus-merb-sexy-forms 0.0.3 → 0.0.4

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/Rakefile CHANGED
@@ -10,7 +10,7 @@ require "spec/rake/spectask"
10
10
  require 'lib/merb-sexy-forms/merbtasks.rb'
11
11
 
12
12
  GEM_NAME = "merb-sexy-forms"
13
- GEM_VERSION = "0.0.3"
13
+ GEM_VERSION = "0.0.4"
14
14
  AUTHOR = "Piotr Sarnacki"
15
15
  EMAIL = "drogus@gmail.com"
16
16
  HOMEPAGE = ""
@@ -28,7 +28,7 @@ spec = Gem::Specification.new do |s|
28
28
  s.author = AUTHOR
29
29
  s.email = EMAIL
30
30
  s.homepage = HOMEPAGE
31
- s.add_dependency('merb', '>= 1.0.6.1')
31
+ s.add_dependency('merb', '>= 1.0.7.1')
32
32
  s.require_path = 'lib'
33
33
  s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec,assets}/**/*")
34
34
 
data/TODO CHANGED
@@ -1 +1,5 @@
1
1
  TODO:
2
+ Add :required option.
3
+ Add :description option - probably provided also with block to easily add more text
4
+ Add error support - displaying errors "near" fields and error class in containers with fields with error.
5
+
@@ -3,7 +3,7 @@ if defined?(Merb::Plugins)
3
3
 
4
4
  # Merb gives you a Merb::Plugins.config hash...feel free to put your stuff in your piece of it
5
5
  Merb::Plugins.config[:merb_sexy_forms] = {
6
- :chickens => false
6
+ :container_tag => "li"
7
7
  }
8
8
 
9
9
  Merb::BootLoader.before_app_loads do
@@ -17,4 +17,4 @@ if defined?(Merb::Plugins)
17
17
  end
18
18
 
19
19
  Merb::Plugins.add_rakefiles "merb-sexy-forms/merbtasks"
20
- end
20
+ end
@@ -2,98 +2,108 @@ module Merb::Helpers::SexyForm
2
2
  module Builder
3
3
  class Base < Merb::Helpers::Form::Builder::ResourcefulFormWithErrors
4
4
  def form(attrs = {}, &blk)
5
- ul_options = attrs.delete(:ul)
6
5
  add_css_class(attrs, "sexy")
7
6
  super(attrs) do
8
7
  captured = @origin.capture(&blk)
9
- tag(:ul, captured, ul_options)
8
+ add_main_container(captured, attrs)
10
9
  end
11
10
  end
12
11
 
13
- def wrap_with_container(attrs = {}, content = "")
14
- li = attrs.delete(:li)
15
- container = attrs.delete(:container)
16
-
17
- first = attrs.delete(:first)
18
- method = attrs.delete(:method)
19
-
20
- if first && (attrs[:id] || method)
21
- if method
22
- id = method ? "#{@name}_#{method}" : attrs[:id]
23
- end
24
- label_id = "#{id}_#{first[:value]}"
25
- else
26
- label_id = attrs[:id]
27
- end
28
-
29
- label = attrs.delete(:label)
30
- if label && !label.is_a?(Hash)
31
- label = {:label => {:title => label}}
32
- end
33
- if label.is_a?(Hash)
34
- label[:label].merge!({:class => "main", :for => label_id})
35
- end
36
- label = label(label)
37
-
38
- if container == false
39
- content = label + content
12
+ def add_main_container(content, attrs)
13
+ ul_options = attrs.delete(:ul)
14
+ if Merb::Plugins.config[:merb_sexy_forms][:container_tag] == "li"
15
+ tag(:ul, content, ul_options)
40
16
  else
41
- content = label + tag(:div, content, container)
42
- end
43
-
44
- if li == false
45
17
  content
46
- else
47
- li = li || {}
48
- li.merge!(:id => "#{attrs[:id]}_container") if attrs[:id] and li[:id].blank?
49
- tag(:li, content, li)
50
18
  end
51
19
  end
52
20
 
21
+ def wrap_with_container(attrs = {}, content = "")
22
+ content = add_html_to_field(content, attrs)
23
+ content = add_field_wrapper(content, attrs)
24
+ content = add_main_label(content, attrs)
25
+ content = add_container(content, attrs)
26
+ end
27
+
28
+
53
29
  %w(text password file).each do |kind|
54
30
  self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
55
- def unbound_#{kind}_field(attrs = {})
31
+ def unbound_#{kind}_field(attrs = {}, &blk)
32
+ yield(attrs) if block_given?
56
33
  label = attrs.delete(:label)
57
34
  wrap_with_container(attrs.merge(:label => label), super(clean_args!(attrs)))
58
35
  end
36
+
37
+ def bound_#{kind}_field(method, attrs = {}, &blk)
38
+ yield(attrs) if block_given?
39
+ super
40
+ end
59
41
  RUBY
60
42
  end
61
43
 
62
44
  def unbound_check_box(attrs = {})
45
+ yield(attrs) if block_given?
63
46
  update_label_options(attrs, "radio")
64
47
  wrap_with_container(attrs.merge(:label => nil),
65
48
  super(clean_args!(attrs)))
66
49
  end
67
50
 
51
+ def bound_check_box(method, attrs = {}, &blk)
52
+ yield(attrs) if block_given?
53
+ super
54
+ end
55
+
68
56
  def unbound_radio_button(attrs = {})
57
+ yield(attrs) if block_given?
69
58
  update_label_options(attrs, "radio")
70
59
  wrap_with_container(attrs.merge(:label => nil),
71
60
  super(clean_args!(attrs)))
72
61
  end
73
62
 
63
+ def bound_radio_button(method, attrs = {}, &blk)
64
+ yield(attrs) if block_given?
65
+ super
66
+ end
67
+
74
68
  def bound_radio_group(method, arr, global_attrs = {})
69
+ yield(attrs) if block_given?
75
70
  first = arr.first
76
71
  wrap_with_container(global_attrs.merge(:first => first, :method => method), super(method, arr))
77
72
  end
78
73
 
79
74
  def unbound_radio_group(arr, global_attrs = {})
75
+ yield(attrs) if block_given?
80
76
  wrap_with_container(global_attrs, super(arr))
81
77
  end
82
78
 
83
79
  def unbound_select(attrs = {})
80
+ yield(attrs) if block_given?
84
81
  wrap_with_container(attrs, super(clean_args!(attrs)))
85
82
  end
86
83
 
84
+ def bound_select(method, attrs = {}, &blk)
85
+ yield(attrs) if block_given?
86
+ super
87
+ end
88
+
87
89
  def unbound_text_area(contents, attrs = {})
90
+ yield(attrs) if block_given?
88
91
  label = attrs.delete(:label)
89
92
  wrap_with_container(attrs.merge(:label => label), super(clean_args!(attrs)))
90
93
  end
91
94
 
95
+ def bound_text_area(method, attrs = {}, &blk)
96
+ yield(attrs) if block_given?
97
+ super
98
+ end
99
+
92
100
  def button(contents, attrs = {})
101
+ yield(attrs) if block_given?
93
102
  wrap_with_container(attrs, super(contents, clean_args!(attrs)))
94
103
  end
95
104
 
96
105
  def submit(value, attrs = {})
106
+ yield(attrs) if block_given?
97
107
  wrap_with_container(attrs, super(value, clean_args!(attrs)))
98
108
  end
99
109
 
@@ -110,8 +120,10 @@ module Merb::Helpers::SexyForm
110
120
 
111
121
  def clean_args!(attrs)
112
122
  new_attrs = attrs.dup
113
- new_attrs.delete(:li)
123
+ new_attrs.delete(:wrapper)
114
124
  new_attrs.delete(:container)
125
+ new_attrs.delete(:before)
126
+ new_attrs.delete(:after)
115
127
  new_attrs
116
128
  end
117
129
 
@@ -123,15 +135,81 @@ module Merb::Helpers::SexyForm
123
135
  end
124
136
 
125
137
  def process_form_attrs(attrs)
126
- attrs[:id] = "#{@name}" unless attrs[:id] || @name.nil?
138
+ attrs[:id] = "#{@name}" unless attrs[:id] || @obj.nil?
127
139
 
128
- if (@obj.respond_to?(:new_record?) && !@obj.new_record?) || (@obj.respond_to?(:new?) && !@obj.new?)
129
- add_css_class(attrs, "edit")
130
- else
131
- add_css_class(attrs, "new")
140
+ if @obj
141
+ if (@obj.respond_to?(:new_record?) && !@obj.new_record?) || (@obj.respond_to?(:new?) && !@obj.new?)
142
+ add_css_class(attrs, "edit")
143
+ else
144
+ add_css_class(attrs, "new")
145
+ end
132
146
  end
133
147
  super(attrs)
134
148
  end
149
+
150
+ def add_main_label(content, attrs)
151
+ first = attrs.delete(:first)
152
+ method = attrs.delete(:method)
153
+
154
+ if first && (attrs[:id] || method)
155
+ if method && @obj
156
+ id = method ? "#{@name}_#{method}" : attrs[:id]
157
+ end
158
+ label_for = "#{id}_#{first[:value]}"
159
+ else
160
+ label_for = attrs[:id]
161
+ end
162
+
163
+ label = attrs.delete(:label)
164
+
165
+ if label && !label.is_a?(Hash)
166
+ label = {:label => {:title => label}}
167
+ end
168
+
169
+ if label.is_a?(Hash)
170
+ label = label[:label]
171
+ label.merge!({:class => "main", :for => label_for})
172
+ end
173
+
174
+ label = label(label)
175
+
176
+ label + content
177
+ end
178
+
179
+ def add_container(content, attrs)
180
+ container = attrs.delete(:container)
181
+
182
+ if container == false
183
+ content
184
+ else
185
+ container = container || {}
186
+ container.merge!(:id => "#{attrs[:id]}_container") if attrs[:id] and container[:id].blank?
187
+ container_tag = Merb::Plugins.config[:merb_sexy_forms][:container_tag]
188
+ tag(container_tag, content, container)
189
+ end
190
+ end
191
+
192
+ def add_field_wrapper(content, attrs)
193
+ wrapper = attrs.delete(:wrapper)
194
+ if wrapper == false
195
+ content
196
+ else
197
+ tag(:div, content, wrapper)
198
+ end
199
+ end
200
+
201
+ def add_html_to_field(content, attrs)
202
+ before = attrs.delete(:before)
203
+ after = attrs.delete(:after)
204
+
205
+ if before
206
+ content = before + content
207
+ end
208
+ if after
209
+ content = content + after
210
+ end
211
+ content
212
+ end
135
213
  end
136
214
  end
137
- end
215
+ end
@@ -17,4 +17,26 @@ module Merb::Helpers::Form
17
17
  form_contexts.pop
18
18
  ret
19
19
  end
20
- end
20
+
21
+ # monkey patching - need to do something about it
22
+ %w(text_field password_field hidden_field file_field
23
+ text_area select check_box radio_button radio_group).each do |kind|
24
+ self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
25
+ def #{kind}(*args, &blk)
26
+ if bound?(*args)
27
+ current_form_context.bound_#{kind}(*args, &blk)
28
+ else
29
+ current_form_context.unbound_#{kind}(*args, &blk)
30
+ end
31
+ end
32
+ RUBY
33
+ end
34
+
35
+ def submit(contents, attrs = {}, &blk)
36
+ current_form_context.submit(contents, attrs, &blk)
37
+ end
38
+
39
+ def button(contents, attrs = {}, &blk)
40
+ current_form_context.button(contents, attrs, &blk)
41
+ end
42
+ end
@@ -0,0 +1,2 @@
1
+ class SexyFormForSpecs < SpecController
2
+ end
@@ -0,0 +1,58 @@
1
+ class FakeModel
2
+
3
+ attr_accessor :vin, :make, :model
4
+
5
+ def self.columns
6
+ [FakeColumn.new(:foo, :string),
7
+ FakeColumn.new(:foobad, :string),
8
+ FakeColumn.new(:desc, :string),
9
+ FakeColumn.new(:bar, :integer),
10
+ FakeColumn.new(:barbad, :integer),
11
+ FakeColumn.new(:baz, :boolean),
12
+ FakeColumn.new(:bazbad, :boolean),
13
+ FakeColumn.new(:bat, :boolean),
14
+ FakeColumn.new(:batbad, :boolean),
15
+ FakeColumn.new(:foobar, :string)
16
+ ]
17
+ end
18
+
19
+ def valid?
20
+ false
21
+ end
22
+
23
+ def new_record?
24
+ false
25
+ end
26
+
27
+ def errors
28
+ FakeErrors.new(self)
29
+ end
30
+
31
+ def foo
32
+ "foowee"
33
+ end
34
+ alias_method :foobad, :foo
35
+
36
+ def bar
37
+ 7
38
+ end
39
+ alias_method :barbad, :bar
40
+
41
+ def baz
42
+ true
43
+ end
44
+ alias_method :bazbad, :baz
45
+
46
+ def bat
47
+ false
48
+ end
49
+ alias_method :batbad, :bat
50
+
51
+ def nothing
52
+ nil
53
+ end
54
+
55
+ def to_s
56
+ 'fake_model'
57
+ end
58
+ end
@@ -0,0 +1,6 @@
1
+ <%= sexy_form_for(@obj, :ul => {:class => "ul_class"}) do %>
2
+ <%= text_field :foo, :label => "Label: ",
3
+ :container => {:class => "contaiener_class"},
4
+ :wrapper => {:class => "wrapper_class" }
5
+ %>
6
+ <% end =%>
@@ -0,0 +1,7 @@
1
+ <%= sexy_form_for(@obj, :ul => {:class => "ul_class"}) do %>
2
+ <%= text_field :foo,
3
+ :label => "Label: ",
4
+ :class => "class",
5
+ :id => "id"
6
+ %>
7
+ <% end =%>
@@ -0,0 +1,3 @@
1
+ <%= sexy_form_for(@obj) do %>
2
+ <%= text_field :foo, :label => "Label: " %>
3
+ <% end =%>
@@ -0,0 +1,6 @@
1
+ <%= sexy_form_for(@obj, :ul => {:class => "ul_class"}) do %>
2
+ <%= text_field :foo,
3
+ :label => "Label: ",
4
+ :before => '<span class="before"></span>',
5
+ :after => '<span class="after"></span>' %>
6
+ <% end =%>
@@ -0,0 +1,23 @@
1
+ <%= sexy_form_for(@obj, :ul => {:class => "ul_class"}) do %>
2
+ <%= text_field :foo do |c| %>
3
+ <% c[:class] = "text_class" %>
4
+ <% end =%>
5
+ <%= text_area :foo do |c| %>
6
+ <% c[:class] = "textarea_class" %>
7
+ <% end =%>
8
+ <%= check_box :baz do |c|%>
9
+ <% c[:class] = "checkbox_class" %>
10
+ <% end =%>
11
+ <%= radio_button :bat do |c|%>
12
+ <% c[:class] = "radio_class" %>
13
+ <% end =%>
14
+ <%= select :bar do |c|%>
15
+ <% c[:class] = "select_class" %>
16
+ <% end =%>
17
+ <%= button "contents" do |c| %>
18
+ <% c[:class] = "button_class" %>
19
+ <% end =%>
20
+ <%= submit "contents" do |c| %>
21
+ <% c[:class] = "submit_class" %>
22
+ <% end =%>
23
+ <% end =%>
@@ -0,0 +1,4 @@
1
+ <%= sexy_form_for(@obj) do %>
2
+ <%= radio_button :foo, :label => "Radio label: ", :id => "radio" %>
3
+ <%= check_box :bar, :label => "Checkbox label: ", :id => "checkbox" %>
4
+ <% end =%>
@@ -0,0 +1,3 @@
1
+ <%= sexy_form_for(@obj) do %>
2
+ <%= text_field :foo, :label => "Label: " %>
3
+ <% end =%>
@@ -0,0 +1,3 @@
1
+ <%= sexy_form(:ul => {:class => "ul_class"}) do %>
2
+ <%= text_field :name => "name", :label => "Label: ", :container => {:class => "contaiener_class"}, :wrapper => {:class => "wrapper_class"} %>
3
+ <% end =%>
@@ -0,0 +1,3 @@
1
+ <%= sexy_form(:ul => {:class => "ul_class"}) do %>
2
+ <%= text_field :name => "name", :label => "Label: ", :class => "class", :id => "id" %>
3
+ <% end =%>
@@ -0,0 +1,3 @@
1
+ <%= sexy_form() do %>
2
+ <%= text_field :name => "name", :label => "Label: " %>
3
+ <% end =%>
@@ -0,0 +1,6 @@
1
+ <%= sexy_form(:ul => {:class => "ul_class"}) do %>
2
+ <%= text_field :name => "name",
3
+ :label => "Label: ",
4
+ :before => '<span class="before"></span>',
5
+ :after => '<span class="after"></span>' %>
6
+ <% end =%>
@@ -0,0 +1,23 @@
1
+ <%= sexy_form(:ul => {:class => "ul_class"}) do %>
2
+ <%= text_field do |c|%>
3
+ <% c[:class] = "text_class" %>
4
+ <% end =%>
5
+ <%= text_area "content" do |c|%>
6
+ <% c[:class] = "textarea_class" %>
7
+ <% end =%>
8
+ <%= check_box do |c|%>
9
+ <% c[:class] = "checkbox_class" %>
10
+ <% end =%>
11
+ <%= radio_button do |c|%>
12
+ <% c[:class] = "radio_class" %>
13
+ <% end =%>
14
+ <%= select do |c|%>
15
+ <% c[:class] = "select_class" %>
16
+ <% end =%>
17
+ <%= button "contents" do |c| %>
18
+ <% c[:class] = "button_class" %>
19
+ <% end =%>
20
+ <%= submit "contents" do |c| %>
21
+ <% c[:class] = "submit_class" %>
22
+ <% end =%>
23
+ <% end =%>
data/spec/merb_test.log CHANGED
@@ -1 +1,94 @@
1
1
  Sat, 20 Dec 2008 13:41:20 GMT ~ info ~ Logfile created
2
+ ~ Could not load ./spec/fixture/app/views/sexy_form_for.rb:
3
+
4
+ uninitialized constant SpecController - (NameError)
5
+
6
+ ./spec/fixture/app/views/sexy_form_for.rb:1
7
+ /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
8
+ /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
9
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/bootloader.rb:863:in `load_file'
10
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/bootloader.rb:1018:in `load_classes_with_requirements'
11
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/bootloader.rb:1015:in `each'
12
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/bootloader.rb:1015:in `load_classes_with_requirements'
13
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/bootloader.rb:903:in `load_classes'
14
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/bootloader.rb:641:in `run'
15
+ /usr/lib/ruby/gems/1.8/gems/extlib-0.9.9/lib/extlib/dictionary.rb:268:in `each'
16
+ /usr/lib/ruby/gems/1.8/gems/extlib-0.9.9/lib/extlib/dictionary.rb:268:in `each'
17
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/bootloader.rb:639:in `run'
18
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/bootloader.rb:99:in `run'
19
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/server.rb:172:in `bootup'
20
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/server.rb:42:in `start'
21
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core.rb:170:in `start'
22
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core.rb:183:in `start_environment'
23
+ ./spec/spec_helper.rb:18
24
+ ./spec/sexy_form_for_spec.rb:1:in `require'
25
+ ./spec/sexy_form_for_spec.rb:1
26
+ /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:14:in `load'
27
+ /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:14:in `load_files'
28
+ /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:13:in `each'
29
+ /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:13:in `load_files'
30
+ /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/options.rb:98:in `run_examples'
31
+ /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/command_line.rb:10:in `run'
32
+ /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/bin/spec:4
33
+ ~ Could not load ./spec/fixture/app/views/sexy_form_for.rb:
34
+
35
+ uninitialized constant SpecController - (NameError)
36
+
37
+ ./spec/fixture/app/views/sexy_form_for.rb:1
38
+ /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
39
+ /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
40
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/bootloader.rb:863:in `load_file'
41
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/bootloader.rb:1018:in `load_classes_with_requirements'
42
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/bootloader.rb:1015:in `each'
43
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/bootloader.rb:1015:in `load_classes_with_requirements'
44
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/bootloader.rb:903:in `load_classes'
45
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/bootloader.rb:641:in `run'
46
+ /usr/lib/ruby/gems/1.8/gems/extlib-0.9.9/lib/extlib/dictionary.rb:268:in `each'
47
+ /usr/lib/ruby/gems/1.8/gems/extlib-0.9.9/lib/extlib/dictionary.rb:268:in `each'
48
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/bootloader.rb:639:in `run'
49
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/bootloader.rb:99:in `run'
50
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/server.rb:172:in `bootup'
51
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/server.rb:42:in `start'
52
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core.rb:170:in `start'
53
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core.rb:183:in `start_environment'
54
+ ./spec/spec_helper.rb:18
55
+ ./spec/sexy_form_for_spec.rb:1:in `require'
56
+ ./spec/sexy_form_for_spec.rb:1
57
+ /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:14:in `load'
58
+ /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:14:in `load_files'
59
+ /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:13:in `each'
60
+ /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:13:in `load_files'
61
+ /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/options.rb:98:in `run_examples'
62
+ /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/command_line.rb:10:in `run'
63
+ /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/bin/spec:4
64
+ ~ Could not load ./spec/fixture/app/views/sexy_form_for.rb:
65
+
66
+ uninitialized constant SpecController - (NameError)
67
+
68
+ ./spec/fixture/app/views/sexy_form_for.rb:1
69
+ /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
70
+ /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
71
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/bootloader.rb:863:in `load_file'
72
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/bootloader.rb:1018:in `load_classes_with_requirements'
73
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/bootloader.rb:1015:in `each'
74
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/bootloader.rb:1015:in `load_classes_with_requirements'
75
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/bootloader.rb:903:in `load_classes'
76
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/bootloader.rb:641:in `run'
77
+ /usr/lib/ruby/gems/1.8/gems/extlib-0.9.9/lib/extlib/dictionary.rb:268:in `each'
78
+ /usr/lib/ruby/gems/1.8/gems/extlib-0.9.9/lib/extlib/dictionary.rb:268:in `each'
79
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/bootloader.rb:639:in `run'
80
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/bootloader.rb:99:in `run'
81
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/server.rb:172:in `bootup'
82
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core/server.rb:42:in `start'
83
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core.rb:170:in `start'
84
+ /usr/lib/ruby/gems/1.8/gems/merb-core-1.0.6.1/lib/merb-core.rb:183:in `start_environment'
85
+ ./spec/spec_helper.rb:18
86
+ ./spec/sexy_form_for_spec.rb:1:in `require'
87
+ ./spec/sexy_form_for_spec.rb:1
88
+ /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:14:in `load'
89
+ /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:14:in `load_files'
90
+ /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:13:in `each'
91
+ /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:13:in `load_files'
92
+ /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/options.rb:98:in `run_examples'
93
+ /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/command_line.rb:10:in `run'
94
+ /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/bin/spec:4
@@ -0,0 +1,80 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "sexy_form_for" do
4
+
5
+ before :each do
6
+ @c = SexyFormForSpecs.new(Merb::Request.new({}))
7
+ @c.instance_variable_set(:@obj, FakeModel.new)
8
+ @container = Merb::Plugins.config[:merb_sexy_forms][:container_tag]
9
+ end
10
+
11
+ it "should allow to pass block to any field and set hash contents inside" do
12
+ ret = @c.render(:blocks)
13
+ ret.should have_selector("form input[type=text].text_class")
14
+ ret.should have_selector("form input[type=submit].submit_class")
15
+ ret.should have_selector("form button.button_class")
16
+ ret.should have_selector("form input[type=radio].radio_class")
17
+ ret.should have_selector("form input[type=checkbox].checkbox_class")
18
+ ret.should have_selector("form select.select_class")
19
+ ret.should have_selector("form textarea.textarea_class")
20
+ end
21
+
22
+ it "should insert some html after and before field" do
23
+ ret = @c.render(:before_after_field)
24
+ ret.should have_selector("form span.before")
25
+ ret.should have_selector("form span.after")
26
+
27
+ ret.should_not have_selector("*[after], *[before]")
28
+ end
29
+
30
+ it "should append attributes to field" do
31
+ ret = @c.render(:append_attributes)
32
+ ret.should have_selector("form input#id.class")
33
+ end
34
+
35
+ it "should not add options attrs" do
36
+ ret = @c.render(:additional_options)
37
+ ret.should_not have_selector("*[container], *[ul], *[wrapper]")
38
+ end
39
+
40
+ it "should add containers" do
41
+ ret = @c.render(:basic)
42
+ ret.should have_selector("form #{@container} > label")
43
+ end
44
+
45
+ it "should add ul if container tag is li" do
46
+ Merb::Plugins.config[:merb_sexy_forms][:container_tag] = "li"
47
+ ret = @c.render(:basic)
48
+ ret.should have_selector("form > ul")
49
+ end
50
+
51
+ it "should'nt add ul if container tag is not li" do
52
+ Merb::Plugins.config[:merb_sexy_forms][:container_tag] = "div"
53
+ ret = @c.render(:basic)
54
+ ret.should_not have_selector("form > ul")
55
+ end
56
+
57
+ it "should add labels with field nested in container" do
58
+ ret = @c.render(:with_labels)
59
+ ret.should have_selector("form #{@container} > label")
60
+ ret.should have_selector("form #{@container} > div > input")
61
+ end
62
+
63
+ it "should add 'choice' class to labels for checkboxes or radio buttons" do
64
+ ret = @c.render(:label_choice_class)
65
+ ret.should have_selector("form div label[for=checkbox].choice")
66
+ ret.should have_selector("form div label[for=radio].choice")
67
+ end
68
+
69
+ it "should not add 'choice' class to main labels with checkboxes or radio buttons" do
70
+ ret = @c.render(:label_choice_class)
71
+ ret.should_not have_selector("form label.choice.main")
72
+ end
73
+
74
+ it "should generate main labels if label option is provided" do
75
+ ret = @c.render(:basic)
76
+ ret.should have_selector("label.main[for=fake_model_foo]")
77
+ end
78
+ end
79
+
80
+
@@ -0,0 +1,79 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "sexy_form" do
4
+
5
+ before :each do
6
+ @c = SexyFormSpecs.new(Merb::Request.new({}))
7
+ @container = Merb::Plugins.config[:merb_sexy_forms][:container_tag]
8
+ end
9
+
10
+ it "should allow to pass block to any field and set hash contents inside" do
11
+ ret = @c.render(:blocks)
12
+ ret.should have_selector("form input[type=text].text_class")
13
+ ret.should have_selector("form input[type=submit].submit_class")
14
+ ret.should have_selector("form button.button_class")
15
+ ret.should have_selector("form input[type=radio].radio_class")
16
+ ret.should have_selector("form input[type=checkbox].checkbox_class")
17
+ ret.should have_selector("form select.select_class")
18
+ ret.should have_selector("form textarea.textarea_class")
19
+ end
20
+
21
+ it "should insert some html after and before field" do
22
+ ret = @c.render(:before_after_field)
23
+ ret.should have_selector("form span.before")
24
+ ret.should have_selector("form span.after")
25
+
26
+ ret.should_not have_selector("*[after], *[before]")
27
+ end
28
+
29
+ it "should append attributes to field" do
30
+ ret = @c.render(:append_attributes)
31
+ ret.should have_selector("form input#id.class")
32
+ end
33
+
34
+ it "should not add options attrs" do
35
+ ret = @c.render(:additional_options)
36
+ ret.should_not have_selector("*[container], *[ul], *[wrapper]")
37
+ end
38
+
39
+ it "should add containers" do
40
+ ret = @c.render(:basic)
41
+ ret.should have_selector("form #{@container} > label")
42
+ end
43
+
44
+ it "should add ul if container tag is li" do
45
+ Merb::Plugins.config[:merb_sexy_forms][:container_tag] = "li"
46
+ ret = @c.render(:basic)
47
+ ret.should have_selector("form > ul")
48
+ end
49
+
50
+ it "should'nt add ul if container tag is not li" do
51
+ Merb::Plugins.config[:merb_sexy_forms][:container_tag] = "div"
52
+ ret = @c.render(:basic)
53
+ ret.should_not have_selector("form > ul")
54
+ end
55
+
56
+ it "should add labels with field nested in container" do
57
+ ret = @c.render(:with_labels)
58
+ ret.should have_selector("form #{@container} > label")
59
+ ret.should have_selector("form #{@container} > div > input")
60
+ end
61
+
62
+ it "should add 'choice' class to labels for checkboxes or radio buttons" do
63
+ ret = @c.render(:label_choice_class)
64
+ ret.should have_selector("form div label[for=checkbox].choice")
65
+ ret.should have_selector("form div label[for=radio].choice")
66
+ end
67
+
68
+ it "should not add 'choice' class to main labels with checkboxes or radio buttons" do
69
+ ret = @c.render(:label_choice_class)
70
+ ret.should_not have_selector("form label.choice.main")
71
+ end
72
+
73
+ it "should generate main labels if label option is provided" do
74
+ ret = @c.render(:basic)
75
+ ret.should have_selector("label.main")
76
+ end
77
+ end
78
+
79
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drogus-merb-sexy-forms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Sarnacki
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-20 00:00:00 -08:00
12
+ date: 2009-01-07 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -19,7 +19,7 @@ dependencies:
19
19
  requirements:
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 1.0.6.1
22
+ version: 1.0.7.1
23
23
  version:
24
24
  description: Merb plugin that provides extended builder for forms
25
25
  email: drogus@gmail.com
@@ -45,12 +45,28 @@ files:
45
45
  - spec/fixture/app
46
46
  - spec/fixture/app/controllers
47
47
  - spec/fixture/app/controllers/application.rb
48
+ - spec/fixture/app/controllers/sexy_form_for.rb
48
49
  - spec/fixture/app/controllers/sexy_form.rb
49
50
  - spec/fixture/app/controllers/specs_controller.rb
50
51
  - spec/fixture/app/views
51
52
  - spec/fixture/app/views/sexy_form_specs
52
53
  - spec/fixture/app/views/sexy_form_specs/label_choice_class.html.erb
54
+ - spec/fixture/app/views/sexy_form_specs/additional_options.html.erb
53
55
  - spec/fixture/app/views/sexy_form_specs/with_labels.html.erb
56
+ - spec/fixture/app/views/sexy_form_specs/before_after_field.html.erb
57
+ - spec/fixture/app/views/sexy_form_specs/append_attributes.html.erb
58
+ - spec/fixture/app/views/sexy_form_specs/blocks.html.erb
59
+ - spec/fixture/app/views/sexy_form_specs/basic.html.erb
60
+ - spec/fixture/app/views/sexy_form_for_specs
61
+ - spec/fixture/app/views/sexy_form_for_specs/label_choice_class.html.erb
62
+ - spec/fixture/app/views/sexy_form_for_specs/additional_options.html.erb
63
+ - spec/fixture/app/views/sexy_form_for_specs/with_labels.html.erb
64
+ - spec/fixture/app/views/sexy_form_for_specs/before_after_field.html.erb
65
+ - spec/fixture/app/views/sexy_form_for_specs/append_attributes.html.erb
66
+ - spec/fixture/app/views/sexy_form_for_specs/blocks.html.erb
67
+ - spec/fixture/app/views/sexy_form_for_specs/basic.html.erb
68
+ - spec/fixture/app/models
69
+ - spec/fixture/app/models/first_generic_fake_model.rb
54
70
  - spec/fixture/config
55
71
  - spec/fixture/config/init.rb.rb
56
72
  - spec/fixture/config/environments
@@ -60,9 +76,10 @@ files:
60
76
  - spec/fixture/config/rack.rb
61
77
  - spec/fixture/config/router.rb
62
78
  - spec/merb_test.log
79
+ - spec/sexy_form_for_spec.rb
63
80
  - spec/spec_helper.rb
64
81
  - spec/merb-sexy-forms_spec.rb
65
- - spec/merb-sexy-forms-form_spec.rb
82
+ - spec/sexy_form_spec.rb
66
83
  - spec/merb.main.pid
67
84
  - assets/stylesheets
68
85
  - assets/stylesheets/sexy_forms.css
@@ -1,29 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- Merb::Plugins.config[:helpers] = {
4
- :default_builder => Merb::Helpers::Form::Builder::FormWithErrors
5
- }
6
-
7
- describe "form" do
8
-
9
- before :each do
10
- @c = SexyFormSpecs.new(Merb::Request.new({}))
11
- end
12
-
13
- it "should add labels with field nested in container" do
14
- ret = @c.render(:with_labels)
15
- ret.should have_selector("form ul li label")
16
- ret.should have_selector("form ul li div input")
17
- end
18
-
19
- it "should add 'choice' class to labels for checkboxes or radio buttons" do
20
- ret = @c.render(:label_choice_class)
21
- ret.should have_selector("form div label[for=checkbox].choice")
22
- ret.should have_selector("form div label[for=radio].choice")
23
- end
24
-
25
- it "should not add 'choice' class to main labels" do
26
- ret = @c.render(:label_choice_class)
27
- ret.should_not have_selector("form label.choice.main")
28
- end
29
- end