sequel-crushyform 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -299,6 +299,7 @@ CHANGE LOG
299
299
 
300
300
  0.0.1 First version
301
301
  0.0.2 Use HTML5 attribute `required`
302
+ 0.0.3 Fix a bug on the default value for label :name
302
303
 
303
304
  COPYRIGHT
304
305
  =========
@@ -1,7 +1,7 @@
1
1
  module ::Sequel::Plugins::Crushyform
2
2
 
3
3
  module ClassMethods
4
- def crushyform_version; [0,0,1]; end
4
+ def crushyform_version; [0,0,3]; end
5
5
  # Schema
6
6
  def crushyform_schema
7
7
  @crushyform_schema ||= default_crushyform_schema
@@ -99,12 +99,13 @@ module ::Sequel::Plugins::Crushyform
99
99
 
100
100
  module InstanceMethods
101
101
  def crushyform(columns=model.crushyform_schema.keys, action=nil, meth='POST')
102
+ columns.delete(:id)
102
103
  fields = columns.inject(""){|out,c|out+crushyfield(c.to_sym)}
103
104
  action.nil? ? fields : "<form action='%s' method='%s' enctype='multipart/form-data'>%s</form>\n" % [action, meth, fields]
104
105
  end
105
106
  # crushyfield is crushyinput but with label+error
106
107
  def crushyfield(col, o={})
107
- field_name = o[:name] || col.to_s.sub(/_id$/, '').tr('_', ' ').capitalize
108
+ field_name = o[:name] || model.crushyform_schema[col][:name] || col.to_s.sub(/_id$/, '').tr('_', ' ').capitalize
108
109
  error_list = errors.on(col).map{|e|" - #{e}"} if !errors.on(col).nil?
109
110
  "<p class='crushyfield %s'><label for='%s'>%s</label><span class='crushyfield-error-list'>%s</span><br />\n%s</p>\n" % [error_list&&'crushyfield-error', crushyid_for(col), field_name, error_list, crushyinput(col, o)]
110
111
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'sequel-crushyform'
3
- s.version = "0.0.2"
3
+ s.version = "0.0.3"
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."
@@ -15,7 +15,7 @@ class Haiku < ::Sequel::Model
15
15
  plugin :schema
16
16
  set_schema do
17
17
  primary_key :id
18
- String :title, :crushyform=>{:type=>:custom}
18
+ String :title, :crushyform=>{:type=>:custom, :name=>'Nice Title'}
19
19
  text :body
20
20
  Boolean :published
21
21
  foreign_key :author_id, :authors
@@ -126,7 +126,7 @@ describe 'Crushyform when schema plugin is used' do
126
126
  should 'use schema declaration for building the default crushyform_schema' do
127
127
  Haiku.default_crushyform_schema.should=={
128
128
  :id => {:type=>:integer},
129
- :title => {:type=>:custom},
129
+ :title => {:type=>:custom,:name=>'Nice Title'},
130
130
  :body => {:type=>:text},
131
131
  :published => {:type=>:boolean},
132
132
  :author_id => {:type=>:parent}
@@ -323,6 +323,7 @@ describe 'Crushyfield types' do
323
323
  ShippingAddress.new.crushyfield(:address_body).should.match(/<label for='#{Regexp.escape ShippingAddress.new.crushyid_for(:address_body)}'>Address body<\/label>/)
324
324
  ShippingAddress.first.crushyfield(:address_body).should.match(/<label for='#{Regexp.escape ShippingAddress.first.crushyid_for(:address_body)}'>Address body<\/label>/)
325
325
  ShippingAddress.new.crushyfield(:address_body,{:name=>'Address Lines'}).should.match(/<label for='#{Regexp.escape ShippingAddress.new.crushyid_for(:address_body)}'>Address Lines<\/label>/)
326
+ Haiku.new.crushyfield(:title).should.match(/<label for='#{Regexp.escape Haiku.new.crushyid_for(:title)}'>Nice Title<\/label>/)
326
327
  end
327
328
 
328
329
  should 'have errors reported for fields' do
@@ -359,9 +360,10 @@ describe 'Crushyform' do
359
360
  should 'use crushyform_schema keys by default for the list of field to put in the form' do
360
361
  form = Haiku.new.crushyform
361
362
  form.should.not==''
362
- Haiku.crushyform_schema.keys.each do |k|
363
+ (Haiku.crushyform_schema.keys - [:id]).each do |k|
363
364
  form.should.match(/#{Haiku.new.crushyid_for(k)}/)
364
365
  end
366
+ form.should.not.match(/#{Haiku.new.crushyid_for(:id)}/)
365
367
  end
366
368
 
367
369
  end
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: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
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-07-13 00:00:00 +01:00
18
+ date: 2011-07-15 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies: []
21
21