padrino-helpers 0.7.9 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ begin
17
17
  gem.add_runtime_dependency "sinatra", ">= 0.9.2"
18
18
  gem.add_runtime_dependency "padrino-core", "= #{GEM_VERSION}"
19
19
  gem.add_development_dependency "haml", ">= 2.2.1"
20
- gem.add_development_dependency "shoulda", ">= 0"
20
+ gem.add_development_dependency "shoulda", ">= 2.10.3"
21
21
  gem.add_development_dependency "mocha", ">= 0.9.7"
22
22
  gem.add_development_dependency "rack-test", ">= 0.5.0"
23
23
  gem.add_development_dependency "webrat", ">= 0.5.1"
@@ -38,14 +38,15 @@ end
38
38
 
39
39
  begin
40
40
  require 'rcov/rcovtask'
41
- Rcov::RcovTask.new do |test|
42
- test.libs << 'test'
43
- test.pattern = 'test/**/test_*.rb'
44
- test.verbose = true
41
+ Rcov::RcovTask.new do |rcov|
42
+ rcov.libs << 'test'
43
+ rcov.pattern = 'test/**/test_*.rb'
44
+ rcov.verbose = true
45
+ rcov.rcov_opts << ['--exclude /Gems/1.8/gems/,/tmp/,padrino-admin,padrino-cache,padrino-core,padrino-gen,padrino-mailer']
45
46
  end
46
47
  rescue LoadError
47
48
  task :rcov do
48
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
49
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install relevance-rcov"
49
50
  end
50
51
  end
51
52
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.9
1
+ 0.8.0
@@ -7,6 +7,7 @@ module Padrino
7
7
  # ==== Examples
8
8
  #
9
9
  # flash_tag(:notice, :class => 'flash', :id => 'flash-notice')
10
+ #
10
11
  def flash_tag(kind, options={})
11
12
  flash_text = flash[kind]
12
13
  return '' if flash_text.blank?
@@ -127,52 +128,71 @@ module Padrino
127
128
  src =~ %r{^\s*(/|http)} ? src : uri_root_path('images', src)
128
129
  end
129
130
 
130
- protected
131
- # stylesheet_tag('style', :media => 'screen')
132
- def stylesheet_tag(source, options={})
133
- options = options.dup.reverse_merge!(:href => stylesheet_path(source), :media => 'screen', :rel => 'stylesheet', :type => 'text/css')
134
- tag(:link, options)
135
- end
136
-
137
- # javascript_tag 'application', :src => '/javascripts/base/application.js'
138
- def javascript_tag(source, options={})
139
- options = options.dup.reverse_merge!(:src => javascript_path(source), :type => 'text/javascript', :content => "")
140
- tag(:script, options)
141
- end
131
+ ##
132
+ # Generate a +link+ tag for stylesheet.
133
+ #
134
+ # ==== Examples
135
+ #
136
+ # stylesheet_tag('style', :media => 'screen')
137
+ #
138
+ def stylesheet_tag(source, options={})
139
+ options = options.dup.reverse_merge!(:href => stylesheet_path(source), :media => 'screen', :rel => 'stylesheet', :type => 'text/css')
140
+ tag(:link, options)
141
+ end
142
+ ##
143
+ # Generate a link +script+ for javascript.
144
+ #
145
+ # ==== Examples
146
+ #
147
+ # javascript_tag 'application', :src => '/javascripts/base/application.js'
148
+ #
149
+ def javascript_tag(source, options={})
150
+ options = options.dup.reverse_merge!(:src => javascript_path(source), :type => 'text/javascript', :content => "")
151
+ tag(:script, options)
152
+ end
142
153
 
