padrino-helpers 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +15 -252
- data/VERSION +1 -1
- data/lib/padrino-helpers/asset_tag_helpers.rb +7 -4
- data/lib/padrino-helpers/form_builder/abstract_form_builder.rb +5 -4
- data/lib/padrino-helpers/form_helpers.rb +2 -1
- data/lib/padrino-helpers/format_helpers.rb +26 -0
- data/padrino-helpers.gemspec +6 -6
- data/test/test_format_helpers.rb +12 -0
- metadata +30 -61
data/README.rdoc
CHANGED
@@ -6,7 +6,6 @@ This component provides a great deal of view helpers related to html markup gene
|
|
6
6
|
There are helpers for generating tags, forms, links, images, and more. Most of the basic
|
7
7
|
methods should be very familiar to anyone who has used rails view helpers.
|
8
8
|
|
9
|
-
|
10
9
|
=== Output Helpers
|
11
10
|
|
12
11
|
Output helpers are a collection of important methods for managing, capturing and displaying output
|
@@ -52,24 +51,8 @@ This will capture the template body passed into the form_tag block and then appe
|
|
52
51
|
to the template through the use of <tt>concat_content</tt>. Note have been built to work for both haml and erb
|
53
52
|
templates using the same syntax.
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
* <tt>content_for(key, &block)</tt>
|
58
|
-
* Capture a block of content to be rendered at a later time.
|
59
|
-
* <tt>content_for(:head) { ...content... }</tt>
|
60
|
-
* Also supports arguments passed to the content block
|
61
|
-
* <tt>content_for(:head) { |param1, param2| ...content... }</tt>
|
62
|
-
* <tt>yield_content(key, *args)</tt>
|
63
|
-
* Render the captured content blocks for a given key.
|
64
|
-
* <tt>yield_content :head</tt>
|
65
|
-
* Also supports arguments yielded to the content block
|
66
|
-
* <tt>yield_content :head, param1, param2</tt>
|
67
|
-
* <tt>capture_html(*args, &block)</tt>
|
68
|
-
* Captures the html from a block of template code for erb or haml
|
69
|
-
* <tt>capture_html(&block)</tt> => "...html..."
|
70
|
-
* <tt>concat_content(text="")</tt>
|
71
|
-
* Outputs the given text to the templates buffer directly in erb or haml
|
72
|
-
* <tt>concat_content("This will be output to the template buffer in erb or haml")</tt>
|
54
|
+
For more information on using output helpers, check out the guide for
|
55
|
+
{Padrino Helpers}[http://wiki.github.com/padrino/padrino-framework/application-helpers].
|
73
56
|
|
74
57
|
=== Tag Helpers
|
75
58
|
|
@@ -89,20 +72,8 @@ The input_tag is used to build tags that are related to accepting input from the
|
|
89
72
|
|
90
73
|
Note that all of these accept html options and result in returning a string containing html tags.
|
91
74
|
|
92
|
-
|
93
|
-
|
94
|
-
* <tt>tag(name, options={})</tt>
|
95
|
-
* Creates an html tag with the given name and options
|
96
|
-
* <tt>tag(:br, :style => 'clear:both')</tt> => <br style="clear:both" />
|
97
|
-
* <tt>tag(:p, :content => "demo", :class => 'large')</tt> => <p class="large">demo</p>
|
98
|
-
* <tt>content_tag(name, content, options={})</tt>
|
99
|
-
* Creates an html tag with given name, content and options
|
100
|
-
* <tt>content_tag(:p, "demo", :class => 'light')</tt> => <p class="light">demo</p>
|
101
|
-
* <tt>content_tag(:p, :class => 'dark') { ...content... }</tt> => <p class="dark">...content...</p>
|
102
|
-
* <tt>input_tag(type, options = {})</tt>
|
103
|
-
* Creates an html input field with given type and options
|
104
|
-
* <tt>input_tag :text, :class => "demo"</tt>
|
105
|
-
* <tt>input_tag :password, :value => "secret", :class => "demo"</tt>
|
75
|
+
For more information on using tag helpers, check out the guide for
|
76
|
+
{Padrino Helpers}[http://wiki.github.com/padrino/padrino-framework/application-helpers].
|
106
77
|
|
107
78
|
=== Asset Helpers
|
108
79
|
|
@@ -122,31 +93,8 @@ simple view template:
|
|
122
93
|
%p Mail me at #{mail_to 'fake@faker.com', "Fake Email Link", :cc => "test@demo.com"}
|
123
94
|
%p= image_tag 'padrino.png', :width => '35', :class => 'logo'
|
124
95
|
|
125
|
-
|
126
|
-
|
127
|
-
* <tt>flash_tag(kind, options={})</tt>
|
128
|
-
* Creates a div to display the flash of given type if it exists
|
129
|
-
* <tt>flash_tag(:notice, :class => 'flash', :id => 'flash-notice')</tt>
|
130
|
-
* <tt>link_to(*args, &block)</tt>
|
131
|
-
* Creates a link element with given name, url and options
|
132
|
-
* <tt>link_to 'click me', '/dashboard', :class => 'linky'</tt>
|
133
|
-
* <tt>link_to 'click me', '/dashboard', :class => 'linky', :if => @foo.present?</tt>
|
134
|
-
* <tt>link_to 'click me', '/dashboard', :class => 'linky', :unless => @foo.blank?</tt>
|
135
|
-
* <tt>link_to 'click me', '/dashboard', :class => 'linky', :unless => :current</tt>
|
136
|
-
* <tt>link_to('/dashboard', :class => 'blocky') { ...content... }</tt>
|
137
|
-
* <tt>mail_to(email, caption=nil, mail_options={})</tt>
|
138
|
-
* Creates a mailto link tag to the specified email_address
|
139
|
-
* <tt>mail_to "me@demo.com"</tt>
|
140
|
-
* <tt>mail_to "me@demo.com", "My Email", :subject => "Feedback", :cc => 'test@demo.com'</tt>
|
141
|
-
* <tt>image_tag(url, options={})</tt>
|
142
|
-
* Creates an image element with given url and options
|
143
|
-
* <tt>image_tag('icons/avatar.png')</tt>
|
144
|
-
* <tt>stylesheet_link_tag(*sources)</tt>
|
145
|
-
* Returns a stylesheet link tag for the sources specified as arguments
|
146
|
-
* <tt>stylesheet_link_tag 'style', 'application', 'layout'</tt>
|
147
|
-
* <tt>javascript_include_tag(*sources)</tt>
|
148
|
-
* Returns an html script tag for each of the sources provided.
|
149
|
-
* <tt>javascript_include_tag 'application', 'special'</tt>
|
96
|
+
For more information on using asset helpers, check out the guide for
|
97
|
+
{Padrino Helpers}[http://wiki.github.com/padrino/padrino-framework/application-helpers].
|
150
98
|
|
151
99
|
=== Form Helpers
|
152
100
|
|
@@ -170,58 +118,8 @@ example of constructing a non-object form would be:
|
|
170
118
|
- field_set_tag(:class => 'buttons') do
|
171
119
|
= submit_tag "Remove"
|
172
120
|
|
173
|
-
|
174
|
-
|
175
|
-
* <tt>form_tag(url, options={}, &block)</tt>
|
176
|
-
* Constructs a form without object based on options
|
177
|
-
* Supports form methods 'put' and 'delete' through hidden field
|
178
|
-
* <tt>form_tag('/register', :class => 'example') { ... }</tt>
|
179
|
-
* <tt>field_set_tag(*args, &block)</tt>
|
180
|
-
* Constructs a field_set to group fields with given options
|
181
|
-
* <tt>field_set_tag(:class => 'office-set') { }</tt>
|
182
|
-
* <tt>field_set_tag("Office", :class => 'office-set') { }</tt>
|
183
|
-
* <tt>error_messages_for(:record, options={})</tt>
|
184
|
-
* Constructs list html for the errors for a given object
|
185
|
-
* <tt>error_messages_for :user</tt>
|
186
|
-
* <tt>label_tag(name, options={}, &block)</tt>
|
187
|
-
* Constructs a label tag from the given options
|
188
|
-
* <tt>label_tag :username, :class => 'long-label'</tt>
|
189
|
-
* <tt>label_tag(:username, :class => 'blocked-label') { ... }</tt>
|
190
|
-
* <tt>hidden_field_tag(name, options={})</tt>
|
191
|
-
* Constructs a hidden field input from the given options
|
192
|
-
* <tt>hidden_field_tag :session_key, :value => 'secret'</tt>
|
193
|
-
* <tt>text_field_tag(name, options={})</tt>
|
194
|
-
* Constructs a text field input from the given options
|
195
|
-
* <tt>text_field_tag :username, :class => 'long'</tt>
|
196
|
-
* <tt>text_area_tag(name, options={})</tt>
|
197
|
-
* Constructs a text area input from the given options
|
198
|
-
* <tt>text_area_tag :username, :class => 'long'</tt>
|
199
|
-
* <tt>password_field_tag(name, options={})</tt>
|
200
|
-
* Constructs a password field input from the given options
|
201
|
-
* <tt>password_field_tag :password, :class => 'long'</tt>
|
202
|
-
* <tt>check_box_tag(name, options={})</tt>
|
203
|
-
* Constructs a checkbox input from the given options
|
204
|
-
* <tt>check_box_tag :remember_me, :checked => true</tt>
|
205
|
-
* <tt>radio_button_tag(name, options={})</tt>
|
206
|
-
* Constructs a radio button input from the given options
|
207
|
-
* <tt>radio_button_tag :gender, :value => 'male'</tt>
|
208
|
-
* <tt>select_tag(name, settings={})</tt>
|
209
|
-
* Constructs a select tag with options from the given settings
|
210
|
-
* <tt>select_tag(:favorite_color, :options => ['1', '2', '3'], :selected => '1')</tt>
|
211
|
-
* <tt>select_tag(:more_color, :options => [['label', '1'], ['label2', '2']])</tt>
|
212
|
-
* <tt>select_tag(:multiple_color, :options => [...], :multiple => true)</tt>
|
213
|
-
* <tt>file_field_tag(name, options={})</tt>
|
214
|
-
* Constructs a file field input from the given options
|
215
|
-
* <tt>file_field_tag :photo, :class => 'long'</tt>
|
216
|
-
* <tt>submit_tag(caption, options={})</tt>
|
217
|
-
* Constructs a submit button from the given options
|
218
|
-
* <tt>submit_tag "Create", :class => 'success'</tt>
|
219
|
-
* <tt>button_tag(caption, options={})</tt>
|
220
|
-
* Constructs an input (type => 'button') from the given options
|
221
|
-
* <tt>button_tag "Cancel", :class => 'clear'</tt>
|
222
|
-
* <tt>image_submit_tag(source, options={})</tt>
|
223
|
-
* Constructs an image submit button from the given options
|
224
|
-
* <tt>image_submit_tag "submit.png", :class => 'success'</tt>
|
121
|
+
For more information on using form helpers, check out the guide for
|
122
|
+
{Padrino Helpers}[http://wiki.github.com/padrino/padrino-framework/application-helpers].
|
225
123
|
|
226
124
|
=== FormBuilders
|
227
125
|
|
@@ -253,51 +151,6 @@ A form_for using these basic fields might look like:
|
|
253
151
|
= location.text_field :city
|
254
152
|
%p
|
255
153
|
= f.submit "Create", :class => 'button'
|
256
|
-
|
257
|
-
The list of defined helpers in the 'form builders' category:
|
258
|
-
|
259
|
-
* <tt>form_for(object, url, settings={}, &block)</tt>
|
260
|
-
* Constructs a form using given or default form_builder
|
261
|
-
* Supports form methods 'put' and 'delete' through hidden field
|
262
|
-
* Defaults to StandardFormBuilder but you can easily create your own!
|
263
|
-
* <tt>form_for(@user, '/register', :id => 'register') { |f| ...field-elements... }</tt>
|
264
|
-
* <tt>form_for(:user, '/register', :id => 'register') { |f| ...field-elements... }</tt>
|
265
|
-
* <tt>fields_for(object, settings={}, &block)</tt>
|
266
|
-
* Constructs fields for a given object for use in an existing form
|
267
|
-
* Defaults to StandardFormBuilder but you can easily create your own!
|
268
|
-
* <tt>fields_for @user.assignment do |assignment| ... end</tt>
|
269
|
-
* <tt>fields_for :assignment do |assigment| ... end</tt>
|
270
|
-
|
271
|
-
The following are fields provided by AbstractFormBuilder that can be used within a form_for or fields_for:
|
272
|
-
|
273
|
-
* <tt>error_messages(options={})</tt>
|
274
|
-
* Displays list html for the errors on form object
|
275
|
-
* <tt>f.errors_messages</tt>
|
276
|
-
* <tt>label(field, options={})</tt>
|
277
|
-
* <tt>f.label :name, :class => 'long'</tt>
|
278
|
-
* <tt>text_field(field, options={})</tt>
|
279
|
-
* <tt>f.text_field :username, :class => 'long'</tt>
|
280
|
-
* <tt>check_box(field, options={})</tt>
|
281
|
-
* Uses hidden field to provide a 'unchecked' value for field
|
282
|
-
* <tt>f.check_box :remember_me, :uncheck_value => 'false'</tt>
|
283
|
-
* <tt>radio_button(field, options={})</tt>
|
284
|
-
* <tt>f.radio_button :gender, :value => 'male'</tt>
|
285
|
-
* <tt>hidden_field(field, options={})</tt>
|
286
|
-
* <tt>f.hidden_field :session_id, :class => 'hidden'</tt>
|
287
|
-
* <tt>text_area(field, options={})</tt>
|
288
|
-
* <tt>f.text_area :summary, :class => 'long'</tt>
|
289
|
-
* <tt>password_field(field, options={})</tt>
|
290
|
-
* <tt>f.password_field :secret, :class => 'long'</tt>
|
291
|
-
* <tt>file_field(field, options={})</tt>
|
292
|
-
* <tt>f.file_field :photo, :class => 'long'</tt>
|
293
|
-
* <tt>select(field, options={})</tt>
|
294
|
-
* <tt>f.select(:state, :options => ['California', 'Texas', 'Wyoming'])</tt>
|
295
|
-
* <tt>f.select(:state, :collection => @states, :fields => [:name, :id])</tt>
|
296
|
-
* <tt>f.select(:state, :options => [...], :include_blank => true)</tt>
|
297
|
-
* <tt>submit(caption, options={})</tt>
|
298
|
-
* <tt>f.submit "Update", :class => 'long'</tt>
|
299
|
-
* <tt>image_submit(source, options={})</tt>
|
300
|
-
* <tt>f.image_submit "submit.png", :class => 'long'</tt>
|
301
154
|
|
302
155
|
There is also an additional StandardFormBuilder which builds on the abstract fields that can be used within a form_for.
|
303
156
|
|
@@ -320,50 +173,10 @@ and would generate this html (with each input contained in a paragraph and conta
|
|
320
173
|
<p><input type="submit" value="Create" class="button"></p>
|
321
174
|
</form>
|
322
175
|
|
323
|
-
|
324
|
-
|
325
|
-
* <tt>text_field_block(field, options={}, label_options={})</tt>
|
326
|
-
* <tt>text_field_block(:nickname, :class => 'big', :caption => "Username")</tt>
|
327
|
-
* <tt>text_area_block(field, options={}, label_options={})</tt>
|
328
|
-
* <tt>text_area_block(:about, :class => 'big')</tt>
|
329
|
-
* <tt>password_field_block(field, options={}, label_options={})</tt>
|
330
|
-
* <tt>password_field_block(:code, :class => 'big')</tt>
|
331
|
-
* <tt>file_field_block(field, options={}, label_options={})</tt>
|
332
|
-
* <tt>file_field_block(:photo, :class => 'big')</tt>
|
333
|
-
* <tt>check_box_block(field, options={}, label_options={})</tt>
|
334
|
-
* <tt>check_box_block(:remember_me, :class => 'big')</tt>
|
335
|
-
* <tt>select_block(field, options={}, label_options={})</tt>
|
336
|
-
* <tt>select_block(:country, :option => ['USA', 'Canada'])</tt>
|
337
|
-
* <tt>submit_block(caption, options={})</tt>
|
338
|
-
* <tt>submit_block(:username, :class => 'big')</tt>
|
339
|
-
* <tt>image_submit_block(source, options={})</tt>
|
340
|
-
* <tt>image_submit_block('submit.png', :class => 'big')</tt>
|
341
|
-
|
342
|
-
You can also easily build your own FormBuilder which allows for customized fields and behavior:
|
343
|
-
|
344
|
-
class MyCustomFormBuilder < AbstractFormBuilder
|
345
|
-
# Here we have access to a number of useful variables
|
346
|
-
#
|
347
|
-
# * template (use this to invoke any helpers)(ex. template.hidden_field_tag(...))
|
348
|
-
# * object (the record for this form) (ex. object.valid?)
|
349
|
-
# * object_name (object's underscored type) (ex. object_name => 'admin_user')
|
350
|
-
#
|
351
|
-
# We also have access to self.field_types => [:text_field, :text_area, ...]
|
352
|
-
# In addition, we have access to all the existing field tag helpers (text_field, hidden_field, file_field, ...)
|
353
|
-
end
|
354
|
-
|
355
|
-
Once a custom builder is defined, any call to form_for can use the new builder:
|
356
|
-
|
357
|
-
- form_for @user, '/register', :builder => 'MyCustomFormBuilder', :id => 'register' do |f|
|
358
|
-
...fields here...
|
359
|
-
|
360
|
-
The form builder can even be made into the default builder when form_for is invoked:
|
176
|
+
You can also easily build your own FormBuilder which allows for customized fields and behavior.
|
361
177
|
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
And there you have it, a fairly complete form builder solution for Padrino (and Sinatra).
|
366
|
-
I hope to create or merge in an even better 'default' form_builder in the near future.
|
178
|
+
For more information on using the Padrino form builders, check out the guide for
|
179
|
+
{Padrino Helpers}[http://wiki.github.com/padrino/padrino-framework/application-helpers].
|
367
180
|
|
368
181
|
=== Format Helpers
|
369
182
|
|
@@ -390,37 +203,8 @@ Format helpers also includes a number of useful text manipulation functions such
|
|
390
203
|
|
391
204
|
These helpers can be invoked from any route or view within your application.
|
392
205
|
|
393
|
-
|
394
|
-
|
395
|
-
* <tt>simple_format(text, html_options)</tt>
|
396
|
-
* Returns text transformed into HTML using simple formatting rules.
|
397
|
-
* <tt>simple_format("hello\nworld")</tt> => "<p>hello<br/>world</p>"
|
398
|
-
* <tt>pluralize(count, singular, plural = nil)</tt>
|
399
|
-
* Attempts to pluralize the singular word unless count is 1.
|
400
|
-
* <tt>pluralize(2, 'person')</tt> => '2 people'
|
401
|
-
* <tt>word_wrap(text, *args)</tt>
|
402
|
-
* Wraps the text into lines no longer than line_width width.
|
403
|
-
* <tt>word_wrap('Once upon a time', :line_width => 8)</tt> => "Once upon\na time"
|
404
|
-
* <tt>truncate(text, *args)</tt>
|
405
|
-
* Truncates a given text after a given :length if text is longer than :length (defaults to 30).
|
406
|
-
* <tt>truncate("Once upon a time in a world far far away", :length => 8)</tt> => "Once upon..."
|
407
|
-
* <tt>escape_html</tt> (alias <tt>h</tt> and <tt>h!</tt>)
|
408
|
-
* (from RackUtils) Escape ampersands, brackets and quotes to their HTML/XML entities.
|
409
|
-
* <tt>relative_time_ago(date)</tt>
|
410
|
-
* Returns relative time in words referencing the given date
|
411
|
-
* <tt>relative_time_ago(2.days.ago)</tt> => "2 days"
|
412
|
-
* <tt>relative_time_ago(5.minutes.ago)</tt> => "5 minutes"
|
413
|
-
* <tt>relative_time_ago(2800.days.ago)</tt> => "over 7 years"
|
414
|
-
* <tt>time_in_words(date)</tt>
|
415
|
-
* Returns relative time in the past or future using appropriate date format
|
416
|
-
* <tt>time_in_words(2.days.ago)</tt> => "2 days ago"
|
417
|
-
* <tt>time_in_words(100.days.ago)</tt> => "Tuesday, July 21"
|
418
|
-
* <tt>time_in_words(1.day.from_now)</tt> => "tomorrow"
|
419
|
-
* <tt>js_escape_html(html_content)</tt>
|
420
|
-
* Escapes html to allow passing information to javascript. Used for passing data inside an ajax .js.erb template
|
421
|
-
* <tt>js_escape_html("<h1>Hey</h1>")</tt>
|
422
|
-
|
423
|
-
See the wiki article for additional information: <...WIKI...>
|
206
|
+
For more information on using the format helpers, check out the guide for
|
207
|
+
{Padrino Helpers}[http://wiki.github.com/padrino/padrino-framework/application-helpers].
|
424
208
|
|
425
209
|
=== Render Helpers
|
426
210
|
|
@@ -439,34 +223,13 @@ There is also a method which renders the first view matching the path and remove
|
|
439
223
|
|
440
224
|
render 'path/to/any/template'
|
441
225
|
|
442
|
-
It is worth noting these are mostly for convenience. With nested view file paths in Sinatra, this becomes tiresome:
|
443
|
-
|
444
|
-
haml :"the/path/to/file"
|
445
|
-
erb "/path/to/file".to_sym
|
446
|
-
|
447
226
|
Finally, we have the all-important partials support for rendering mini-templates onto a page:
|
448
227
|
|
449
228
|
partial 'photo/_item', :object => @photo, :locals => { :foo => 'bar' }
|
450
229
|
partial 'photo/_item', :collection => @photos
|
451
230
|
|
452
|
-
|
453
|
-
|
454
|
-
# /views/photo/_item.haml
|
455
|
-
# Access to collection counter with <partial_name>_counter i.e item_counter
|
456
|
-
# Access the object with the partial_name i.e item
|
457
|
-
|
458
|
-
The list of defined helpers in the 'render helpers' category:
|
459
|
-
|
460
|
-
* <tt>render(engine, data, options, locals)</tt>
|
461
|
-
* Renders the specified template with the given options
|
462
|
-
* <tt>render ‘user/new’'</tt>
|
463
|
-
* <tt>render :erb, ‘users/new’, :layout => false</tt>
|
464
|
-
* <tt>partial(template, *args)</tt>
|
465
|
-
* Renders the html related to the partial template for object or collection
|
466
|
-
* <tt>partial 'photo/_item', :object => @photo, :locals => { :foo => 'bar' }</tt>
|
467
|
-
* <tt>partial 'photo/_item', :collection => @photos</tt>
|
468
|
-
|
469
|
-
See the wiki article for additional information: <...WIKI...>
|
231
|
+
For more information on using the render and partial helpers, check out the guide for
|
232
|
+
{Padrino Helpers}[http://wiki.github.com/padrino/padrino-framework/application-helpers].
|
470
233
|
|
471
234
|
== Copyright
|
472
235
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.2
|
@@ -208,10 +208,13 @@ module Padrino
|
|
208
208
|
|
209
209
|
##
|
210
210
|
# Generates a favicon link.
|
211
|
-
#
|
212
|
-
#
|
213
|
-
#
|
214
|
-
#
|
211
|
+
#
|
212
|
+
# ==== Examples
|
213
|
+
#
|
214
|
+
# favicon_tag 'images/favicon.png'
|
215
|
+
# # or override some options
|
216
|
+
# favicon_tag 'images/favicon.png', :type => 'image/ico'
|
217
|
+
#
|
215
218
|
def favicon_tag(source,options={})
|
216
219
|
type = File.extname(source).gsub('.','')
|
217
220
|
options = options.dup.reverse_merge!(:href => source, :rel => 'icon', :type => "image/#{type}")
|
@@ -67,15 +67,15 @@ module Padrino
|
|
67
67
|
def check_box(field, options={})
|
68
68
|
unchecked_value = options.delete(:uncheck_value) || '0'
|
69
69
|
options.reverse_merge!(:id => field_id(field), :value => '1')
|
70
|
-
options.
|
71
|
-
html
|
70
|
+
options.reverse_merge!(:checked => true) if values_matches_field?(field, options[:value])
|
71
|
+
html = @template.hidden_field_tag(options[:name] || field_name(field), :value => unchecked_value, :id => nil)
|
72
72
|
html << @template.check_box_tag(field_name(field), options)
|
73
73
|
end
|
74
74
|
|
75
75
|
# f.radio_button :gender, :value => 'male'
|
76
76
|
def radio_button(field, options={})
|
77
77
|
options.reverse_merge!(:id => field_id(field, options[:value]))
|
78
|
-
options.
|
78
|
+
options.reverse_merge!(:checked => true) if values_matches_field?(field, options[:value])
|
79
79
|
@template.radio_button_tag field_name(field), options
|
80
80
|
end
|
81
81
|
|
@@ -122,7 +122,8 @@ module Padrino
|
|
122
122
|
|
123
123
|
# Add a :invalid css class to the field if it contain an error
|
124
124
|
def field_error(field, options)
|
125
|
-
|
125
|
+
error = @object.errors[field] rescue nil
|
126
|
+
if error
|
126
127
|
[options[:class], :invalid].flatten.compact.join(" ")
|
127
128
|
else
|
128
129
|
options[:class]
|
@@ -163,7 +163,8 @@ module Padrino
|
|
163
163
|
#
|
164
164
|
def error_message_on(object, field, options={})
|
165
165
|
object = instance_variable_get("@#{object}")
|
166
|
-
|
166
|
+
error = object.errors[field] rescue nil
|
167
|
+
if error
|
167
168
|
options.reverse_merge!(:tag => :span, :class => :error)
|
168
169
|
tag = options.delete(:tag)
|
169
170
|
error = [options.delete(:prepend), Array(object.errors[field]).first, options.delete(:append)].compact.join(" ")
|
@@ -88,6 +88,32 @@ module Padrino
|
|
88
88
|
end * "\n"
|
89
89
|
end
|
90
90
|
|
91
|
+
##
|
92
|
+
# Highlights one or more words everywhere in text by inserting it into a :highlighter string.
|
93
|
+
#
|
94
|
+
# The highlighter can be customized by passing :+highlighter+ as a single-quoted string
|
95
|
+
# with \1 where the phrase is to be inserted (defaults to ’<strong class="highlight">\1</strong>’)
|
96
|
+
#
|
97
|
+
# ==== Examples
|
98
|
+
#
|
99
|
+
# # => Lorem ipsum <strong class="highlight">dolor</strong> sit amet
|
100
|
+
# highlight('Lorem ipsum dolor sit amet', 'dolor')
|
101
|
+
#
|
102
|
+
# # => Lorem ipsum <span class="custom">dolor</span> sit amet
|
103
|
+
# highlight('Lorem ipsum dolor sit amet', 'dolor', :highlighter => '<span class="custom">\1</span>')
|
104
|
+
#
|
105
|
+
def highlight(text, words, *args)
|
106
|
+
options = args.extract_options!
|
107
|
+
options.reverse_merge!(:highlighter => '<strong class="highlight">\1</strong>')
|
108
|
+
|
109
|
+
if text.blank? || words.blank?
|
110
|
+
text
|
111
|
+
else
|
112
|
+
match = Array(words).map { |p| Regexp.escape(p) }.join('|')
|
113
|
+
text.gsub(/(#{match})(?!(?:[^<]*?)(?:["'])[^<>]*>)/i, options[:highlighter])
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
91
117
|
##
|
92
118
|
# Reports the approximate distance in time between two Time or Date objects or integers as seconds.
|
93
119
|
# Set <tt>include_seconds</tt> to true if you want more detailed approximations when distance < 1 min, 29 secs
|
data/padrino-helpers.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{padrino-helpers}
|
8
|
-
s.version = "0.9.
|
8
|
+
s.version = "0.9.2"
|
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-
|
12
|
+
s.date = %q{2010-03-01}
|
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 = [
|
@@ -76,7 +76,7 @@ Gem::Specification.new do |s|
|
|
76
76
|
s.rdoc_options = ["--charset=UTF-8"]
|
77
77
|
s.require_paths = ["lib"]
|
78
78
|
s.rubyforge_project = %q{padrino-helpers}
|
79
|
-
s.rubygems_version = %q{1.3.
|
79
|
+
s.rubygems_version = %q{1.3.5}
|
80
80
|
s.summary = %q{Helpers for padrino}
|
81
81
|
|
82
82
|
if s.respond_to? :specification_version then
|
@@ -84,14 +84,14 @@ Gem::Specification.new do |s|
|
|
84
84
|
s.specification_version = 3
|
85
85
|
|
86
86
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
87
|
-
s.add_runtime_dependency(%q<padrino-core>, ["= 0.9.
|
87
|
+
s.add_runtime_dependency(%q<padrino-core>, ["= 0.9.2"])
|
88
88
|
s.add_development_dependency(%q<haml>, [">= 2.2.1"])
|
89
89
|
s.add_development_dependency(%q<shoulda>, [">= 2.10.3"])
|
90
90
|
s.add_development_dependency(%q<mocha>, [">= 0.9.7"])
|
91
91
|
s.add_development_dependency(%q<rack-test>, [">= 0.5.0"])
|
92
92
|
s.add_development_dependency(%q<webrat>, [">= 0.5.1"])
|
93
93
|
else
|
94
|
-
s.add_dependency(%q<padrino-core>, ["= 0.9.
|
94
|
+
s.add_dependency(%q<padrino-core>, ["= 0.9.2"])
|
95
95
|
s.add_dependency(%q<haml>, [">= 2.2.1"])
|
96
96
|
s.add_dependency(%q<shoulda>, [">= 2.10.3"])
|
97
97
|
s.add_dependency(%q<mocha>, [">= 0.9.7"])
|
@@ -99,7 +99,7 @@ Gem::Specification.new do |s|
|
|
99
99
|
s.add_dependency(%q<webrat>, [">= 0.5.1"])
|
100
100
|
end
|
101
101
|
else
|
102
|
-
s.add_dependency(%q<padrino-core>, ["= 0.9.
|
102
|
+
s.add_dependency(%q<padrino-core>, ["= 0.9.2"])
|
103
103
|
s.add_dependency(%q<haml>, [">= 2.2.1"])
|
104
104
|
s.add_dependency(%q<shoulda>, [">= 2.10.3"])
|
105
105
|
s.add_dependency(%q<mocha>, [">= 0.9.7"])
|
data/test/test_format_helpers.rb
CHANGED
@@ -61,6 +61,18 @@ class TestFormatHelpers < Test::Unit::TestCase
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
+
context 'for #highlight method' do
|
65
|
+
should 'highligth with defaults' do
|
66
|
+
actual_text = highlight('Lorem ipsum dolor sit amet', 'dolor')
|
67
|
+
assert_equal 'Lorem ipsum <strong class="highlight">dolor</strong> sit amet', actual_text
|
68
|
+
end
|
69
|
+
|
70
|
+
should 'highlight with highlighter' do
|
71
|
+
actual_text = highlight('Lorem ipsum dolor sit amet', 'dolor', :highlighter => '<span class="custom">\1</span>')
|
72
|
+
assert_equal 'Lorem ipsum <span class="custom">dolor</span> sit amet', actual_text
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
64
76
|
context 'for #truncate method' do
|
65
77
|
should "support default truncation" do
|
66
78
|
actual_text = truncate("Once upon a time in a world far far away")
|
metadata
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: padrino-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 9
|
8
|
-
- 1
|
9
|
-
version: 0.9.1
|
4
|
+
version: 0.9.2
|
10
5
|
platform: ruby
|
11
6
|
authors:
|
12
7
|
- Padrino Team
|
@@ -17,93 +12,69 @@ autorequire:
|
|
17
12
|
bindir: bin
|
18
13
|
cert_chain: []
|
19
14
|
|
20
|
-
date: 2010-
|
15
|
+
date: 2010-03-01 00:00:00 +01:00
|
21
16
|
default_executable:
|
22
17
|
dependencies:
|
23
18
|
- !ruby/object:Gem::Dependency
|
24
19
|
name: padrino-core
|
25
|
-
|
26
|
-
|
20
|
+
type: :runtime
|
21
|
+
version_requirement:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
23
|
requirements:
|
28
24
|
- - "="
|
29
25
|
- !ruby/object:Gem::Version
|
30
|
-
|
31
|
-
|
32
|
-
- 9
|
33
|
-
- 1
|
34
|
-
version: 0.9.1
|
35
|
-
type: :runtime
|
36
|
-
version_requirements: *id001
|
26
|
+
version: 0.9.2
|
27
|
+
version:
|
37
28
|
- !ruby/object:Gem::Dependency
|
38
29
|
name: haml
|
39
|
-
|
40
|
-
|
30
|
+
type: :development
|
31
|
+
version_requirement:
|
32
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
33
|
requirements:
|
42
34
|
- - ">="
|
43
35
|
- !ruby/object:Gem::Version
|
44
|
-
segments:
|
45
|
-
- 2
|
46
|
-
- 2
|
47
|
-
- 1
|
48
36
|
version: 2.2.1
|
49
|
-
|
50
|
-
version_requirements: *id002
|
37
|
+
version:
|
51
38
|
- !ruby/object:Gem::Dependency
|
52
39
|
name: shoulda
|
53
|
-
|
54
|
-
|
40
|
+
type: :development
|
41
|
+
version_requirement:
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
55
43
|
requirements:
|
56
44
|
- - ">="
|
57
45
|
- !ruby/object:Gem::Version
|
58
|
-
segments:
|
59
|
-
- 2
|
60
|
-
- 10
|
61
|
-
- 3
|
62
46
|
version: 2.10.3
|
63
|
-
|
64
|
-
version_requirements: *id003
|
47
|
+
version:
|
65
48
|
- !ruby/object:Gem::Dependency
|
66
49
|
name: mocha
|
67
|
-
|
68
|
-
|
50
|
+
type: :development
|
51
|
+
version_requirement:
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
69
53
|
requirements:
|
70
54
|
- - ">="
|
71
55
|
- !ruby/object:Gem::Version
|
72
|
-
segments:
|
73
|
-
- 0
|
74
|
-
- 9
|
75
|
-
- 7
|
76
56
|
version: 0.9.7
|
77
|
-
|
78
|
-
version_requirements: *id004
|
57
|
+
version:
|
79
58
|
- !ruby/object:Gem::Dependency
|
80
59
|
name: rack-test
|
81
|
-
|
82
|
-
|
60
|
+
type: :development
|
61
|
+
version_requirement:
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
83
63
|
requirements:
|
84
64
|
- - ">="
|
85
65
|
- !ruby/object:Gem::Version
|
86
|
-
segments:
|
87
|
-
- 0
|
88
|
-
- 5
|
89
|
-
- 0
|
90
66
|
version: 0.5.0
|
91
|
-
|
92
|
-
version_requirements: *id005
|
67
|
+
version:
|
93
68
|
- !ruby/object:Gem::Dependency
|
94
69
|
name: webrat
|
95
|
-
|
96
|
-
|
70
|
+
type: :development
|
71
|
+
version_requirement:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
97
73
|
requirements:
|
98
74
|
- - ">="
|
99
75
|
- !ruby/object:Gem::Version
|
100
|
-
segments:
|
101
|
-
- 0
|
102
|
-
- 5
|
103
|
-
- 1
|
104
76
|
version: 0.5.1
|
105
|
-
|
106
|
-
version_requirements: *id006
|
77
|
+
version:
|
107
78
|
description: Tag helpers, asset helpers, form helpers, form builders and many more helpers for padrino
|
108
79
|
email: padrinorb@gmail.com
|
109
80
|
executables: []
|
@@ -181,20 +152,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
181
152
|
requirements:
|
182
153
|
- - ">="
|
183
154
|
- !ruby/object:Gem::Version
|
184
|
-
segments:
|
185
|
-
- 0
|
186
155
|
version: "0"
|
156
|
+
version:
|
187
157
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
188
158
|
requirements:
|
189
159
|
- - ">="
|
190
160
|
- !ruby/object:Gem::Version
|
191
|
-
segments:
|
192
|
-
- 0
|
193
161
|
version: "0"
|
162
|
+
version:
|
194
163
|
requirements: []
|
195
164
|
|
196
165
|
rubyforge_project: padrino-helpers
|
197
|
-
rubygems_version: 1.3.
|
166
|
+
rubygems_version: 1.3.5
|
198
167
|
signing_key:
|
199
168
|
specification_version: 3
|
200
169
|
summary: Helpers for padrino
|