padrino-fields 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +40 -0
- data/Gemfile.lock +133 -0
- data/LICENSE.txt +20 -0
- data/README.markdown +189 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/lib/padrino-fields.rb +30 -0
- data/lib/padrino-fields/form_builder.rb +183 -0
- data/lib/padrino-fields/form_helpers.rb +63 -0
- data/lib/padrino-fields/orms/datamapper.rb +54 -0
- data/lib/padrino-fields/settings.rb +18 -0
- data/load_paths.rb +12 -0
- data/padrino-fields.gemspec +141 -0
- data/test/.DS_Store +0 -0
- data/test/fixtures/datamapper/app.rb +48 -0
- data/test/fixtures/datamapper/views/capture_concat.erb +14 -0
- data/test/fixtures/datamapper/views/capture_concat.haml +12 -0
- data/test/fixtures/datamapper/views/content_for.erb +11 -0
- data/test/fixtures/datamapper/views/content_for.haml +9 -0
- data/test/fixtures/datamapper/views/content_tag.erb +11 -0
- data/test/fixtures/datamapper/views/content_tag.haml +9 -0
- data/test/fixtures/datamapper/views/fields_for.erb +20 -0
- data/test/fixtures/datamapper/views/fields_for.haml +15 -0
- data/test/fixtures/datamapper/views/form_for.erb +56 -0
- data/test/fixtures/datamapper/views/form_for.haml +47 -0
- data/test/fixtures/datamapper/views/form_tag.erb +56 -0
- data/test/fixtures/datamapper/views/form_tag.haml +45 -0
- data/test/fixtures/datamapper/views/link_to.erb +5 -0
- data/test/fixtures/datamapper/views/link_to.haml +4 -0
- data/test/fixtures/datamapper/views/mail_to.erb +3 -0
- data/test/fixtures/datamapper/views/mail_to.haml +3 -0
- data/test/fixtures/datamapper/views/meta_tag.erb +3 -0
- data/test/fixtures/datamapper/views/meta_tag.haml +3 -0
- data/test/helper.rb +128 -0
- data/test/test_datamapper.rb +109 -0
- data/test/test_form_builder.rb +193 -0
- data/test/test_form_helpers.rb +59 -0
- data/test/test_settings.rb +51 -0
- metadata +288 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
source :rubygems
|
2
|
+
|
3
|
+
group :other do
|
4
|
+
gem "builder", ">= 2.1.2"
|
5
|
+
end
|
6
|
+
|
7
|
+
group :db do
|
8
|
+
gem "dm-core", ">= 1.0"
|
9
|
+
gem "dm-migrations", ">= 1.0"
|
10
|
+
gem "dm-validations", ">= 1.0"
|
11
|
+
gem "dm-aggregates", ">= 1.0"
|
12
|
+
gem "dm-sqlite-adapter", ">= 1.0"
|
13
|
+
end
|
14
|
+
|
15
|
+
group :development do
|
16
|
+
gem "rcov"
|
17
|
+
gem "jeweler"
|
18
|
+
gem "rake", ">= 0.8.7"
|
19
|
+
gem "mocha", ">= 0.9.8"
|
20
|
+
gem "rack-test", ">= 0.5.0"
|
21
|
+
gem "fakeweb", ">=1.2.8"
|
22
|
+
gem "webrat", ">= 0.5.1"
|
23
|
+
gem "haml", ">= 2.2.22"
|
24
|
+
gem "phocus"
|
25
|
+
gem "shoulda", ">= 2.10.3"
|
26
|
+
gem "uuid", ">= 2.3.1"
|
27
|
+
gem "bcrypt-ruby", :require => "bcrypt"
|
28
|
+
platforms :mri_18 do
|
29
|
+
gem "ruby-prof", ">= 0.9.1"
|
30
|
+
gem "system_timer", ">= 1.0"
|
31
|
+
end
|
32
|
+
platforms :mri do
|
33
|
+
gem "memcached", ">= 0.20.1"
|
34
|
+
gem 'dalli', ">=1.0.2"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
gem "padrino"
|
39
|
+
gem "padrino-core"
|
40
|
+
gem "padrino-helpers"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.0.5)
|
5
|
+
addressable (2.2.4)
|
6
|
+
bcrypt-ruby (2.1.4)
|
7
|
+
builder (3.0.0)
|
8
|
+
dalli (1.0.2)
|
9
|
+
data_objects (0.10.3)
|
10
|
+
addressable (~> 2.1)
|
11
|
+
dm-aggregates (1.0.2)
|
12
|
+
dm-core (~> 1.0.2)
|
13
|
+
dm-core (1.0.2)
|
14
|
+
addressable (~> 2.2)
|
15
|
+
extlib (~> 0.9.15)
|
16
|
+
dm-do-adapter (1.0.2)
|
17
|
+
data_objects (~> 0.10.2)
|
18
|
+
dm-core (~> 1.0.2)
|
19
|
+
dm-migrations (1.0.2)
|
20
|
+
dm-core (~> 1.0.2)
|
21
|
+
dm-sqlite-adapter (1.0.2)
|
22
|
+
dm-do-adapter (~> 1.0.2)
|
23
|
+
do_sqlite3 (~> 0.10.2)
|
24
|
+
dm-validations (1.0.2)
|
25
|
+
dm-core (~> 1.0.2)
|
26
|
+
do_sqlite3 (0.10.3)
|
27
|
+
data_objects (= 0.10.3)
|
28
|
+
extlib (0.9.15)
|
29
|
+
fakeweb (1.3.0)
|
30
|
+
git (1.2.5)
|
31
|
+
haml (3.0.25)
|
32
|
+
http_router (0.5.4)
|
33
|
+
rack (>= 1.0.0)
|
34
|
+
url_mount (~> 0.2.1)
|
35
|
+
i18n (0.5.0)
|
36
|
+
jeweler (1.5.2)
|
37
|
+
bundler (~> 1.0.0)
|
38
|
+
git (>= 1.2.5)
|
39
|
+
rake
|
40
|
+
macaddr (1.0.0)
|
41
|
+
mail (2.2.15)
|
42
|
+
activesupport (>= 2.3.6)
|
43
|
+
i18n (>= 0.4.0)
|
44
|
+
mime-types (~> 1.16)
|
45
|
+
treetop (~> 1.4.8)
|
46
|
+
memcached (1.2.1)
|
47
|
+
mime-types (1.16)
|
48
|
+
mocha (0.9.12)
|
49
|
+
nokogiri (1.4.4)
|
50
|
+
padrino (0.9.23)
|
51
|
+
padrino-admin (= 0.9.23)
|
52
|
+
padrino-cache (= 0.9.23)
|
53
|
+
padrino-core (= 0.9.23)
|
54
|
+
padrino-gen (= 0.9.23)
|
55
|
+
padrino-helpers (= 0.9.23)
|
56
|
+
padrino-mailer (= 0.9.23)
|
57
|
+
padrino-admin (0.9.23)
|
58
|
+
padrino-core (= 0.9.23)
|
59
|
+
padrino-helpers (= 0.9.23)
|
60
|
+
padrino-cache (0.9.23)
|
61
|
+
padrino-core (= 0.9.23)
|
62
|
+
padrino-core (0.9.23)
|
63
|
+
activesupport (>= 3.0.0)
|
64
|
+
http_router (~> 0.5.4)
|
65
|
+
sinatra (~> 1.2.0)
|
66
|
+
thor (>= 0.14.3)
|
67
|
+
tzinfo
|
68
|
+
padrino-gen (0.9.23)
|
69
|
+
bundler (>= 1.0.2)
|
70
|
+
git
|
71
|
+
padrino-core (= 0.9.23)
|
72
|
+
padrino-helpers (0.9.23)
|
73
|
+
i18n (>= 0.4.1)
|
74
|
+
padrino-core (= 0.9.23)
|
75
|
+
padrino-mailer (0.9.23)
|
76
|
+
mail (>= 2.2.0)
|
77
|
+
padrino-core (= 0.9.23)
|
78
|
+
phocus (1.1)
|
79
|
+
polyglot (0.3.1)
|
80
|
+
rack (1.2.1)
|
81
|
+
rack-test (0.5.7)
|
82
|
+
rack (>= 1.0)
|
83
|
+
rake (0.8.7)
|
84
|
+
rcov (0.9.9)
|
85
|
+
ruby-prof (0.9.2)
|
86
|
+
shoulda (2.11.3)
|
87
|
+
sinatra (1.2.0)
|
88
|
+
rack (~> 1.1)
|
89
|
+
tilt (>= 1.2.2, < 2.0)
|
90
|
+
system_timer (1.0)
|
91
|
+
thor (0.14.6)
|
92
|
+
tilt (1.2.2)
|
93
|
+
treetop (1.4.9)
|
94
|
+
polyglot (>= 0.3.1)
|
95
|
+
tzinfo (0.3.24)
|
96
|
+
url_mount (0.2.1)
|
97
|
+
rack
|
98
|
+
uuid (2.3.1)
|
99
|
+
macaddr (~> 1.0)
|
100
|
+
webrat (0.7.3)
|
101
|
+
nokogiri (>= 1.2.0)
|
102
|
+
rack (>= 1.0)
|
103
|
+
rack-test (>= 0.5.3)
|
104
|
+
|
105
|
+
PLATFORMS
|
106
|
+
ruby
|
107
|
+
|
108
|
+
DEPENDENCIES
|
109
|
+
bcrypt-ruby
|
110
|
+
builder (>= 2.1.2)
|
111
|
+
dalli (>= 1.0.2)
|
112
|
+
dm-aggregates (>= 1.0)
|
113
|
+
dm-core (>= 1.0)
|
114
|
+
dm-migrations (>= 1.0)
|
115
|
+
dm-sqlite-adapter (>= 1.0)
|
116
|
+
dm-validations (>= 1.0)
|
117
|
+
fakeweb (>= 1.2.8)
|
118
|
+
haml (>= 2.2.22)
|
119
|
+
jeweler
|
120
|
+
memcached (>= 0.20.1)
|
121
|
+
mocha (>= 0.9.8)
|
122
|
+
padrino
|
123
|
+
padrino-core
|
124
|
+
padrino-helpers
|
125
|
+
phocus
|
126
|
+
rack-test (>= 0.5.0)
|
127
|
+
rake (>= 0.8.7)
|
128
|
+
rcov
|
129
|
+
ruby-prof (>= 0.9.1)
|
130
|
+
shoulda (>= 2.10.3)
|
131
|
+
system_timer (>= 1.0)
|
132
|
+
uuid (>= 2.3.1)
|
133
|
+
webrat (>= 0.5.1)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Steven Garcia
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,189 @@
|
|
1
|
+
# PadrinoFields
|
2
|
+
|
3
|
+
Forms made easy for the **[Padrino Framework](http://www.padrinorb.com)**
|
4
|
+
|
5
|
+
Takes the pain out of building forms. Generates inputs, labels and field hints with a minimal and flexible DSL. Currently only supports **[DataMapper](http://datamapper.org/)**, but plugging more ORMs in will be trivial due to modular design (See below)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Install the gem:
|
10
|
+
|
11
|
+
gem install padrino-fields
|
12
|
+
|
13
|
+
Add it to your Gemfile:
|
14
|
+
|
15
|
+
gem "padrino-fields"
|
16
|
+
|
17
|
+
|
18
|
+
Initialize it in your **app.rb**
|
19
|
+
|
20
|
+
register PadrinoFields
|
21
|
+
|
22
|
+
set :default_builder, 'PadrinoFieldsBuilder'
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
The heart of **PadrinoFields** is the **:input** method
|
27
|
+
|
28
|
+
- form_for @user do |f|
|
29
|
+
= f.input :username
|
30
|
+
= f.input :password
|
31
|
+
= f.submit
|
32
|
+
|
33
|
+
This will generate a form with labels for username and password - supplying the appropriate inputs, labels and error messages on missing/invalid fields. **PadrinoFields** looks at your database columns to generate default inputs.
|
34
|
+
|
35
|
+
### Field Customization
|
36
|
+
|
37
|
+
Override the default input type like so:
|
38
|
+
|
39
|
+
= f.input :description, :as => :text
|
40
|
+
= f.input :joined_on, :as => :string
|
41
|
+
= f.accept_terms, :as => :boolean
|
42
|
+
|
43
|
+
Add custom label text, field hints and more:
|
44
|
+
|
45
|
+
= f.input :username, :caption => 'You will login with this name'
|
46
|
+
= f.input :password, :hint => 'Letters and numbers only'
|
47
|
+
|
48
|
+
Disable labels, hints or errors:
|
49
|
+
|
50
|
+
= f.input :username, :caption => false
|
51
|
+
= f.input :password, :hint => false
|
52
|
+
= f.input :email, :disabled => true
|
53
|
+
|
54
|
+
Pass html attribute straight to the input:
|
55
|
+
|
56
|
+
= f.input :username, :input_html => { :class => 'special' }
|
57
|
+
= f.input :password, :input_html => { :maxlength => 20 }
|
58
|
+
= f.input :remember_me, :input_html => { :value => '1' }
|
59
|
+
|
60
|
+
### Options / Collections
|
61
|
+
|
62
|
+
Options can be arrays or ranges, and when a **:options** is given the **:select** input will be rendered by default, so we don't need to pass the **:as => :select** option.
|
63
|
+
|
64
|
+
= f.input :user, :options => User.all.map(&:name)
|
65
|
+
|
66
|
+
Use ranges as options for your select tags
|
67
|
+
|
68
|
+
= f.input :year, :options => (1950..Time.now.year)
|
69
|
+
|
70
|
+
Options may also be rendered as **:radios** and **:checks**
|
71
|
+
|
72
|
+
= f.input :user, :options => User.all.map(&:name), :as => :radios
|
73
|
+
|
74
|
+
You can produce optgroups using **:grouped_options**
|
75
|
+
|
76
|
+
# Using a Hash
|
77
|
+
options = {
|
78
|
+
"Friends" => ["Yoda","Obiwan"],
|
79
|
+
"Enemies" => ["Palpatine","Darth Vader"]
|
80
|
+
}
|
81
|
+
|
82
|
+
# Using an Array
|
83
|
+
options = [
|
84
|
+
["Friends",["Yoda","Obiwan"],
|
85
|
+
["Enemies", ["Palpatine","Darth Vader"]]
|
86
|
+
]
|
87
|
+
|
88
|
+
= f.input :user, :grouped_options => options
|
89
|
+
|
90
|
+
### Available Inputs
|
91
|
+
|
92
|
+
Mapping | Input | Column Type
|
93
|
+
:-------------|:----------------|:------------------------------------
|
94
|
+
**:boolean** |check box |boolean
|
95
|
+
**:string** |text field |string
|
96
|
+
**:email** |email field |string with name matching "email"
|
97
|
+
**:url** |url field |string with name matching "url"
|
98
|
+
**:tel** |tel field |string with name matching "phone"
|
99
|
+
**:password** |password field |string with name matching "password"
|
100
|
+
**:search** |search |string with name matching "search"
|
101
|
+
**:text** |text area |text
|
102
|
+
**:file** |file field |string, responding to file methods
|
103
|
+
**:number** |number field |integer, float, decimal
|
104
|
+
**:date** |date field |date, datetime, timestamps
|
105
|
+
**:select** |select |-
|
106
|
+
**:radios** |radio buttons |-
|
107
|
+
**:checks** |check boxes |-
|
108
|
+
|
109
|
+
|
110
|
+
### Validations
|
111
|
+
|
112
|
+
By default all inputs are optional. **PadrinoFields** looks at your model validations to see if a field's presence is required and will mark it by prepending a * to the label.
|
113
|
+
|
114
|
+
# app/models/person.rb
|
115
|
+
class Person
|
116
|
+
validates_presence_of :name
|
117
|
+
|
118
|
+
# app/views/people/_form.haml
|
119
|
+
= f.input :name
|
120
|
+
|
121
|
+
=> <label><abbr>*<abbr>Name</label><input ...
|
122
|
+
|
123
|
+
You can also do it manually with the **:required** option
|
124
|
+
|
125
|
+
= f.input :email, :required => true
|
126
|
+
|
127
|
+
### Settings
|
128
|
+
|
129
|
+
You can override a few default settings by creating a lib file as follows:
|
130
|
+
|
131
|
+
PadrinoFields::Settings.configure do |config|
|
132
|
+
|
133
|
+
config.container = :p
|
134
|
+
# Tag which wraps the inputs and labels
|
135
|
+
|
136
|
+
config.label_required_marker = "<abbr>*</abbr>"
|
137
|
+
# Visual indicator of a required field
|
138
|
+
|
139
|
+
config.label_required_marker_position = :prepend
|
140
|
+
# Placement of marker, either :append or :prepend (default)
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
|
145
|
+
## ORM Support
|
146
|
+
|
147
|
+
So far only Datamapper is supported, but since the code is decoupled it should be relatively easy to support others:
|
148
|
+
|
149
|
+
1. Clone **padrino-fields/orms/datamapper.rb** and extend your ORM in a similar fashion
|
150
|
+
2. Clone **test/fixtures/datamapper** and substitute the models with your ORM
|
151
|
+
3. Clone **test/test_datamapper.rb** to write tests
|
152
|
+
4. Open **lib/padrino-fields/form_builder.rb**
|
153
|
+
|
154
|
+
Require your orm file and include its module as follows:
|
155
|
+
|
156
|
+
require File.expand_path(File.dirname(__FILE__) + '/orms/mycoolorm') if defined?(MyCoolOrm)
|
157
|
+
|
158
|
+
module Padrino
|
159
|
+
module Helpers
|
160
|
+
module FormBuilder
|
161
|
+
class PadrinoFields < AbstractFormBuilder #:nodoc:
|
162
|
+
|
163
|
+
include PadrinoFields::MyCoolOrm if defined?(MyCoolOrm)
|
164
|
+
|
165
|
+
## Todo
|
166
|
+
|
167
|
+
* Add country select
|
168
|
+
* Generators for config and views
|
169
|
+
* I18n integration
|
170
|
+
* More documentation
|
171
|
+
|
172
|
+
## Bug reports
|
173
|
+
|
174
|
+
If you discover any bugs, feel free to create an issue on GitHub. Please add as much information as possible to help us fix the problem. You can be an even bigger help by forking and sending a pull request. Be sure to include tests with your code!
|
175
|
+
|
176
|
+
[http://github.com/activestylus/padrino-field/issues](http://github.com/activestylus/padrino-field/issues)
|
177
|
+
|
178
|
+
## Credit
|
179
|
+
|
180
|
+
This gem borrows heavily from the following projects:
|
181
|
+
|
182
|
+
* [Formtastic](http://github.com/justinfrench/formtastic)
|
183
|
+
* [SimpleForm](http://github.com/plataformatec/simple_form)
|
184
|
+
|
185
|
+
Many thanks to [Justin French](https://github.com/justinfrench) and [Jose Valim](https://github.com/josevalim) for the inspiration. Extra shouts to [Nathan Esquenazi](https://github.com/nesquena) and [Davide d'Agostino](https://github.com/DAddYE) for lending a hand on the [google group](https://groups.google.com/forum/#!forum/padrino)
|
186
|
+
|
187
|
+
## License
|
188
|
+
|
189
|
+
MIT License. Copyright 2011 Steven Garcia
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "padrino-fields"
|
16
|
+
gem.homepage = "http://github.com/activestylus/padrino-fields"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{Advanced form helpers for Padrino framework}
|
19
|
+
gem.description = %Q{Smart fields for your forms, similar to Formtastic or SimpleForm}
|
20
|
+
gem.email = "stevendgarcia@gmail.com"
|
21
|
+
gem.authors = ["Steven Garcia"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
Rake::TestTask.new(:test) do |test|
|
31
|
+
test.libs << 'lib' << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'rcov/rcovtask'
|
37
|
+
Rcov::RcovTask.new do |test|
|
38
|
+
test.libs << 'test'
|
39
|
+
test.pattern = 'test/**/test_*.rb'
|
40
|
+
test.verbose = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "padrino-fields #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.3.3
|