143
- # Returns the javascript_path appending the default javascripts path if necessary
144
- def javascript_path(source)
145
- return source if source =~ /^http/
146
- source = source.to_s.gsub(/\.js$/, '')
147
- source_name = source; source_name << ".js" unless source =~ /\.js/
148
- result_path = source_name if source =~ %r{^/} # absolute path
149
- result_path ||= uri_root_path("javascripts", source_name)
150
- return result_path if result_path =~ /\?/
151
- public_path = Padrino.root("public", result_path)
152
- stamp = File.exist?(public_path) ? File.mtime(public_path).to_i : Time.now.to_i
153
- "#{result_path}?#{stamp}"
154
- end
154
+ ##
155
+ # Returns the javascript_path appending the default javascripts path if necessary
156
+ #
157
+ def javascript_path(source)
158
+ return source if source =~ /^http/
159
+ source = source.to_s.gsub(/\.js$/, '')
160
+ source_name = source; source_name << ".js" unless source =~ /\.js/
161
+ result_path = source_name if source =~ %r{^/} # absolute path
162
+ result_path ||= uri_root_path("javascripts", source_name)
163
+ return result_path if result_path =~ /\?/
164
+ public_path = Padrino.root("public", result_path)
165
+ stamp = File.exist?(public_path) ? File.mtime(public_path).to_i : Time.now.to_i
166
+ "#{result_path}?#{stamp}"
167
+ end
155
168
 
156
- # Returns the stylesheet_path appending the default stylesheets path if necessary
157
- def stylesheet_path(source)
158
- return source if source =~ /^http/
159
- source = source.to_s.gsub(/\.css$/, '')
160
- source_name = source; source_name << ".css" unless source =~ /\.css/
161
- result_path = source_name if source =~ %r{^/} # absolute path
162
- result_path ||= uri_root_path("stylesheets", source_name)
163
- return result_path if result_path =~ /\?/
164
- public_path = Padrino.root("public", result_path)
165
- stamp = File.exist?(public_path) ? File.mtime(public_path).to_i : Time.now.to_i
166
- "#{result_path}?#{stamp}"
167
- end
169
+ ##
170
+ # Returns the stylesheet_path appending the default stylesheets path if necessary
171
+ #
172
+ def stylesheet_path(source)
173
+ return source if source =~ /^http/
174
+ source = source.to_s.gsub(/\.css$/, '')
175
+ source_name = source; source_name << ".css" unless source =~ /\.css/
176
+ result_path = source_name if source =~ %r{^/} # absolute path
177
+ result_path ||= uri_root_path("stylesheets", source_name)
178
+ return result_path if result_path =~ /\?/
179
+ public_path = Padrino.root("public", result_path)
180
+ stamp = File.exist?(public_path) ? File.mtime(public_path).to_i : Time.now.to_i
181
+ "#{result_path}?#{stamp}"
182
+ end
168
183
 
169
- # Returns the uri root of the application, defaulting to '/'
184
+ private
185
+ ##
186
+ # Returns the uri root of the application.'
187
+ #
170
188
  def uri_root_path(*paths)
171
189
  root_uri = self.class.uri_root if self.class.respond_to?(:uri_root)
172
190
  File.join(root_uri || '/', *paths)
173
191
  end
174
192
 
193
+ ##
175
194
  # Parse link_to options for give correct conditions
195
+ #
176
196
  def parse_conditions(url, options)
177
197
  if options.has_key?(:if)
178
198
  condition = options.delete(:if)
@@ -124,7 +124,7 @@ module Padrino
124
124
 
125
125
  # Returns the human name of the field. Look that use builtin I18n.
126
126
  def field_human_name(field)
127
- I18n.translate("#{object_name}.attributes.#{field}", :count => 1, :default => field.to_s.humanize, :scope => [:models])
127
+ I18n.translate("#{object_name}.attributes.#{field}", :count => 1, :default => field.to_s.humanize, :scope => :models)
128
128
  end
129
129
 
130
130
  # Returns the id for the given field
@@ -14,6 +14,7 @@ module Padrino
14
14
  # file_field_block(:photo, { :class => 'long' }, { :class => 'wide-label' })
15
15
  # check_box_block(:remember_me, { :class => 'long' }, { :class => 'wide-label' })
16
16
  # select_block(:color, :options => ['green', 'black'])
