david-former 0.0.1 → 0.0.2
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/VERSION.yml +1 -1
- data/lib/former.rb +21 -21
- data/spec/former_spec.rb +2 -2
- metadata +1 -1
data/VERSION.yml
CHANGED
data/lib/former.rb
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
gem 'actionpack'; require 'action_view'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
module Former
|
|
4
|
+
class FormBuilder < ActionView::Helpers::FormBuilder
|
|
5
|
+
%w(text_field text_area file_field).each do |field_type|
|
|
6
|
+
self.class_eval <<-RUBY
|
|
6
7
|
def #{field_type}(name, options = {})
|
|
7
8
|
str = ""
|
|
8
9
|
|
|
@@ -16,26 +17,25 @@ class StandardFormBuilder < ActionView::Helpers::FormBuilder
|
|
|
16
17
|
|
|
17
18
|
str << super(name, options)
|
|
18
19
|
end
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
RUBY
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def radio_button_group(name, values, *args)
|
|
24
|
+
options = Hash === args.last ? args.pop : {}
|
|
25
|
+
|
|
26
|
+
result = values.inject("") do |html, value|
|
|
27
|
+
label = label("#{name}_#{value}", value)
|
|
28
|
+
rb = radio_button(name, value)
|
|
29
|
+
unless options[:label_position] == :after
|
|
30
|
+
content = "#{label} #{rb}"
|
|
31
|
+
else
|
|
32
|
+
content = "#{rb} #{label}"
|
|
33
|
+
end
|
|
24
34
|
|
|
25
|
-
|
|
26
|
-
label = label("#{name}_#{value}", value)
|
|
27
|
-
rb = radio_button(name, value)
|
|
28
|
-
unless options[:label_position] == :after
|
|
29
|
-
content = "#{label} #{rb}"
|
|
30
|
-
else
|
|
31
|
-
content = "#{rb} #{label}"
|
|
35
|
+
html << "<li>#{content}</li>"
|
|
32
36
|
end
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
|
|
38
|
+
"<ul>#{result}</ul>"
|
|
35
39
|
end
|
|
36
|
-
|
|
37
|
-
"<ul>#{result}</ul>"
|
|
38
40
|
end
|
|
39
41
|
end
|
|
40
|
-
|
|
41
|
-
ActionView::Base.default_form_builder = StandardFormBuilder
|
data/spec/former_spec.rb
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
require File.join(File.dirname(__FILE__), %w(spec_helper))
|
|
2
2
|
|
|
3
|
-
describe
|
|
3
|
+
describe Former::FormBuilder do
|
|
4
4
|
before do
|
|
5
5
|
@template = mock("template")
|
|
6
6
|
@object = mock("model")
|
|
7
|
-
@fb =
|
|
7
|
+
@fb = Former::FormBuilder.new(:model, @object, @template, {}, nil)
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
%w(text_field text_area file_field).each do |field_type|
|