sequel-crushyform 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -3
- data/lib/sequel_crushyform.rb +3 -2
- data/sequel-crushyform.gemspec +1 -1
- data/test/spec_crushyform.rb +15 -0
- metadata +4 -4
data/README.md
CHANGED
@@ -60,15 +60,15 @@ Options give the action URL and method.
|
|
60
60
|
|
61
61
|
Now say you want to have all the default options, but you want a wrapping form tag, you can do that:
|
62
62
|
|
63
|
-
BlogPost.new.crushyform(
|
63
|
+
BlogPost.new.crushyform( BlogPost.crushyform_schema.keys, "/new_blog" ) # Returns a nice form (a crushy form to be precise)
|
64
64
|
|
65
|
-
You have to put the default value `
|
65
|
+
You have to put the default value `Model.crushyform_schema.keys` because in the order of priority, the list of columns is more important
|
66
66
|
|
67
67
|
This is due to the fact that in a real case scenario we are more likely to use the version without a wrapping form tag.
|
68
68
|
Mainly because we want to add some other hidden inputs like a destination, a method override in order to generate a PUT request or a pseudo XHR value.
|
69
69
|
|
70
70
|
Another reason might be that you want to add other fields to the tag.
|
71
|
-
The default tag is pretty basic
|
71
|
+
The default tag is pretty basic.
|
72
72
|
|
73
73
|
CSS CLASSES
|
74
74
|
===========
|
@@ -301,6 +301,7 @@ CHANGE LOG
|
|
301
301
|
0.0.2 Use HTML5 attribute `required`
|
302
302
|
0.0.3 Fix a bug on the default value for label :name
|
303
303
|
0.0.4 Fix type `:none`
|
304
|
+
0.0.5 Crushyform method guesses the enctype
|
304
305
|
|
305
306
|
COPYRIGHT
|
306
307
|
=========
|
data/lib/sequel_crushyform.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module ::Sequel::Plugins::Crushyform
|
2
2
|
|
3
3
|
module ClassMethods
|
4
|
-
def crushyform_version; [0,0,
|
4
|
+
def crushyform_version; [0,0,5]; end
|
5
5
|
# Schema
|
6
6
|
def crushyform_schema
|
7
7
|
@crushyform_schema ||= default_crushyform_schema
|
@@ -101,7 +101,8 @@ module ::Sequel::Plugins::Crushyform
|
|
101
101
|
def crushyform(columns=model.crushyform_schema.keys, action=nil, meth='POST')
|
102
102
|
columns.delete(:id)
|
103
103
|
fields = columns.inject(""){|out,c|out+crushyfield(c.to_sym)}
|
104
|
-
|
104
|
+
enctype = fields.match(/type='file'/) ? "enctype='multipart/form-data'" : ''
|
105
|
+
action.nil? ? fields : "<form action='%s' method='%s' %s>%s</form>\n" % [action, meth, enctype, fields]
|
105
106
|
end
|
106
107
|
# crushyfield is crushyinput but with label+error
|
107
108
|
def crushyfield(col, o={})
|
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.5"
|
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
@@ -92,6 +92,16 @@ class Attached < ::Sequel::Model
|
|
92
92
|
::StashMagic.with_public_root ROOT+'/test'
|
93
93
|
end
|
94
94
|
|
95
|
+
class Pic < ::Sequel::Model
|
96
|
+
plugin :schema
|
97
|
+
set_schema do
|
98
|
+
primary_key :id
|
99
|
+
String :name
|
100
|
+
String :image, :crushyform=>{:type=>:attachment}
|
101
|
+
end
|
102
|
+
create_table unless table_exists?
|
103
|
+
end
|
104
|
+
|
95
105
|
# ========
|
96
106
|
# = Test =
|
97
107
|
# ========
|
@@ -368,6 +378,11 @@ describe 'Crushyform' do
|
|
368
378
|
form.should.not.match(/#{Haiku.new.crushyid_for(:id)}/)
|
369
379
|
end
|
370
380
|
|
381
|
+
should 'make forms with enctype automated' do
|
382
|
+
Haiku.new.crushyform(Haiku.crushyform_schema.keys, '/url').should.not.match(/enctype='multipart\/form-data'/)
|
383
|
+
Pic.new.crushyform(Pic.crushyform_schema.keys, '/url').should.match(/enctype='multipart\/form-data'/)
|
384
|
+
end
|
385
|
+
|
371
386
|
end
|
372
387
|
|
373
388
|
::FileUtils.rm_rf(ROOT+'/test/stash') if F.exists?(ROOT+'/test/stash')
|
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: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
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-08-04 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|