sinatra-formkeeper 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -6,7 +6,7 @@ gemspec
6
6
  gem "hpricot"
7
7
  gem "rack"
8
8
  gem "sinatra"
9
- gem "formkeeper", "~> 0.0.4"
9
+ gem "formkeeper", "~> 0.0.5"
10
10
 
11
11
  group :development, :test do
12
12
  gem "rspec"
data/README.md CHANGED
@@ -66,6 +66,118 @@ Calling 'form' with block which includes rule-setting,
66
66
  you can build a form-rule.
67
67
  There are some DSL-method to build rules. In this example, 'filters' and 'field' are written.
68
68
 
69
+ #### filters
70
+
71
+ You can set 'filters'. All input parameters are filtered by indicated filtering feature
72
+ The filtering process is executed before validation.
73
+
74
+ form do
75
+ filters :strip
76
+ ...
77
+ end
78
+
79
+ You can set multiple filters at once
80
+
81
+ form do
82
+ filters :strip, :downcase
83
+ ...
84
+ end
85
+
86
+ All preset filters are described at [8: Preset Filters]
87
+
88
+ #### field
89
+
90
+ You can add a setting for each field
91
+
92
+ form do
93
+ field :field_name, :present => true, length => 0..10
94
+ ...
95
+ end
96
+
97
+ This constraint works for an input form named as "field_name", for instance
98
+
99
+ <input type="text" name="field_name" />
100
+
101
+ And key-value pares are following the field name.
102
+ They are constraints set for the field.
103
+ You can add your favorite constraints here.
104
+
105
+ All preset constraints are described at [9: Preset Constraints]
106
+ Read the chapter for more detail.
107
+
108
+ And you can set filters here,
109
+ if you don't want to filter all the parameters included in the request.
110
+ This filtering setting only affets on :field_name.
111
+
112
+ form do
113
+ field :field_name, :present => true, filters => [:strip, :downcase]
114
+ ...
115
+ end
116
+
117
+ You can set as just one single symbol, if you don't need multiple filters.
118
+
119
+ form do
120
+ field :field_name, :present => true, filters => :strip
121
+ ...
122
+ end
123
+
124
+ #### checkbox
125
+
126
+ You also can set the rule like this.
127
+
128
+ form do
129
+ checkbox :field_name, :count => 1..3, int => true
130
+ ...
131
+ end
132
+
133
+ This is just for field which has multiple values.
134
+ For instance,
135
+
136
+ <input type="checkbox" name="field_name[]" value="1" checked>
137
+ <label>check1</label>
138
+ <input type="checkbox" name="field_name[]" value="2" checked>
139
+ <label>check2</label>
140
+ <input type="checkbox" name="field_name[]" value="3" checked>
141
+ <label>check3</label>
142
+
143
+ Or
144
+
145
+ <select name="favorite[]" multiple>
146
+ <option value="1" selected="selected">white</option>
147
+ <option value="2">black</option>
148
+ <option value="3">blue</option>
149
+ </select>
150
+
151
+ Rack request handle such type of name (exp: field_name[]) as Array.
152
+ For this type of input, use 'checkbox' method.
153
+ In this case, you must use :count constraints instead of :present.
154
+
155
+ #### combination
156
+
157
+ There is another special rule, 'Combination'
158
+
159
+ form do
160
+ combination :same_address, :fields => ["email01", "email02"], :same => true
161
+ combination :favorite_color, :fields => ["white", "black", "blue"], :any => true
162
+ end
163
+
164
+ Set rule-name as a first argument.
165
+ And you should set multiple target fields.
166
+ And one constraint like (:same => true), or (:any => true).
167
+
168
+ :same and :any are called as 'Combination Constraint'
169
+ For this purpose, formkeeper provides you a simple way to do same things.
170
+
171
+ form do
172
+ same :same_address, ["email01", "email02"]
173
+ any :favorite_color, ["white", "black", "blue"]
174
+ end
175
+
176
+ You can call a name of 'Combination Constraints' as a method.
177
+ Followed by rule-name and target-fields.
178
+
179
+ All preset constraints are described at [10: Preset Combination Constraints]
180
+
69
181
  ### 2: Check if user's input is valid or not
70
182
 
71
183
  'form.failed?' can be used to judge if user's input is valid for the rule you build.
@@ -262,7 +374,36 @@ If you want to show messages for each field, separately, of course you can.
262
374
  </body>
263
375
  </html>
264
376
 
265
- ### 8: Utilize Plugins
377
+ ### 8: Preset Filters
378
+
379
+ #### strip
380
+ #### downcase
381
+ #### upcase
382
+
383
+ ### 9: Preset Constraints
384
+
385
+ #### present
386
+ #### length
387
+ #### bytesize
388
+ #### ascii
389
+ #### regexp
390
+ #### int
391
+ #### uint
392
+ #### alpha
393
+ #### alpha_space
394
+ #### alnum
395
+ #### alnum_space
396
+ #### uri
397
+
398
+ ### 10: Preset Combination Constraints
399
+
400
+ #### same
401
+ #### any
402
+ #### date
403
+ #### time
404
+ #### datetime
405
+
406
+ ### 11: Utilize Plugins
266
407
 
267
408
  require 'formkeeper/japanese'
268
409
 
@@ -272,7 +413,7 @@ If you want to show messages for each field, separately, of course you can.
272
413
  end
273
414
  end
274
415
 
275
- ### 9: Custom Filter
416
+ ### 12: Custom Filter
276
417
 
277
418
  form_filter :my_capitalize_filter do |value|
278
419
  value.capitalize
@@ -285,7 +426,7 @@ If you want to show messages for each field, separately, of course you can.
285
426
  end
286
427
 
287
428
 
288
- ### 10: Custom Constraint
429
+ ### 13: Custom Constraint
289
430
 
290
431
  ## See Also
291
432
 
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module FormKeeper
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-formkeeper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-23 00:00:00.000000000 Z
12
+ date: 2012-10-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Sinatra extension which handles stuff around HTML forms
15
15
  email: