reformed 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +64 -0
- data/Rakefile +9 -0
- data/lib/reformed/form_builder.rb +139 -0
- data/lib/reformed/form_helper.rb +17 -0
- data/lib/reformed/railtie.rb +11 -0
- data/lib/reformed/version.rb +3 -0
- data/lib/reformed.rb +8 -0
- data/reformed.gemspec +29 -0
- data/test/reformed/form_builder_test.rb +186 -0
- data/test/reformed/form_helper_test.rb +23 -0
- data/test/reformed/reformed_test.rb +13 -0
- data/test/test_helper.rb +68 -0
- metadata +168 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Jason Torres
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
Reformed
|
2
|
+
========
|
3
|
+
|
4
|
+
Better Rails 3+ and 4+ Form Builder with support for any CSS Framework. Natively supports Bootstrap 2 and 3, Zurb 3 and 4 via customization.
|
5
|
+
|
6
|
+
### Installation
|
7
|
+
|
8
|
+
gem 'reformed'
|
9
|
+
|
10
|
+
### Instructions
|
11
|
+
|
12
|
+
It's very easy to use, just do this
|
13
|
+
|
14
|
+
= reform_for do |f|
|
15
|
+
f.input :name
|
16
|
+
f.input :email
|
17
|
+
f.input :password
|
18
|
+
end
|
19
|
+
|
20
|
+
### Customization
|
21
|
+
|
22
|
+
The best feature ever. Customization supports lambda
|
23
|
+
|
24
|
+
Reformed::FormBuilder.input_wrapper = lambda { |controls, options|
|
25
|
+
"<div class=\"input-control\">#{controls[:label]} #{controls[:input]} #{controls[:error]} #{controls[:hint]}</div>"
|
26
|
+
}
|
27
|
+
|
28
|
+
Reformed::FormBuilder.label_wrapper = lambda { |controls, options|
|
29
|
+
"<span>#{controls[:label]}</span>"
|
30
|
+
}
|
31
|
+
|
32
|
+
Reformed::FormBuilder.hint_wrapper = lambda { |message, options|
|
33
|
+
"<span class=\"hint\">#{message}</span>"
|
34
|
+
}
|
35
|
+
|
36
|
+
Reformed::FormBuilder.error_wrapper = lambda { |message, options|
|
37
|
+
"<span class=\"error\">#{message}</span>"
|
38
|
+
}
|
39
|
+
|
40
|
+
|
41
|
+
More examples to follow soon
|
42
|
+
|
43
|
+
## HTML5
|
44
|
+
|
45
|
+
By default, Reformed will render your controls as html5, you can turn it off by doing the following
|
46
|
+
|
47
|
+
Reformed::FormBuilder.html5 = false
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create new Pull Request
|
56
|
+
|
57
|
+
|
58
|
+
## Contributors
|
59
|
+
|
60
|
+
Vixon - The Jason Torres and Victor Solis show.
|
61
|
+
|
62
|
+
## License
|
63
|
+
|
64
|
+
MIT License
|
data/Rakefile
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
module Reformed
|
2
|
+
class FormBuilder < ActionView::Helpers::FormBuilder
|
3
|
+
include ActionView::Helpers::OutputSafetyHelper
|
4
|
+
|
5
|
+
cattr_accessor :input_wrapper, :label_wrapper, :html5
|
6
|
+
|
7
|
+
@@html5 = true
|
8
|
+
|
9
|
+
@@input_wrapper = lambda { |controls, options|
|
10
|
+
"<div class=\"input-control\">#{controls[:label]} #{controls[:input]} #{controls[:error]} #{controls[:hint]}</div>"
|
11
|
+
}
|
12
|
+
|
13
|
+
@@label_wrapper = lambda { |controls, options|
|
14
|
+
"<span>#{controls[:label]}</span>"
|
15
|
+
}
|
16
|
+
|
17
|
+
@@hint_wrapper = lambda { |message, options|
|
18
|
+
"<span class=\"hint\">#{message}</span>"
|
19
|
+
}
|
20
|
+
|
21
|
+
@@error_wrapper = lambda { |message, options|
|
22
|
+
"<span class=\"error\">#{message}</span>"
|
23
|
+
}
|
24
|
+
|
25
|
+
def input(method, options = {}, &block)
|
26
|
+
controls = {}
|
27
|
+
|
28
|
+
if options[:hint]
|
29
|
+
controls[:hint] = hint_wrap(options.delete(:hint), control_options(options))
|
30
|
+
end
|
31
|
+
|
32
|
+
if options[:error]
|
33
|
+
controls[:error] = error_wrap(options.delete(:error), control_options(options))
|
34
|
+
end
|
35
|
+
|
36
|
+
controls[:label] = label_wrap(method, control_options(options.merge(method: method), :label))
|
37
|
+
|
38
|
+
controls[:input] = input_wrap(method, control_options(options))
|
39
|
+
|
40
|
+
raw @@input_wrapper.call(controls, options)
|
41
|
+
end
|
42
|
+
|
43
|
+
def input_wrap(method, options, &block)
|
44
|
+
whatami = options[:as] || as(method)
|
45
|
+
options.delete(:as)
|
46
|
+
|
47
|
+
case whatami
|
48
|
+
when :string then text_field method, options
|
49
|
+
when :text then text_area method, options
|
50
|
+
when :file then file_field method, options
|
51
|
+
when :string then text_field method, options
|
52
|
+
when :password then password_field method, options
|
53
|
+
when :radio then radio_button method, options[:choices], options
|
54
|
+
when :boolean then check_box method, options
|
55
|
+
when :url then url_field method, options
|
56
|
+
when :email then email_field method, options
|
57
|
+
when :phone then phone_field method, options
|
58
|
+
when :number then number_field method, options
|
59
|
+
when :date then date_select method, options, options.delete(:html) || {}
|
60
|
+
when :time then time_select method, options, options.delete(:html) || {}
|
61
|
+
when :datetime then datetime_select method, options, options.delete(:html) || {}
|
62
|
+
when :select then select method, options[:choices], options, options.delete(:html) || {}
|
63
|
+
when :hidden then hidden_field method, options
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def label_wrap(method, options = {}, &block)
|
68
|
+
label_text = options.delete(:label) if options[:label]
|
69
|
+
if label_text
|
70
|
+
@@label_wrapper.call({label: label(method, label_text, options, &block)}, options)
|
71
|
+
else
|
72
|
+
@@label_wrapper.call({label: label(method, options[:label], &block)}, options)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def hint_wrap(str, options, &block)
|
77
|
+
@@hint_wrapper.call(str, options)
|
78
|
+
end
|
79
|
+
|
80
|
+
def error_wrap(str, options, &block)
|
81
|
+
@@error_wrapper.call(str, options)
|
82
|
+
end
|
83
|
+
|
84
|
+
def reform_fields_for(record_or_name_or_array, *args, &block)
|
85
|
+
options = args.extract_options!
|
86
|
+
options[:builder] ||= self.class
|
87
|
+
fields_for(record_or_name_or_array, *(args << options), &block)
|
88
|
+
end
|
89
|
+
|
90
|
+
def html5?
|
91
|
+
@@html5
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def as(method)
|
97
|
+
|
98
|
+
# determine the field type
|
99
|
+
case "#{method}"
|
100
|
+
when /url/ then return (html5? ? :url : :string)
|
101
|
+
when /email/ then return (html5? ? :email : :string)
|
102
|
+
when /phone/ then return (html5? ? :phone : :string)
|
103
|
+
when /password/ then return :password
|
104
|
+
end
|
105
|
+
|
106
|
+
case infer_type(method)
|
107
|
+
when :radio then return :radio
|
108
|
+
when :string then return :string
|
109
|
+
when :boolean then return :boolean
|
110
|
+
when :integer then return :number
|
111
|
+
when :float then return :number
|
112
|
+
when :decimal then return :number
|
113
|
+
when :timestamp then return :datetime
|
114
|
+
when :datetime then return :datetime
|
115
|
+
when :date then return :date
|
116
|
+
when :time then return :time
|
117
|
+
when :text then return :text
|
118
|
+
else method.to_sym
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
def infer_type(method)
|
124
|
+
column = @object.column_for_attribute(method) if @object.respond_to?(:column_for_attribute)
|
125
|
+
return column.type
|
126
|
+
end
|
127
|
+
|
128
|
+
def control_options(options, type = nil)
|
129
|
+
if type == :label
|
130
|
+
{label: options[:label]}
|
131
|
+
elsif type
|
132
|
+
options[type.to_sym] || {}
|
133
|
+
else
|
134
|
+
options
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'reformed/form_builder'
|
2
|
+
|
3
|
+
module Reformed
|
4
|
+
module FormHelper
|
5
|
+
|
6
|
+
def reform_for(record, options = {}, &block)
|
7
|
+
options[:builder] ||= Reformed::FormBuilder
|
8
|
+
form_for(record, options, &block)
|
9
|
+
end
|
10
|
+
|
11
|
+
def reform_fields_for(record, options = {}, &block)
|
12
|
+
options[:builder] ||= Reformed::FormBuilder
|
13
|
+
fields_for(record, options, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/lib/reformed.rb
ADDED
data/reformed.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'reformed/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "reformed"
|
8
|
+
spec.version = Reformed::VERSION
|
9
|
+
spec.authors = ["Jason Torres"]
|
10
|
+
spec.email = ["jason.e.torres@gmail.com"]
|
11
|
+
spec.description = %q{Better Rails Forms}
|
12
|
+
spec.summary = %q{A better rails form builder that supports multiple}
|
13
|
+
spec.homepage = "http://github.com/vixon/reformed"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "mocha"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency('activerecord', '>= 4.0.0', '< 4.1')
|
25
|
+
spec.add_development_dependency('railties', '>= 4.0.0', '< 4.1')
|
26
|
+
spec.add_development_dependency('activemodel', '>= 4.0.0', '< 4.1')
|
27
|
+
spec.add_development_dependency('actionpack', '>= 4.0.0', '< 4.1')
|
28
|
+
spec.add_development_dependency('activesupport', '>= 4.0.0', '< 4.1')
|
29
|
+
end
|
@@ -0,0 +1,186 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class Reformed::FormBuilderTest < ActionView::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@user = User.new
|
7
|
+
@user.name = 'Lalala'
|
8
|
+
end
|
9
|
+
|
10
|
+
test "yields the correct instance" do
|
11
|
+
form_for :user, url: '/', builder: Reformed::FormBuilder do |f|
|
12
|
+
assert f.instance_of?(Reformed::FormBuilder)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
test "responds to the input method" do
|
17
|
+
form_for :user, url: '/', builder: Reformed::FormBuilder do |f|
|
18
|
+
assert f.respond_to?(:input)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
test "responds to reform_for" do
|
23
|
+
assert respond_to?(:reform_for)
|
24
|
+
end
|
25
|
+
|
26
|
+
test "yields the input" do
|
27
|
+
reform_for(@user, url: '/') do |f|
|
28
|
+
assert_match 'user_name', f.input(:name)
|
29
|
+
end
|
30
|
+
|
31
|
+
output = reform_for(@user, url: '/') do |f|
|
32
|
+
f.input :name
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
test "yields an input field with an input wrapper" do
|
37
|
+
Reformed::FormBuilder.input_wrapper = lambda { |controls, options|
|
38
|
+
"<div class='mycustomdiv'>#{controls[:input]}</div>"
|
39
|
+
}
|
40
|
+
|
41
|
+
reform_for(@user, url: '/') do |f|
|
42
|
+
assert_match "<div class='mycustomdiv'>", f.input(:name)
|
43
|
+
assert_match "<input id=\"user_name\" name=\"user[name]\" type=\"text\" value=\"Lalala\" />", f.input(:name)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
test "yields a label" do
|
48
|
+
Reformed::FormBuilder.label_wrapper = lambda { |controls, options|
|
49
|
+
"<span class=\"label-wrapper\">#{controls[:label]}</span>"
|
50
|
+
}
|
51
|
+
|
52
|
+
reform_for(@user, url: '/') do |f|
|
53
|
+
output = f.input(:name)
|
54
|
+
assert_match "<span class=\"label-wrapper\">", output
|
55
|
+
assert_match "<label for=\"user_name\">Name</label>", output
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
test "yields a label with a custom label" do
|
60
|
+
Reformed::FormBuilder.label_wrapper = lambda { |controls, options|
|
61
|
+
"<span class=\"label-wrapper\">#{controls[:label]}</span>"
|
62
|
+
}
|
63
|
+
|
64
|
+
reform_for(@user, url: '/') do |f|
|
65
|
+
output = f.input(:name, label: 'Custom Label')
|
66
|
+
assert_match "<span class=\"label-wrapper\">", output
|
67
|
+
assert_match "<label for=\"user_name\">Custom Label</label>", output
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
test "infer types from method" do
|
72
|
+
reform_for(@user, url: '/') do |f|
|
73
|
+
assert :string, f.send(:as, :name)
|
74
|
+
assert :text, f.send(:as, :body)
|
75
|
+
|
76
|
+
assert :boolean, f.send(:as, :cute)
|
77
|
+
|
78
|
+
assert :number, f.send(:as, :age)
|
79
|
+
assert :number, f.send(:as, :price)
|
80
|
+
assert :number, f.send(:as, :currency)
|
81
|
+
|
82
|
+
assert :url, f.send(:as, :url)
|
83
|
+
assert :email, f.send(:as, :email)
|
84
|
+
assert :password, f.send(:as, :password)
|
85
|
+
|
86
|
+
assert :datetime, f.send(:as, :birthdate)
|
87
|
+
assert :datetime, f.send(:as, :datecolumn)
|
88
|
+
assert :datetime, f.send(:as, :timecolumn)
|
89
|
+
assert :datetime, f.send(:as, :timestampcolumn)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
test "yields a text field with an input wrapper" do
|
94
|
+
@user.body = "your body is a wonderland"
|
95
|
+
reform_for(@user, url: '/') do |f|
|
96
|
+
assert_match "<textarea id=\"user_body\" name=\"user[body]\">\nyour body is a wonderland</textarea>", f.input(:body)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
test "yields a url field" do
|
101
|
+
reform_for(@user, url: '/') do |f|
|
102
|
+
assert_match '<input id="user_url" name="user[url]" type="url" />', f.input(:url)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
test "yields a phone field" do
|
107
|
+
reform_for(@user, url: '/') do |f|
|
108
|
+
assert_match '<input id="user_phone" name="user[phone]" type="tel" />', f.input(:phone)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
test "yields an email field" do
|
113
|
+
reform_for(@user, url: '/') do |f|
|
114
|
+
assert_match '<input id="user_email" name="user[email]" type="email" />', f.input(:email)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
test "yields a checkbox field" do
|
119
|
+
reform_for(@user, url: '/') do |f|
|
120
|
+
assert_match '<input id="user_cute" name="user[cute]" type="checkbox" value="1" />', f.input(:cute)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
test "yields a radio field" do
|
125
|
+
reform_for(@user, url: '/') do |f|
|
126
|
+
assert_match '<input checked="checked" id="user_cute" name="user[cute]" type="radio" />', f.input(:cute, as: :radio)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
test "yields a password field" do
|
131
|
+
reform_for(@user, url: '/') do |f|
|
132
|
+
assert_match '<input id="user_password" name="user[password]" type="password" />', f.input(:password)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
test "yields a date field" do
|
137
|
+
reform_for(@user, url: '/') do |f|
|
138
|
+
assert_match 'user_birthdate_1i', f.input(:birthdate)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
test "yields a hidden field" do
|
143
|
+
reform_for(@user, url: '/') do |f|
|
144
|
+
assert_match '<input id="user_name" name="user[name]" type="hidden" value="Lalala" />', f.input(:name, as: :hidden)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
test "yields a select field" do
|
149
|
+
reform_for(@user, url: '/') do |f|
|
150
|
+
assert_match '<select id="user_gender" name="user[gender]"><option value="male">male</option>
|
151
|
+
<option value="female">female</option></select>', f.input(:gender, as: :select, choices: ['male', 'female'])
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
test "yields an input with a hint" do
|
156
|
+
|
157
|
+
Reformed::FormBuilder.input_wrapper = lambda { |controls, options|
|
158
|
+
"<div class='input-control'>#{controls[:input]} #{controls[:hint]}</div>"
|
159
|
+
}
|
160
|
+
|
161
|
+
reform_for(@user, url: '/') do |f|
|
162
|
+
assert '<div class="input-control"><input id="user_name" name="user[name]" type="text" value="Lalala" /> <span class="hint">Full Name</span></div>', f.input(:name, hint: 'Full Name')
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
test "yields an input with an error" do
|
167
|
+
Reformed::FormBuilder.input_wrapper = lambda { |controls, options|
|
168
|
+
"<div class='input-control'>#{controls[:input]} #{controls[:hint]}</div>"
|
169
|
+
}
|
170
|
+
|
171
|
+
reform_for(@user, url: '/') do |f|
|
172
|
+
assert '<div class="input-control"><input id="user_name" name="user[name]" type="text" value="Lalala" /> <span class="error">Full Name</span></div>', f.input(:name, error: 'Full Name')
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
test "yields an input with the whole shebang" do
|
177
|
+
Reformed::FormBuilder.input_wrapper = lambda { |controls, options|
|
178
|
+
"<div class=\"input-control\">#{controls[:label]} #{controls[:input]} #{controls[:error]} #{controls[:hint]}</div>"
|
179
|
+
}
|
180
|
+
|
181
|
+
reform_for(@user, url: '/') do |f|
|
182
|
+
assert_match '<div class="input-control"><span class="label-wrapper"><label for="user_name">Name</label></span> <input class="input" id="user_name" name="user[name]" placeholder="a placeholder" style="width:100px;" type="text" value="Lalala" /> <span class="error">I have an error!</span> <span class="hint">This is a hint</span></div', f.input(:name, hint: 'Full Name', hint: 'This is a hint', error: 'I have an error!', placeholder: 'a placeholder', style: "width:100px;", class: 'input')
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class Reformed::FormHelperTest < ActionView::TestCase
|
4
|
+
|
5
|
+
setup do
|
6
|
+
@user = User.new
|
7
|
+
end
|
8
|
+
|
9
|
+
test "yields the correct form builder instance" do
|
10
|
+
output = reform_for :user, url: '/' do |f|
|
11
|
+
assert f.instance_of?(Reformed::FormBuilder)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
test "yields the correct form fields for builder instance" do
|
16
|
+
output = reform_for :user, url: '/' do |f|
|
17
|
+
f.reform_fields_for :lala do |ff|
|
18
|
+
assert ff.instance_of?(Reformed::FormBuilder)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
ENV["RAILS_ENV"] ||= "test"
|
2
|
+
#require File.expand_path('test/testapp/config/environment')
|
3
|
+
|
4
|
+
require 'minitest/autorun'
|
5
|
+
|
6
|
+
#require 'rails'
|
7
|
+
#require 'rails/test_help'
|
8
|
+
|
9
|
+
require 'active_record'
|
10
|
+
require 'active_support'
|
11
|
+
require 'active_support/test_case'
|
12
|
+
require 'active_model'
|
13
|
+
require 'action_controller'
|
14
|
+
require 'action_controller/test_case'
|
15
|
+
require 'action_view'
|
16
|
+
require 'action_view/template'
|
17
|
+
require 'action_view/test_case'
|
18
|
+
|
19
|
+
require 'reformed'
|
20
|
+
require 'reformed/form_helper'
|
21
|
+
|
22
|
+
require 'mocha/setup'
|
23
|
+
|
24
|
+
ActionView::Base.send :include, Reformed::FormHelper
|
25
|
+
ActionView::TestCase.send :include, Reformed::FormHelper
|
26
|
+
|
27
|
+
class User
|
28
|
+
include ActiveModel::Model
|
29
|
+
|
30
|
+
cattr_accessor :columns
|
31
|
+
self.columns = []
|
32
|
+
|
33
|
+
def self.column(name, sql_type = nil, default = nil, null = true)
|
34
|
+
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
|
35
|
+
attr_accessor name
|
36
|
+
end
|
37
|
+
|
38
|
+
def all
|
39
|
+
return []
|
40
|
+
end
|
41
|
+
|
42
|
+
column :name, :string
|
43
|
+
column :url, :string
|
44
|
+
column :email, :string
|
45
|
+
column :age, :integer
|
46
|
+
column :price, :float
|
47
|
+
column :currency, :decimal
|
48
|
+
column :birthdate, :datetime
|
49
|
+
column :phone, :string
|
50
|
+
|
51
|
+
column :gender, :string
|
52
|
+
|
53
|
+
column :datecolumn, :date
|
54
|
+
column :timecolumn, :time
|
55
|
+
column :timestampcolumn, :timestamp
|
56
|
+
column :body, :text
|
57
|
+
column :cute, :boolean
|
58
|
+
|
59
|
+
def column_for_attribute(attr)
|
60
|
+
columns.select { |c| c.name.to_s == attr.to_s }.first
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
#class User < FakeModel
|
66
|
+
#column :name, :string
|
67
|
+
#column :email, :string
|
68
|
+
#end
|
metadata
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: reformed
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jason Torres
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-09-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: &70336038792340 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70336038792340
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: mocha
|
27
|
+
requirement: &70336038791800 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70336038791800
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
requirement: &70336038791060 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70336038791060
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: activerecord
|
49
|
+
requirement: &70336038790040 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 4.0.0
|
55
|
+
- - <
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '4.1'
|
58
|
+
type: :development
|
59
|
+
prerelease: false
|
60
|
+
version_requirements: *70336038790040
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: railties
|
63
|
+
requirement: &70336038788960 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 4.0.0
|
69
|
+
- - <
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '4.1'
|
72
|
+
type: :development
|
73
|
+
prerelease: false
|
74
|
+
version_requirements: *70336038788960
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: activemodel
|
77
|
+
requirement: &70336038788040 !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 4.0.0
|
83
|
+
- - <
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '4.1'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: *70336038788040
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: actionpack
|
91
|
+
requirement: &70336038787140 !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 4.0.0
|
97
|
+
- - <
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '4.1'
|
100
|
+
type: :development
|
101
|
+
prerelease: false
|
102
|
+
version_requirements: *70336038787140
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: activesupport
|
105
|
+
requirement: &70336038786220 !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 4.0.0
|
111
|
+
- - <
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '4.1'
|
114
|
+
type: :development
|
115
|
+
prerelease: false
|
116
|
+
version_requirements: *70336038786220
|
117
|
+
description: Better Rails Forms
|
118
|
+
email:
|
119
|
+
- jason.e.torres@gmail.com
|
120
|
+
executables: []
|
121
|
+
extensions: []
|
122
|
+
extra_rdoc_files: []
|
123
|
+
files:
|
124
|
+
- .gitignore
|
125
|
+
- Gemfile
|
126
|
+
- LICENSE.txt
|
127
|
+
- README.md
|
128
|
+
- Rakefile
|
129
|
+
- lib/reformed.rb
|
130
|
+
- lib/reformed/form_builder.rb
|
131
|
+
- lib/reformed/form_helper.rb
|
132
|
+
- lib/reformed/railtie.rb
|
133
|
+
- lib/reformed/version.rb
|
134
|
+
- reformed.gemspec
|
135
|
+
- test/reformed/form_builder_test.rb
|
136
|
+
- test/reformed/form_helper_test.rb
|
137
|
+
- test/reformed/reformed_test.rb
|
138
|
+
- test/test_helper.rb
|
139
|
+
homepage: http://github.com/vixon/reformed
|
140
|
+
licenses:
|
141
|
+
- MIT
|
142
|
+
post_install_message:
|
143
|
+
rdoc_options: []
|
144
|
+
require_paths:
|
145
|
+
- lib
|
146
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
147
|
+
none: false
|
148
|
+
requirements:
|
149
|
+
- - ! '>='
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
requirements: []
|
159
|
+
rubyforge_project:
|
160
|
+
rubygems_version: 1.8.15
|
161
|
+
signing_key:
|
162
|
+
specification_version: 3
|
163
|
+
summary: A better rails form builder that supports multiple
|
164
|
+
test_files:
|
165
|
+
- test/reformed/form_builder_test.rb
|
166
|
+
- test/reformed/form_helper_test.rb
|
167
|
+
- test/reformed/reformed_test.rb
|
168
|
+
- test/test_helper.rb
|