padrino-helpers 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.2.6
@@ -40,6 +40,14 @@ module Padrino
40
40
  link_to (caption || email), mail_href, html_options
41
41
  end
42
42
 
43
+ # Creates a meta element with the content and given options
44
+ # meta_tag "weblog,news", :name => "keywords" => <meta name="keywords" content="weblog,news">
45
+ # meta_tag "text/html; charset=UTF-8", :http-equiv => "Content-Type" => <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
46
+ def meta_tag(content, options={})
47
+ options.reverse_merge!("content" => content)
48
+ content_tag(:meta, '', options)
49
+ end
50
+
43
51
  # Creates an image element with given url and options
44
52
  # image_tag('icons/avatar.png')
45
53
  def image_tag(url, options={})
@@ -18,7 +18,7 @@ module Padrino
18
18
 
19
19
  # f.label :username, :caption => "Nickname"
20
20
  def label(field, options={})
21
- options.reverse_merge!(:caption => field.to_s.titleize)
21
+ options.reverse_merge!(:caption => "#{field.to_s.titleize}: ")
22
22
  @template.label_tag(field_id(field), options)
23
23
  end
24
24
 
@@ -56,8 +56,8 @@ module Padrino
56
56
  # label_tag :username, :class => 'long-label'
57
57
  # label_tag :username, :class => 'long-label' do ... end
58
58
  def label_tag(name, options={}, &block)
59
- options.reverse_merge!(:caption => name.to_s.titleize, :for => name)
60
- caption_text = options.delete(:caption) + ": "
59
+ options.reverse_merge!(:caption => "#{name.to_s.titleize}: ", :for => name)
60
+ caption_text = options.delete(:caption)
61
61
  if block_given? # label with inner content
62
62
  label_content = caption_text + capture_html(&block)
63
63
  concat_content(content_tag(:label, label_content, options))
@@ -81,10 +81,10 @@ module Padrino
81
81
  end
82
82
 
83
83
  # Constructs a text area input from the given options
84
- # text_area_tag :username, :class => 'long'
84
+ # text_area_tag :username, :class => 'long', :value => "Demo?"
85
85
  def text_area_tag(name, options={})
86
- options.reverse_merge!(:name => name)
87
- content_tag(:textarea, '', options)
86
+ options.reverse_merge!(:name => name, :value => '')
87
+ content_tag(:textarea, options.delete(:value), options)
88
88
  end
89
89
 
90
90
  # Constructs a password field input from the given options
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{padrino-helpers}
8
- s.version = "0.2.5"
8
+ s.version = "0.2.6"
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{2009-12-21}
12
+ s.date = %q{2009-12-22}
13
13
  s.description = %q{Tag helpers, asset helpers, form helpers, form builders and many more helpers for padrino}