17
+ #
17
18
  (self.field_types - [ :hidden_field, :radio_button ]).each do |field_type|
18
19
  class_eval <<-EOF
19
20
  def #{field_type}_block(field, options={}, label_options={})
@@ -63,13 +63,29 @@ module Padrino
63
63
  ##
64
64
  # Constructs list html for the errors for a given symbol
65
65
  #
66
+ # ==== Options
67
+ #
68
+ # :header_tag:: Used for the header of the error div (default: "h2").
69
+ # :id:: The id of the error div (default: "errorExplanation").
70
+ # :class:: The class of the error div (default: "errorExplanation").
71
+ # :object:: The object (or array of objects) for which to display errors,
72
+ # if you need to escape the instance variable convention.
73
+ # :object_name:: The object name to use in the header, or any text that you prefer.
74
+ # If +:object_name+ is not set, the name of the first object will be used.
75
+ # :header_message:: The message in the header of the error div. Pass +nil+
76
+ # or an empty string to avoid the header message altogether. (Default: "X errors
77
+ # prohibited this object from being saved").
78
+ # :message:: The explanation message after the header message and before
79
+ # the error list. Pass +nil+ or an empty string to avoid the explanation message
80
+ # altogether. (Default: "There were problems with the following fields:").
81
+ #
66
82
  # ==== Examples
67
83
  #
68
84
  # error_messages_for :user
69
85
  #
70
- def error_messages_for(*params)
71
- options = params.extract_options!.symbolize_keys
72
- objects = params.collect {|object_name| object_name.is_a?(Symbol) ? instance_variable_get("@#{object_name}") : object_name }.compact
86
+ def error_messages_for(*objects)
87
+ options = objects.extract_options!.symbolize_keys
88
+ objects = objects.collect {|object_name| object_name.is_a?(Symbol) ? instance_variable_get("@#{object_name}") : object_name }.compact
73
89
  count = objects.inject(0) {|sum, object| sum + object.errors.count }
74
90
 
75
91
  unless count.zero?
@@ -79,11 +95,11 @@ module Padrino
79
95
  value = options[key]
80
96
  html[key] = value unless value.blank?
81
97
  else
82
- html[key] = 'field-errors'
98
+ html[key] = 'field-errors' unless key == :style
83
99
  end
84
100
  end
85
101
 
86
- options[:object_name] ||= params.first.class
102
+ options[:object_name] ||= objects.first.class
87
103
 
88
104
  I18n.with_options :locale => options[:locale], :scope => [:models, :errors, :template] do |locale|
89
105
  header_message = if options.include?(:header_message)
@@ -267,37 +283,50 @@ module Padrino
267
283
  input_tag(:image, options)
268
284
  end
269
285
 
270
- protected
271
- # Returns an array of option items for a select field based on the given collection
272
- # fields is an array containing the fields to display from each item in the collection
273
- def options_from_collection(collection, fields)
274
- return '' if collection.blank?
275
- collection.collect { |item| [ item.send(fields.first), item.send(fields.last) ] }
276
- end
286
+ ##
287
+ # Returns an array of option items for a select field based on the given collection
288
+ # fields is an array containing the fields to display from each item in the collection
289
+ #
290
+ def options_from_collection(collection, fields)
291
+ return '' if collection.blank?
292
+ collection.collect { |item| [ item.send(fields.first), item.send(fields.last) ] }
293
+ end
277
294
 
