sequel-crushyform 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +17 -9
- data/lib/sequel_crushyform.rb +2 -2
- data/sequel-crushyform.gemspec +1 -1
- data/test/spec_crushyform.rb +10 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
CRUSHYFORM
|
2
2
|
==========
|
3
3
|
|
4
|
+
Every toolkit has a screwdriver and this one is a cruciform.
|
5
|
+
|
4
6
|
Crushyform is a Sequel plugin that helps building forms.
|
5
7
|
It basically does them for you so that you can forget about the boring part.
|
6
8
|
The kind of thing which is good to have in your toolbox for building a CMS.
|
@@ -10,6 +12,8 @@ We tried to make it as modular as possible but with sensible default values.
|
|
10
12
|
I am also aware that this documentation is new and might lack some crucial information
|
11
13
|
but feel free to drop me a line if you have any question.
|
12
14
|
|
15
|
+
By the way, I'd like to thank [Jeremy Evans](https://github.com/jeremyevans) for answering so many questions on the #sequel IRC channel.
|
16
|
+
|
13
17
|
HOW TO INSTALL ?
|
14
18
|
================
|
15
19
|
|
@@ -148,18 +152,21 @@ instead of trying to complicate something that is gonna be ugly at the end anywa
|
|
148
152
|
Also if you want to use a proper time field (just time with no date), don't forget to declare it all lowercase in your schema.
|
149
153
|
Otherwise it will use the Time ruby class which is a time including the date:
|
150
154
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
155
|
+
set_schema do
|
156
|
+
primary_key :id
|
157
|
+
Time :opening_hour # type is :datetime
|
158
|
+
time :opening_hour # type is :time
|
159
|
+
end
|
160
|
+
|
161
|
+
I wish I could use HTML5 date/time fields, but they are not implemented in many browsers yet, and
|
162
|
+
it does not allow to ask for a specific format, which is a not really nice.
|
156
163
|
|
157
164
|
MORE ABOUT ATTACHMENT FIELD
|
158
165
|
---------------------------
|
159
166
|
|
160
167
|
Regarding the :attachment type, it should be able to work with any kind of system.
|
161
168
|
We made it simple and customizable enough to adapt to many attachment solutions.
|
162
|
-
|
169
|
+
I called it :attachment because I never really use blobs, but it might be used with blobs as well.
|
163
170
|
Once again because it is very basic.
|
164
171
|
|
165
172
|
This is typically the kind of field that cannot really be guessed by crushyform.
|
@@ -205,14 +212,14 @@ Or you can override the final instance method `Model::to_label`:
|
|
205
212
|
self.my_label_column
|
206
213
|
end
|
207
214
|
|
208
|
-
The good thing that this method is very useful in many places of CMS of your application, and even the front end:
|
215
|
+
The good thing is that this method is very useful in many places of CMS of your application, and even the front end:
|
209
216
|
|
210
217
|
@author.to_label
|
211
218
|
|
212
219
|
It could even work with addresses.
|
213
220
|
Crushyform turns a multi-line text in a one liner if it is the label column.
|
214
221
|
|
215
|
-
# Say the class Address has a column called :body which is the
|
222
|
+
# Say the class Address has a column called :body which is the last choice for a label in LABEL_COLUMNS
|
216
223
|
#
|
217
224
|
# 4, Virginia Street
|
218
225
|
# Flat C
|
@@ -291,8 +298,9 @@ CHANGE LOG
|
|
291
298
|
==========
|
292
299
|
|
293
300
|
0.0.1 First version
|
301
|
+
0.0.2 Use HTML5 attribute `required`
|
294
302
|
|
295
303
|
COPYRIGHT
|
296
304
|
=========
|
297
305
|
|
298
|
-
(c) 2011 Mickael Riga - see file
|
306
|
+
(c) 2011 Mickael Riga - see file LICENSE for details
|
data/lib/sequel_crushyform.rb
CHANGED
@@ -24,7 +24,7 @@ module ::Sequel::Plugins::Crushyform
|
|
24
24
|
@crushyform_types ||= {
|
25
25
|
:none => proc{''},
|
26
26
|
:string => proc do |m,c,o|
|
27
|
-
"<input type='%s' name='%s' value='%s' id='%s' class='%s' />%s\n" % [o[:input_type]||'text', o[:input_name], o[:input_value], m.crushyid_for(c), o[:input_class], o[:required]]
|
27
|
+
"<input type='%s' name='%s' value='%s' id='%s' class='%s' %s />%s\n" % [o[:input_type]||'text', o[:input_name], o[:input_value], m.crushyid_for(c), o[:input_class], o[:required]&&'required', o[:required]]
|
28
28
|
end,
|
29
29
|
:boolean => proc do |m,c,o|
|
30
30
|
crushid = m.crushyid_for(c)
|
@@ -37,7 +37,7 @@ module ::Sequel::Plugins::Crushyform
|
|
37
37
|
out % [o[:input_class], o[:input_name], crushid, s[0], crushid, o[:input_name], crushid, s[1], crushid]
|
38
38
|
end,
|
39
39
|
:text => proc do |m,c,o|
|
40
|
-
"<textarea name='%s' id='%s' class='%s'>%s</textarea>%s\n" % [o[:input_name], m.crushyid_for(c), o[:input_class], o[:input_value], o[:required]]
|
40
|
+
"<textarea name='%s' id='%s' class='%s' %s>%s</textarea>%s\n" % [o[:input_name], m.crushyid_for(c), o[:input_class], o[:required]&&'required', o[:input_value], o[:required]]
|
41
41
|
end,
|
42
42
|
:date => proc do |m,c,o|
|
43
43
|
o[:input_value] = "%s-%s-%s" % [o[:input_value].year, o[:input_value].month, o[:input_value].day] if o[:input_value].is_a?(Sequel.datetime_class)
|
data/sequel-crushyform.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'sequel-crushyform'
|
3
|
-
s.version = "0.0.
|
3
|
+
s.version = "0.0.2"
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
5
|
s.summary = "A Sequel plugin that helps building forms"
|
6
6
|
s.description = "A Sequel plugin that helps building forms. It basically does them for you so that you can forget about the boring part. The kind of thing which is good to have in your toolbox for building a CMS."
|
data/test/spec_crushyform.rb
CHANGED
@@ -278,13 +278,22 @@ describe 'Crushyfield types' do
|
|
278
278
|
|
279
279
|
should 'have :required option which is a text representing requirement and defaulting to blank' do
|
280
280
|
Review.new.crushyinput(:title).should.not.match(/#{Regexp.escape Review.crushyfield_required}/)
|
281
|
-
Review.new.crushyinput(:title,{:required=>"
|
281
|
+
Review.new.crushyinput(:title,{:required=>" Required field"}).should.match(/Required field/)
|
282
282
|
end
|
283
283
|
|
284
284
|
should 'use the default requirement text when :required option is true instead of a string' do
|
285
285
|
Review.new.crushyinput(:title,{:required=>true}).should.match(/#{Regexp.escape Review.crushyfield_required}/)
|
286
286
|
end
|
287
287
|
|
288
|
+
should 'use HTML5 required attribute on required fields' do
|
289
|
+
Review.new.crushyinput(:title).should.match(/class='' \/>/)
|
290
|
+
Review.new.crushyinput(:title,{:required=>true}).should.match(/class='' required \/>/)
|
291
|
+
Review.new.crushyinput(:title,{:required=>"Must Be"}).should.match(/class='' required \/>/)
|
292
|
+
Review.new.crushyinput(:body).should.match(/class='' >/)
|
293
|
+
Review.new.crushyinput(:body,{:required=>true}).should.match(/class='' required>/)
|
294
|
+
Review.new.crushyinput(:body,{:required=>"Must Be"}).should.match(/class='' required>/)
|
295
|
+
end
|
296
|
+
|
288
297
|
should 'format date/time/datetime correctly' do
|
289
298
|
TestDateTime.new.db_schema[:meeting][:type].should== :time # Check that the correct type is used for following tests (see README)
|
290
299
|
TestDateTime.new.crushyinput(:birth).should.match(/value=''/)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel-crushyform
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mickael Riga
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-07-13 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|