14
14
  s.email = %q{nesquena@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -49,6 +49,8 @@ Gem::Specification.new do |s|
49
49
  "test/fixtures/markup_app/views/link_to.haml",
50
50
  "test/fixtures/markup_app/views/mail_to.erb",
51
51
  "test/fixtures/markup_app/views/mail_to.haml",
52
+ "test/fixtures/markup_app/views/meta_tag.erb",
53
+ "test/fixtures/markup_app/views/meta_tag.haml",
52
54
  "test/fixtures/render_app/app.rb",
53
55
  "test/fixtures/render_app/views/erb/test.erb",
54
56
  "test/fixtures/render_app/views/haml/test.haml",
@@ -2,7 +2,7 @@
2
2
  <%= f.error_messages(:header_message => "custom MarkupUser cannot be saved!") %>
3
3
  <%= f.hidden_field :session_id %>
4
4
  <p>
5
- <%= f.label :username, :caption => "Login", :class => 'user-label' %>
5
+ <%= f.label :username, :caption => "Login: ", :class => 'user-label' %>
6
6
  <%= f.text_field :username, :class => 'user-text', :value => "John" %>
7
7
  </p>
8
8
  <p>
@@ -18,11 +18,11 @@
18
18
  <%= f.file_field :photo, :class => 'user-photo' %>
19
19
  </p>
20
20
  <p>
21
- <%= f.label :about, :caption => "About Me" %>
21
+ <%= f.label :about, :caption => "About Me: " %>
22
22
  <%= f.text_area :about, :class => 'user-about' %>
23
23
  </p>
24
24
  <p>
25
- <%= f.label :gender, :caption => "Your gender:" %>
25
+ <%= f.label :gender, :caption => "Your gender: " %>
26
26
  <%= f.radio_button :gender, :value => 'male' %>
27
27
  <%= f.radio_button :gender, :value => 'female' %>
28
28
  </p>
@@ -41,7 +41,7 @@
41
41
  <% form_for MarkupUser.new, '/another_demo', :id => 'demo2', :method => 'get' do |f| %>
42
42
  <%= f.error_messages :header_message => "custom MarkupUser cannot be saved!" %>
43
43
  <%= f.hidden_field :session_id %>
44
- <%= f.text_field_block :username, { :class => 'input' }, { :caption => 'Nickname', :class => 'label' } %>
44
+ <%= f.text_field_block :username, { :class => 'input' }, { :caption => 'Nickname: ', :class => 'label' } %>
45
45
  <%= f.password_field_block :code, { :class => 'input' } %>
46
46
  <%= f.text_area_block :about, { :class => 'textarea' } %>
47
47
  <%= f.file_field_block :photo, { :class => 'upload' } %>
@@ -2,7 +2,7 @@
2
2
  = f.error_messages(:header_message => "custom MarkupUser cannot be saved!")
3
3
  = f.hidden_field :session_id
4
4
  %p
5
- = f.label :username, :caption => "Login", :class => 'user-label'
5
+ = f.label :username, :caption => "Login: ", :class => 'user-label'
6
6
  = f.text_field :username, :class => 'user-text', :value => "John"
7
7
  %p
8
8
  = f.label :email, :caption => "Email", :class => 'user-email'
@@ -14,10 +14,10 @@
14
14
  = f.label :photo
15
15
  = f.file_field :photo, :class => 'user-photo'
16
16
  %p
17
- = f.label :about, :caption => "About Me"
17
+ = f.label :about, :caption => "About Me: "
18
18
  = f.text_area :about, :class => 'user-about'
19
19
  %p
20
- = f.label :gender, :caption => "Your gender"
20
+ = f.label :gender, :caption => "Your gender: "
21
21
  = f.radio_button :gender, :value => 'male'
22
22
  = f.radio_button :gender, :value => 'female'
23
23
  %p
@@ -34,7 +34,7 @@
34
34
  - form_for MarkupUser.new, '/another_demo', :id => 'demo2', :method => 'get' do |f|
35
35
  = f.error_messages :header_message => "custom MarkupUser cannot be saved!"
36
36
  = f.hidden_field :session_id
37
- = f.text_field_block :username, { :class => 'input' }, { :caption => 'Nickname', :class => 'label' }
37
+ = f.text_field_block :username, { :class => 'input' }, { :caption => 'Nickname: ', :class => 'label' }
38
38
  = f.password_field_block :code, { :class => 'input' }
39
39
  = f.text_area_block :about, { :class => 'textarea' }
40
40
  = f.file_field_block :photo, { :class => 'upload' }
@@ -0,0 +1,3 @@
1
+ <%= meta_tag "weblog,news", :name => "keywords" %>
2
+
3
+ <%= meta_tag "text/html; charset=UTF-8", :"http-equiv" => "Content-Type" %>
@@ -0,0 +1,3 @@
1
+ = meta_tag "weblog,news", :name => "keywords"
2
+
3
+ = meta_tag "text/html; charset=UTF-8", :"http-equiv" => "Content-Type"
@@ -82,6 +82,27 @@ class TestAssetTagHelpers < Test::Unit::TestCase
82
82
  end
83
83
  end
84
84
 
85
+ context 'for #meta_tag method' do
86
+ should "display meta tag with given content and name" do
87
+ actual_html = meta_tag("weblog,news", :name => "keywords")
88
+ assert_has_tag("meta", :name => "keywords", "content" => "weblog,news") { actual_html }
89
+ end
90
+ should "display meta tag with given content and http-equiv" do
91
+ actual_html = meta_tag("text/html; charset=UTF-8", :"http-equiv" => "Content-Type")
92
+ assert_has_tag("meta", :"http-equiv" => "Content-Type", "content" => "text/html; charset=UTF-8") { actual_html }
93
+ end
94
+ should "display meta tag element in haml" do
95
+ visit '/haml/meta_tag'
96
+ assert_have_selector 'meta', "content" => "weblog,news", :name => "keywords"
97
+ assert_have_selector 'meta', "content" => "text/html; charset=UTF-8", :"http-equiv" => "Content-Type"
98
+ end
99
+ should "display meta tag element in erb" do
100
+ visit '/erb/meta_tag'
101
+ assert_have_selector 'meta', "content" => "weblog,news", :name => "keywords"
102
+ assert_have_selector 'meta', "content" => "text/html; charset=UTF-8", :"http-equiv" => "Content-Type"
103
+ end
104
+ end
105
+
85
106
  context 'for #image_tag method' do
86
107
  should "display image tag absolute link with no options" do
87
108
  assert_has_tag('img', :src => "/absolute/pic.gif") { image_tag('/absolute/pic.gif') }
@@ -148,7 +148,7 @@ class TestFormBuilder < Test::Unit::TestCase
148
148
 
149
149
  context 'for #label method' do
150
150
  should "display correct label html" do
151
- actual_html = standard_builder.label(:first_name, :class => 'large', :caption => "F. Name")
151
+ actual_html = standard_builder.label(:first_name, :class => 'large', :caption => "F. Name: ")
152
152
  assert_has_tag('label', :class => 'large', :for => 'user_first_name', :content => "F. Name: ") { actual_html }
153
153
  end
154
154
 
@@ -301,6 +301,11 @@ class TestFormBuilder < Test::Unit::TestCase
301
301
  assert_has_tag('textarea.large', :id => 'user_about', :name => 'user[about]') { actual_html }
302
302
  end
303
303
 
304
+ should "display correct text_area html and content" do
305
+ actual_html = standard_builder.text_area(:about, :value => "Demo")
306
+ assert_has_tag('textarea', :id => 'user_about', :content => 'Demo') { actual_html }
307
+ end
308
+
304
309
  should "display correct text_area in haml" do
305
310
  visit '/haml/form_for'
306
311
  assert_have_selector '#demo textarea', :name => 'markup_user[about]', :id => 'markup_user_about', :class => 'user-about'
@@ -454,7 +459,7 @@ class TestFormBuilder < Test::Unit::TestCase
454
459
  context 'for #text_field_block method' do
455
460
  should "display correct text field block html" do
456
461
  actual_html = standard_builder.text_field_block(:first_name, :class => 'large', :caption => "FName")
457
- assert_has_tag('p label', :for => 'user_first_name', :content => "FName: ") { actual_html }
462
+ assert_has_tag('p label', :for => 'user_first_name', :content => "FName") { actual_html }
458
463
  assert_has_tag('p input.large[type=text]', :value => "Joe", :id => 'user_first_name', :name => 'user[first_name]') { actual_html }
459
464
  end
460
465
 
@@ -474,7 +479,7 @@ class TestFormBuilder < Test::Unit::TestCase
474
479
  context 'for #text_area_block method' do
475
480
  should "display correct text area block html" do
476
481
  actual_html = standard_builder.text_area_block(:about, :class => 'large', :caption => "About Me")
477
- assert_has_tag('p label', :for => 'user_about', :content => "About Me: ") { actual_html }
482
+ assert_has_tag('p label', :for => 'user_about', :content => "About Me") { actual_html }
478
483
  assert_has_tag('p textarea', :id => 'user_about', :name => 'user[about]') { actual_html }
479
484
  end
480
485
 
@@ -493,7 +498,7 @@ class TestFormBuilder < Test::Unit::TestCase
493
498
 
494
499
  context 'for #password_field_block method' do
495
500
  should "display correct password field block html" do
496
- actual_html = standard_builder.password_field_block(:keycode, :class => 'large', :caption => "Code")
501
+ actual_html = standard_builder.password_field_block(:keycode, :class => 'large', :caption => "Code: ")
497
502
  assert_has_tag('p label', :for => 'user_keycode', :content => "Code: ") { actual_html }
498
503
  assert_has_tag('p input.large[type=password]', :id => 'user_keycode', :name => 'user[keycode]') { actual_html }
499
504
  end
@@ -513,7 +518,7 @@ class TestFormBuilder < Test::Unit::TestCase
513
518
 
514
519
  context 'for #file_field_block method' do
515
520
  should "display correct file field block html" do
516
- actual_html = standard_builder.file_field_block(:photo, :class => 'large', :caption => "Photo")
521
+ actual_html = standard_builder.file_field_block(:photo, :class => 'large', :caption => "Photo: ")
517
522
  assert_has_tag('p label', :for => 'user_photo', :content => "Photo: ") { actual_html }
518
523
  assert_has_tag('p input.large[type=file]', :id => 'user_photo', :name => 'user[photo]') { actual_html }
519
524
  end
@@ -533,8 +538,8 @@ class TestFormBuilder < Test::Unit::TestCase
533
538
 
534
539
  context 'for #check_box_block method' do
535
540
  should "display correct check box block html" do
536
- actual_html = standard_builder.check_box_block(:remember_me, :class => 'large', :caption => "Remember session")
537
- assert_has_tag('p label', :for => 'user_remember_me', :content => "Remember session: ") { actual_html }
541
+ actual_html = standard_builder.check_box_block(:remember_me, :class => 'large', :caption => "Remember session?")
542
+ assert_has_tag('p label', :for => 'user_remember_me', :content => "Remember session?") { actual_html }
538
543
  assert_has_tag('p input.large[type=checkbox]', :id => 'user_remember_me', :name => 'user[remember_me]') { actual_html }
539
544
  end
540
545
 
@@ -554,7 +559,7 @@ class TestFormBuilder < Test::Unit::TestCase
554
559
  context 'for #select_block method' do
555
560
  should "display correct select_block block html" do
556
561
  actual_html = standard_builder.select_block(:country, :options => ['USA', 'Canada'], :class => 'large', :caption => "Your country")
557
- assert_has_tag('p label', :for => 'user_country', :content => "Your country: ") { actual_html }
562
+ assert_has_tag('p label', :for => 'user_country', :content => "Your country") { actual_html }
558
563
  assert_has_tag('p select', :id => 'user_country', :name => 'user[country]') { actual_html }
559
564
  assert_has_tag('p select option', :content => 'USA') { actual_html }
560
565
  assert_has_tag('p select option', :content => 'Canada') { actual_html }
@@ -108,7 +108,7 @@ class TestFormHelpers < Test::Unit::TestCase
108
108
  context 'for #label_tag method' do
109
109
  should "display label tag in ruby" do
110
110
  actual_html = label_tag(:username, :class => 'long-label', :caption => "Nickname")
111
- assert_has_tag(:label, :for => 'username', :class => 'long-label', :content => "Nickname: ") { actual_html }
111
+ assert_has_tag(:label, :for => 'username', :class => 'long-label', :content => "Nickname") { actual_html }
112
112
  end
113
113
 
114
114
  should "display label tag in erb for simple form" do
@@ -190,6 +190,11 @@ class TestFormHelpers < Test::Unit::TestCase
190
190
  assert_has_tag(:textarea, :class => "long", :name => 'about') { actual_html }
191
191
  end
192
192
 
193
+ should "display text area in ruby with specified content" do
194
+ actual_html = text_area_tag(:about, :value => "a test")
195
+ assert_has_tag(:textarea, :content => "a test", :name => 'about') { actual_html }
196
+ end
197
+
193
198
  should "display text area in erb" do
194
199
  visit '/erb/form_tag'
195
200
  assert_have_selector 'form.advanced-form textarea', :count => 1, :name => 'about', :class => 'large'
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.2.5
4
+ version: 0.2.6
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: 2009-12-21 00:00:00 -08:00
15
+ date: 2009-12-22 00:00:00 -08:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -127,6 +127,8 @@ files:
127
127
  - test/fixtures/markup_app/views/link_to.haml
128
128
  - test/fixtures/markup_app/views/mail_to.erb
129
129
  - test/fixtures/markup_app/views/mail_to.haml
130
+ - test/fixtures/markup_app/views/meta_tag.erb
131
+ - test/fixtures/markup_app/views/meta_tag.haml
130
132
  - test/fixtures/render_app/app.rb
131
133
  - test/fixtures/render_app/views/erb/test.erb
132
134
  - test/fixtures/render_app/views/haml/test.haml