278
- # Returns the options tags for a select based on the given option items
279
- def options_for_select(option_items, selected_value=nil)
280
- return '' if option_items.blank?
281
- option_items.collect do |caption, value|
282
- value ||= caption
283
- content_tag(:option, caption, :value => value, :selected => selected_value.to_s =~ /#{value}|#{caption}/)
284
- end
295
+ #
296
+ # Returns the options tags for a select based on the given option items
297
+ #
298
+ def options_for_select(option_items, selected_value=nil)
299
+ return '' if option_items.blank?
300
+ option_items.collect do |caption, value|
301
+ value ||= caption
302
+ content_tag(:option, caption, :value => value, :selected => selected_value.to_s =~ /#{value}|#{caption}/)
285
303
  end
304
+ end
286
305
 
287
- # returns the hidden method field for 'put' and 'delete' forms
288
- # Only 'get' and 'post' are allowed within browsers;
289
- # 'put' and 'delete' are just specified using hidden fields with form action still 'put'.
290
- # hidden_form_method_field('delete') => <input name="_method" value="delete" />
291
- def hidden_form_method_field(desired_method)
292
- return '' if (desired_method.to_s =~ /get|post/)
293
- original_method = desired_method.to_s.dup
294
- desired_method.to_s.replace('post')
295
- hidden_field_tag(:_method, :value => original_method)
296
- end
306
+ ##
307
+ # Returns the hidden method field for 'put' and 'delete' forms
308
+ # Only 'get' and 'post' are allowed within browsers;
309
+ # 'put' and 'delete' are just specified using hidden fields with form action still 'put'.
310
+ #
311
+ # ==== Examples
312
+ #
313
+ # # Generate: <input name="_method" value="delete" />
314
+ # hidden_form_method_field('delete')
315
+ #
316
+ def hidden_form_method_field(desired_method)
317
+ return '' if (desired_method.to_s =~ /get|post/)
318
+ original_method = desired_method.to_s.dup
319
+ desired_method.to_s.replace('post')
320
+ hidden_field_tag(:_method, :value => original_method)
321
+ end
297
322
 
323
+ private
324
+ ##
298
325
  # Returns the FormBuilder class to use based on all available setting sources
299
- # If explicitly defined, returns that, otherwise returns defaults
300
- # configured_form_builder_class(nil) => StandardFormBuilder
326
+ # If explicitly defined, returns that, otherwise returns defaults.
327
+ #
328
+ # configured_form_builder_class(nil) => StandardFormBuilder
329
+ #
301
330
  def configured_form_builder_class(explicit_builder=nil)
302
331
  default_builder = self.respond_to?(:options) && self.options.default_builder
303
332
  configured_builder = explicit_builder || default_builder || 'StandardFormBuilder'
@@ -7,7 +7,7 @@ module Padrino
7
7
  # Methods are provided for phone numbers, currency, percentage,
8
8
  # precision, positional notation, and file size.
9
9
  #
10
- # Verbatim copy of Rails Number helper
10
+ # Verbatim copy of Rails Number Helpers
11
11
  #
12
12
  module NumberHelpers
13
13
  ##
@@ -15,11 +15,12 @@ module Padrino
15
15
  # in the +options+ hash.
16
16
  #
17
17
  # ==== Options
18
- # * <tt>:precision</tt> - Sets the level of precision (defaults to 2).
19
- # * <tt>:unit</tt> - Sets the denomination of the currency (defaults to "$").
20
- # * <tt>:separator</tt> - Sets the separator between the units (defaults to ".").
21
- # * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults to ",").
22
- # * <tt>:format</tt> - Sets the format of the output string (defaults to "%u%n"). The field types are:
18
+ #
19
+ # :precision:: Sets the level of precision (defaults to 2).
20
+ # :unit:: Sets the denomination of the currency (defaults to "$").
21
+ # :separator:: Sets the separator between the units (defaults to ".").
22
+ # :delimiter:: Sets the thousands delimiter (defaults to ",").
23
+ # :format:: Sets the format of the output string (defaults to "%u%n"). The field types are:
23
24
  #
24
25
  # %u The currency unit
25
26
  # %n The number
@@ -65,9 +66,10 @@ module Padrino
65
66
  # format in the +options+ hash.
66
67
  #
67
68
  # ==== Options
68
- # * <tt>:precision</tt> - Sets the level of precision (defaults to 3).
69
- # * <tt>:separator</tt> - Sets the separator between the units (defaults to ".").
70
- # * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults to "").
69
+ #
70
+ # :precision:: Sets the level of precision (defaults to 3).
71
+ # :separator:: Sets the separator between the units (defaults to ".").
72
+ # :delimiter:: Sets the thousands delimiter (defaults to "").
71
73
  #
72
74
  # ==== Examples
73
75
  #
@@ -102,8 +104,9 @@ module Padrino
102
104
  # customize the format in the +options+ hash.
103
105
  #
104
106
  # ==== Options
105
- # * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults to ",").
106
- # * <tt>:separator</tt> - Sets the separator between the units (defaults to ".").
107
+ #
108
+ # :delimiter:: Sets the thousands delimiter (defaults to ",").
109
+ # :separator:: Sets the separator between the units (defaults to ".").
107
110
  #
108
111
  # ==== Examples
109
112
  #
@@ -145,9 +148,9 @@ module Padrino
145
148
  #
146
149
  # ==== Options
147
150
  #
148
- # * <tt>:precision</tt> - Sets the level of precision (defaults to 3).
149
- # * <tt>:separator</tt> - Sets the separator between the units (defaults to ".").
150
- # * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults to "").
151
+ # :precision:: Sets the level of precision (defaults to 3).
152
+ # :separator:: Sets the separator between the units (defaults to ".").
153
+ # :delimiter:: Sets the thousands delimiter (defaults to "").
151
154
  #
152
155
  # ==== Examples
153
156
  #
@@ -196,9 +199,10 @@ module Padrino
196
199
  # format in the +options+ hash.
197
200
  #
198
201
  # ==== Options
199
- # * <tt>:precision</tt> - Sets the level of precision (defaults to 1).
200
- # * <tt>:separator</tt> - Sets the separator between the units (defaults to ".").
201
- # * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults to "").
202
+ #
203
+ # :precision:: Sets the level of precision (defaults to 1).
204
+ # :separator:: Sets the separator between the units (defaults to ".").
205
+ # :delimiter:: Sets the thousands delimiter (defaults to "").
202
206
  #
203
207
  # ==== Examples
204
208
  #
@@ -77,40 +77,64 @@ module Padrino
77
77
  }.join
78
78
  end
79
79
 
80
- protected
80
+ private
81
+ ##
81
82
  # Retrieves content_blocks stored by content_for or within yield_content
82
- # content_blocks[:name] => ['...', '...']
83
+ #
84
+ # ==== Examples
85
+ #
86
+ # content_blocks[:name] => ['...', '...']
87
+ #
83
88
  def content_blocks
84
89
  @content_blocks ||= Hash.new {|h,k| h[k] = [] }
85
90
  end
86
91
 
92
+ ##
87
93
  # Used to capture the html from a block of erb code
88
- # capture_erb(&block) => '...html...'
94
+ #
95
+ # ==== Examples
96
+ #
97
+ # capture_erb(&block) => '...html...'
98
+ #
89
99
  def capture_erb(*args, &block)
90
100
  erb_with_output_buffer { block_given? && block.call(*args) }
91
101
  end
92
102
 
103
+ ##
93
104
  # Concats directly to an erb template
94
- # erb_concat("Direct to buffer")
105
+ #
106
+ # ==== Examples
107
+ #
108
+ # erb_concat("Direct to buffer")
109
+ #
95
110
  def erb_concat(text)
96
111
  @_out_buf << text if has_erb_buffer?
97
112
  end
98
113
 
114
+ ##
99
115
  # Returns true if an erb buffer is detected
100
- # has_erb_buffer? => true
116
+ #
117
+ # ==== Examples
118
+ #
119
+ # has_erb_buffer? => true
120
+ #
101
121
  def has_erb_buffer?
102
122
  !@_out_buf.nil?
103
123
  end
104
124
 
125
+ ##
105
126
  # Used to determine if a block is called from ERB.
106
127
  # NOTE: This doesn't actually work yet because the variable __in_erb_template
107
128
  # hasn't been defined in ERB. We need to find a way to fix this.
129
+ #
108
130
  def block_is_erb?(block)
109
131
  has_erb_buffer? || block && eval('defined? __in_erb_template', block)
110
132
  end
111
133
 
134
+ ##
112
135
  # Used to direct the buffer for the erb capture
113
- def erb_with_output_buffer(buf = '') #:nodoc:
136
+ #
137
+ def erb_with_output_buffer(buf = '')
114
138
  @_out_buf, old_buffer = buf, @_out_buf
115
139
  yield
116
140
  @_out_buf
@@ -46,8 +46,10 @@ module Padrino
46
46
  base_tag << (open_tag ? ">" : (content ? ">#{content}</#{name}>" : " />"))
47
47
  end
48
48
 
49
- protected
49
+ private
50
+ ##
50
51
  # Returns a list of attributes which can only contain an identity value (i.e selected)
52
+ #
51
53
  def identity_tag_attributes
52
54
  [:checked, :disabled, :selected, :multiple]
53
55
  end
@@ -1,4 +1,6 @@
1
1
  require 'padrino-core/support_lite'
2
+ require 'active_support/core_ext/float/rounding'
3
+ require 'active_support/option_merger'
2
4
  require 'cgi'
3
5
 
4
6
  Dir[File.dirname(__FILE__) + '/padrino-helpers/**/*.rb'].each {|file| require file }
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{padrino-helpers}
8
- s.version = "0.7.9"
8
+ s.version = "0.8.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
12
- s.date = %q{2010-02-11}
12
+ s.date = %q{2010-02-14}
13
13
  s.description = %q{Tag helpers, asset helpers, form helpers, form builders and many more helpers for padrino}
14
14
  s.email = %q{padrinorb@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -62,7 +62,6 @@ Gem::Specification.new do |s|
62
62
  "test/fixtures/render_app/views/template/haml_template.haml",
63
63
  "test/fixtures/render_app/views/template/some_template.haml",
64
64
  "test/helper.rb",
65
- "test/support_helpers.rb",
66
65
  "test/test_asset_tag_helpers.rb",
67
66
  "test/test_form_builder.rb",
68
67
  "test/test_form_helpers.rb",
@@ -85,26 +84,26 @@ Gem::Specification.new do |s|
85
84
 
86
85
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
87
86
  s.add_runtime_dependency(%q<sinatra>, [">= 0.9.2"])
88
- s.add_runtime_dependency(%q<padrino-core>, ["= 0.7.9"])
87
+ s.add_runtime_dependency(%q<padrino-core>, ["= 0.8.0"])
89
88
  s.add_development_dependency(%q<haml>, [">= 2.2.1"])
90
- s.add_development_dependency(%q<shoulda>, [">= 0"])
89
+ s.add_development_dependency(%q<shoulda>, [">= 2.10.3"])
91
90
  s.add_development_dependency(%q<mocha>, [">= 0.9.7"])
92
91
  s.add_development_dependency(%q<rack-test>, [">= 0.5.0"])
93
92
  s.add_development_dependency(%q<webrat>, [">= 0.5.1"])
94
93
  else
95
94
  s.add_dependency(%q<sinatra>, [">= 0.9.2"])
96
- s.add_dependency(%q<padrino-core>, ["= 0.7.9"])
95
+ s.add_dependency(%q<padrino-core>, ["= 0.8.0"])
97
96
  s.add_dependency(%q<haml>, [">= 2.2.1"])
98
- s.add_dependency(%q<shoulda>, [">= 0"])
97
+ s.add_dependency(%q<shoulda>, [">= 2.10.3"])
99
98
  s.add_dependency(%q<mocha>, [">= 0.9.7"])
100
99
  s.add_dependency(%q<rack-test>, [">= 0.5.0"])
101
100
  s.add_dependency(%q<webrat>, [">= 0.5.1"])
102
101
  end
103
102
  else
104
103
  s.add_dependency(%q<sinatra>, [">= 0.9.2"])
105
- s.add_dependency(%q<padrino-core>, ["= 0.7.9"])
104
+ s.add_dependency(%q<padrino-core>, ["= 0.8.0"])
106
105
  s.add_dependency(%q<haml>, [">= 2.2.1"])
107
- s.add_dependency(%q<shoulda>, [">= 0"])
106
+ s.add_dependency(%q<shoulda>, [">= 2.10.3"])
108
107
  s.add_dependency(%q<mocha>, [">= 0.9.7"])
109
108
  s.add_dependency(%q<rack-test>, [">= 0.5.0"])
110
109
  s.add_dependency(%q<webrat>, [">= 0.5.1"])
@@ -55,6 +55,7 @@ end
55
55
 
56
56
  class Errors < Array
57
57
  def initialize; self << [:fake, :second, :third]; end
58
+ def on(fake); true if fake == :email; end
58
59
  def full_messages
59
60
  ["This is a fake error", "This is a second fake error", "This is a third fake error"]
60
61
  end
data/test/helper.rb CHANGED
@@ -5,8 +5,6 @@ require 'mocha'
5
5
  require 'rack/test'
6
6
  require 'webrat'
7
7
 
8
- # require 'extlib' # test with extlib
9
-
10
8
  # We try to load the vendored padrino-core if exist
11
9
  %w(core).each do |gem|
12
10
  if File.exist?(File.dirname(__FILE__) + "/../../padrino-#{gem}/lib")
@@ -14,9 +12,14 @@ require 'webrat'
14
12
  end
15
13
  end
16
14
 
17
- require 'support_helpers'
18
15
  require 'padrino-helpers'
19
16
 
17
+ # We need some extension for do our tests
18
+ require 'active_support/core_ext/date'
19
+ require 'active_support/core_ext/time'
20
+ require 'active_support/core_ext/numeric'
21
+ require 'active_support/duration'
22
+
20
23
  class Test::Unit::TestCase
21
24
  include Padrino::Helpers::OutputHelpers
22
25
  include Padrino::Helpers::TagHelpers
@@ -129,10 +129,12 @@ class TestFormBuilder < Test::Unit::TestCase
129
129
  end
130
130
 
131
131
  should "display correct form html with valid record" do
132
- actual_html = standard_builder.error_messages(:header_message => "Demo form cannot be saved")
133
- assert_has_tag('div.field-errors h2', :content => "Demo form cannot be saved") { actual_html }
134
- assert_has_tag('div.field-errors ul li', :content => "1") { actual_html }
135
- assert_has_tag('div.field-errors ul li', :content => "2") { actual_html }
132
+ actual_html = standard_builder.error_messages(:header_message => "Demo form cannot be saved", :style => "foo:bar", :class => "mine")
133
+ assert_has_tag('#field-errors h2', :content => "Demo form cannot be saved") { actual_html }
134
+ assert_has_tag('#field-errors ul li', :content => "1") { actual_html }
135
+ assert_has_tag('#field-errors ul li', :content => "2") { actual_html }
136
+ assert_has_tag('#field-errors', :style => "foo:bar") { actual_html }
137
+ assert_has_tag('#field-errors', :class => "mine") { actual_html }
136
138
  end
137
139
 
138
140
  should "display correct form in haml" do
@@ -141,6 +143,7 @@ class TestFormBuilder < Test::Unit::TestCase
141
143
  assert_have_selector '#demo div.field-errors ul li', :content => "This is a fake error"
142
144
  assert_have_selector '#demo2 div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
143
145
  assert_have_selector '#demo2 div.field-errors ul li', :content => "This is a fake error"
146
+ assert_have_selector '#demo input', :name => 'markup_user[email]', :class => 'x-form-invalid'
144
147
  end
145
148
 
146
149
  should "display correct form in erb" do
@@ -149,6 +152,7 @@ class TestFormBuilder < Test::Unit::TestCase
149
152
  assert_have_selector '#demo div.field-errors ul li', :content => "This is a fake error"
150
153
  assert_have_selector '#demo2 div.field-errors h2', :content => "custom MarkupUser cannot be saved!"
151
154
  assert_have_selector '#demo2 div.field-errors ul li', :content => "This is a fake error"
155
+ assert_have_selector '#demo input', :name => 'markup_user[email]', :class => 'x-form-invalid'
152
156
  end
153
157
  end
154
158
 
@@ -53,6 +53,12 @@ class TestFormatHelpers < Test::Unit::TestCase
53
53
  actual_text = word_wrap('Once upon a time', :line_width => 1)
54
54
  assert_equal "Once\nupon\na\ntime", actual_text
55
55
  end
56
+ should "return proper formatting for default width" do
57
+ actual_text = word_wrap(1.upto(50).map.join(" "))
58
+ assert_equal 1.upto(30).map.join(" ") + "\n" + 31.upto(50).map.join(" "), actual_text
59
+ actual_text = word_wrap(1.upto(50).map.join(" "), 80)
60
+ assert_equal 1.upto(30).map.join(" ") + "\n" + 31.upto(50).map.join(" "), actual_text
61
+ end
56
62
  end
57
63
 
58
64
  context 'for #truncate method' do
@@ -88,6 +94,21 @@ class TestFormatHelpers < Test::Unit::TestCase
88
94
  end
89
95
 
90
96
  context 'for #time_ago_in_words method' do
97
+ should "less than 5 seconds" do
98
+ assert_equal 'less than 5 seconds', time_ago_in_words(Time.now, true)
99
+ end
100
+ should "less than 10 seconds" do
101
+ assert_equal 'less than 10 seconds', time_ago_in_words(Time.now-5, true)
102
+ end
103
+ should "less than 20 seconds" do
104
+ assert_equal 'less than 20 seconds', time_ago_in_words(Time.now-10, true)
105
+ end
106
+ should "less than a minute" do
107
+ assert_equal 'less than a minute', time_ago_in_words(Time.now-40, true)
108
+ end
109
+ should "2 minutes" do
110
+ assert_equal '2 minutes', time_ago_in_words(Time.now-120, true)
111
+ end
91
112
  should "display today" do
92
113
  assert_equal 'less than a minute', time_ago_in_words(Time.now)
93
114
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.9
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2010-02-11 00:00:00 +01:00
15
+ date: 2010-02-14 00:00:00 +01:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -33,7 +33,7 @@ dependencies:
33
33
  requirements:
34
34
  - - "="
35
35
  - !ruby/object:Gem::Version
36
- version: 0.7.9
36
+ version: 0.8.0
37
37
  version:
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: haml
@@ -53,7 +53,7 @@ dependencies:
53
53
  requirements:
54
54
  - - ">="
55
55
  - !ruby/object:Gem::Version
56
- version: "0"
56
+ version: 2.10.3
57
57
  version:
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: mocha
@@ -140,7 +140,6 @@ files:
140
140
  - test/fixtures/render_app/views/template/haml_template.haml
141
141
  - test/fixtures/render_app/views/template/some_template.haml
142
142
  - test/helper.rb
143
- - test/support_helpers.rb
144
143
  - test/test_asset_tag_helpers.rb
145
144
  - test/test_form_builder.rb
146
145
  - test/test_form_helpers.rb
@@ -1,21 +0,0 @@
1
- require 'padrino-core/support_lite'
2
- unless Fixnum.method_defined?(:days)
3
- if Padrino.support == :extlib
4
- class Object
5
- # A duck-type assistant method. For example, Active Support extends Date
6
- # to define an acts_like_date? method, and extends Time to define
7
- # acts_like_time?. As a result, we can do "x.acts_like?(:time)" and
8
- # "x.acts_like?(:date)" to do duck-type-safe comparisons, since classes that
9
- # we want to act like Time simply need to define an acts_like_time? method.
10
- def acts_like?(duck)
11
- respond_to? "acts_like_#{duck}?"
12
- end
13
- end
14
- else
15
- require 'active_support/core_ext/object/misc'
16
- end
17
- require 'active_support/core_ext/date'
18
- require 'active_support/core_ext/time'
19
- require 'active_support/core_ext/numeric'
20
- require 'active_support/duration'
21
- end