sequel-crushyform 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -302,6 +302,7 @@ CHANGE LOG
302
302
  0.0.3 Fix a bug on the default value for label :name
303
303
  0.0.4 Fix type `:none`
304
304
  0.0.5 Crushyform method guesses the enctype
305
+ 0.0.6 Human name for classes and label for new records
305
306
 
306
307
  COPYRIGHT
307
308
  =========
@@ -1,7 +1,7 @@
1
1
  module ::Sequel::Plugins::Crushyform
2
2
 
3
3
  module ClassMethods
4
- def crushyform_version; [0,0,5]; end
4
+ def crushyform_version; [0,0,6]; end
5
5
  # Schema
6
6
  def crushyform_schema
7
7
  @crushyform_schema ||= default_crushyform_schema
@@ -95,6 +95,8 @@ module ::Sequel::Plugins::Crushyform
95
95
  def label_column=(n); @label_column=n; end
96
96
  # Dataset selecting only columns used for building names
97
97
  def label_dataset; select(:id, label_column); end
98
+ # Human readable name
99
+ def human_name; self.name.gsub(/([A-Z]+)([A-Z][a-z])/,'\1 \2').gsub(/([a-z\d])([A-Z])/,'\1 \2'); end
98
100
  end
99
101
 
100
102
  module InstanceMethods
@@ -130,7 +132,7 @@ module ::Sequel::Plugins::Crushyform
130
132
  # Which means there could be a colision.
131
133
  def crushyid_for(col); "%s-%s-%s" % [id||'new',self.class.name,col]; end
132
134
  # Used to determine a humanly readable representation of the entry on one line of text
133
- def to_label; model.label_column.nil? ? "#{model} #{id}" : self.__send__(model.label_column).to_s.tr("\n\r", ' '); end
135
+ def to_label; model.label_column.nil? ? [self.new? ? 'New' : nil, model.human_name, id].compact!.join(' ') : self.__send__(model.label_column).to_s.tr("\n\r", ' '); end
134
136
  # Provide a thumbnail for the column
135
137
  def to_thumb(c)
136
138
  current = self.__send__(c)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'sequel-crushyform'
3
- s.version = "0.0.5"
3
+ s.version = "0.0.6"
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."
@@ -102,6 +102,8 @@ class Pic < ::Sequel::Model
102
102
  create_table unless table_exists?
103
103
  end
104
104
 
105
+ class WithAccronymYMCAName < ::Sequel::Model; end
106
+
105
107
  # ========
106
108
  # = Test =
107
109
  # ========
@@ -151,6 +153,10 @@ describe 'Crushyform miscellaneous helpers' do
151
153
  Haiku.crushyform_version.size.should==3
152
154
  end
153
155
 
156
+ should 'have a human readable name' do
157
+ WithAccronymYMCAName.human_name.should=='With Accronym YMCA Name'
158
+ end
159
+
154
160
  should 'have a correct default crushyid' do
155
161
  ShippingAddress.new.crushyid_for(:address_body).should=='new-ShippingAddress-address_body'
156
162
  ShippingAddress.first.crushyid_for(:address_body).should=='1-ShippingAddress-address_body'
@@ -181,10 +187,12 @@ describe 'Crushyform miscellaneous helpers' do
181
187
 
182
188
  should 'have a label based on Model::label_column' do
183
189
  Author.first.to_label.should=='Bradbury'
190
+ Author.new(:surname=>'Brautigan').to_label.should=='Brautigan'
184
191
  end
185
192
 
186
193
  should 'Have a fallback label when label_column is nil' do
187
- ShippingAddress.first.to_label.should=="ShippingAddress 1"
194
+ ShippingAddress.first.to_label.should=="Shipping Address 1"
195
+ ShippingAddress.new.to_label.should=="New Shipping Address"
188
196
  end
189
197
 
190
198
  should 'avoid line breaks if label column is a multiline field' do
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: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mickael Riga