sinatra_more 0.3.27 → 0.3.28
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/sinatra_more/markup_plugin/asset_tag_helpers.rb +8 -0
- data/lib/sinatra_more/markup_plugin/form_builder/abstract_form_builder.rb +1 -1
- data/lib/sinatra_more/markup_plugin/form_helpers.rb +5 -5
- data/lib/sinatra_more/warden_plugin.rb +5 -3
- data/sinatra_more.gemspec +4 -2
- data/test/fixtures/markup_app/views/form_for.erb +4 -4
- data/test/fixtures/markup_app/views/form_for.haml +4 -4
- data/test/fixtures/markup_app/views/meta_tag.erb +3 -0
- data/test/fixtures/markup_app/views/meta_tag.haml +3 -0
- data/test/markup_plugin/test_asset_tag_helpers.rb +23 -0
- data/test/markup_plugin/test_form_builder.rb +15 -10
- data/test/markup_plugin/test_form_helpers.rb +7 -2
- metadata +4 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.28
|
@@ -38,6 +38,14 @@ module SinatraMore
|
|
38
38
|
link_to (caption || email), mail_href, html_options
|
39
39
|
end
|
40
40
|
|
41
|
+
# Creates a meta element with the content and given options
|
42
|
+
# meta_tag "weblog,news", :name => "keywords" => <meta name="keywords" content="weblog,news">
|
43
|
+
# meta_tag "text/html; charset=UTF-8", :http-equiv => "Content-Type" => <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
44
|
+
def meta_tag(content, options={})
|
45
|
+
options.reverse_merge!("content" => content)
|
46
|
+
content_tag(:meta, '', options)
|
47
|
+
end
|
48
|
+
|
41
49
|
# Creates an image element with given url and options
|
42
50
|
# image_tag('icons/avatar.png')
|
43
51
|
def image_tag(url, options={})
|
@@ -15,7 +15,7 @@ class AbstractFormBuilder
|
|
15
15
|
|
16
16
|
# f.label :username, :caption => "Nickname"
|
17
17
|
def label(field, options={})
|
18
|
-
options.reverse_merge!(:caption => field.to_s.titleize)
|
18
|
+
options.reverse_merge!(:caption => "#{field.to_s.titleize}: ")
|
19
19
|
@template.label_tag(field_id(field), options)
|
20
20
|
end
|
21
21
|
|
@@ -55,8 +55,8 @@ module SinatraMore
|
|
55
55
|
# label_tag :username, :class => 'long-label'
|
56
56
|
# label_tag :username, :class => 'long-label' do ... end
|
57
57
|
def label_tag(name, options={}, &block)
|
58
|
-
options.reverse_merge!(:caption => name.to_s.titleize, :for => name)
|
59
|
-
caption_text = options.delete(:caption)
|
58
|
+
options.reverse_merge!(:caption => "#{name.to_s.titleize}: ", :for => name)
|
59
|
+
caption_text = options.delete(:caption)
|
60
60
|
if block_given? # label with inner content
|
61
61
|
label_content = caption_text + capture_html(&block)
|
62
62
|
concat_content(content_tag(:label, label_content, options))
|
@@ -80,10 +80,10 @@ module SinatraMore
|
|
80
80
|
end
|
81
81
|
|
82
82
|
# Constructs a text area input from the given options
|
83
|
-
# text_area_tag :username, :class => 'long'
|
83
|
+
# text_area_tag :username, :class => 'long', :value => "Demo?"
|
84
84
|
def text_area_tag(name, options={})
|
85
|
-
options.reverse_merge!(:name => name)
|
86
|
-
content_tag(:textarea,
|
85
|
+
options.reverse_merge!(:name => name, :value => '')
|
86
|
+
content_tag(:textarea, options.delete(:value), options)
|
87
87
|
end
|
88
88
|
|
89
89
|
# Constructs a password field input from the given options
|
@@ -32,14 +32,16 @@ module SinatraMore
|
|
32
32
|
raise "WardenPlugin::Error - Install warden with 'sudo gem install warden' to use plugin!" unless Warden && Warden::Manager
|
33
33
|
app.use Warden::Manager do |manager|
|
34
34
|
manager.default_strategies :password
|
35
|
+
manager.default_serializers :session, :cookie
|
35
36
|
manager.failure_app = app
|
37
|
+
manager.serializers.update(:session) do
|
38
|
+
def serialize(user); user.nil? ? nil : user.id; end
|
39
|
+
def deserialize(id); id.nil? ? nil : PasswordStrategy.user_class.find(id); end
|
40
|
+
end
|
36
41
|
end
|
37
42
|
app.helpers SinatraMore::OutputHelpers
|
38
43
|
app.helpers SinatraMore::WardenHelpers
|
39
|
-
|
40
44
|
Warden::Manager.before_failure { |env,opts| env['REQUEST_METHOD'] = "POST" }
|
41
|
-
Warden::Manager.serialize_into_session { |user| user.nil? ? nil : user.id }
|
42
|
-
Warden::Manager.serialize_from_session { |id| id.nil? ? nil : PasswordStrategy.user_class.find(id) }
|
43
45
|
Warden::Strategies.add(:password, PasswordStrategy)
|
44
46
|
PasswordStrategy.user_class = User if defined?(User)
|
45
47
|
end
|
data/sinatra_more.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sinatra_more}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.28"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Nathan Esquenazi"]
|
12
|
-
s.date = %q{2009-12-
|
12
|
+
s.date = %q{2009-12-22}
|
13
13
|
s.default_executable = %q{sinatra_gen}
|
14
14
|
s.description = %q{Expands sinatra with standard helpers and tools to allow for complex applications}
|
15
15
|
s.email = %q{nesquena@gmail.com}
|
@@ -116,6 +116,8 @@ Gem::Specification.new do |s|
|
|
116
116
|
"test/fixtures/markup_app/views/link_to.haml",
|
117
117
|
"test/fixtures/markup_app/views/mail_to.erb",
|
118
118
|
"test/fixtures/markup_app/views/mail_to.haml",
|
119
|
+
"test/fixtures/markup_app/views/meta_tag.erb",
|
120
|
+
"test/fixtures/markup_app/views/meta_tag.haml",
|
119
121
|
"test/fixtures/render_app/app.rb",
|
120
122
|
"test/fixtures/render_app/views/erb/test.erb",
|
121
123
|
"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' }
|
@@ -145,4 +145,27 @@ class TestAssetTagHelpers < Test::Unit::TestCase
|
|
145
145
|
assert_has_tag('script', :src => "http://google.com/lib.js") { actual_html }
|
146
146
|
end
|
147
147
|
end
|
148
|
+
|
149
|
+
context 'for #meta_tag method' do
|
150
|
+
should "display meta tag with given content and name" do
|
151
|
+
actual_html = meta_tag("weblog,news", :name => "keywords")
|
152
|
+
assert_has_tag("meta", :name => "keywords", "content" => "weblog,news") { actual_html }
|
153
|
+
end
|
154
|
+
should "display meta tag with given content and http-equiv" do
|
155
|
+
actual_html = meta_tag("text/html; charset=UTF-8", :"http-equiv" => "Content-Type")
|
156
|
+
assert_has_tag("meta", :"http-equiv" => "Content-Type", "content" => "text/html; charset=UTF-8") { actual_html }
|
157
|
+
end
|
158
|
+
should "display meta tag element in haml" do
|
159
|
+
visit '/haml/meta_tag'
|
160
|
+
assert_have_selector 'meta', "content" => "weblog,news", :name => "keywords"
|
161
|
+
assert_have_selector 'meta', "content" => "text/html; charset=UTF-8", :"http-equiv" => "Content-Type"
|
162
|
+
end
|
163
|
+
should "display meta tag element in erb" do
|
164
|
+
visit '/erb/meta_tag'
|
165
|
+
assert_have_selector 'meta', "content" => "weblog,news", :name => "keywords"
|
166
|
+
assert_have_selector 'meta', "content" => "text/html; charset=UTF-8", :"http-equiv" => "Content-Type"
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
|
148
171
|
end
|
@@ -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
|
|
@@ -300,6 +300,11 @@ class TestFormBuilder < Test::Unit::TestCase
|
|
300
300
|
actual_html = standard_builder.text_area(:about, :class => 'large')
|
301
301
|
assert_has_tag('textarea.large', :id => 'user_about', :name => 'user[about]') { actual_html }
|
302
302
|
end
|
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
|
303
308
|
|
304
309
|
should "display correct text_area in haml" do
|
305
310
|
visit '/haml/form_for'
|
@@ -454,19 +459,19 @@ 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
|
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
|
|
461
466
|
should "display correct text field block in haml" do
|
462
467
|
visit '/haml/form_for'
|
463
|
-
assert_have_selector '#demo2 p label', :for => 'markup_user_username', :content => "Nickname
|
468
|
+
assert_have_selector '#demo2 p label', :for => 'markup_user_username', :content => "Nickname", :class => 'label'
|
464
469
|
assert_have_selector '#demo2 p input', :type => 'text', :name => 'markup_user[username]', :id => 'markup_user_username'
|
465
470
|
end
|
466
471
|
|
467
472
|
should "display correct text field block in erb" do
|
468
473
|
visit '/erb/form_for'
|
469
|
-
assert_have_selector '#demo2 p label', :for => 'markup_user_username', :content => "Nickname
|
474
|
+
assert_have_selector '#demo2 p label', :for => 'markup_user_username', :content => "Nickname", :class => 'label'
|
470
475
|
assert_have_selector '#demo2 p input', :type => 'text', :name => 'markup_user[username]', :id => 'markup_user_username'
|
471
476
|
end
|
472
477
|
end
|
@@ -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
|
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
|
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
|
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
|
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
|
@@ -187,7 +187,12 @@ class TestFormHelpers < Test::Unit::TestCase
|
|
187
187
|
context 'for #text_area_tag method' do
|
188
188
|
should "display text area in ruby" do
|
189
189
|
actual_html = text_area_tag(:about, :class => 'long')
|
190
|
-
assert_has_tag(:textarea, :class => "long", :name => 'about') { actual_html }
|
190
|
+
assert_has_tag(:textarea, :class => "long", :content => '', :name => 'about') { actual_html }
|
191
|
+
end
|
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 }
|
191
196
|
end
|
192
197
|
|
193
198
|
should "display text area in erb" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra_more
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.28
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Esquenazi
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-22 00:00:00 -08:00
|
13
13
|
default_executable: sinatra_gen
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -219,6 +219,8 @@ files:
|
|
219
219
|
- test/fixtures/markup_app/views/link_to.haml
|
220
220
|
- test/fixtures/markup_app/views/mail_to.erb
|
221
221
|
- test/fixtures/markup_app/views/mail_to.haml
|
222
|
+
- test/fixtures/markup_app/views/meta_tag.erb
|
223
|
+
- test/fixtures/markup_app/views/meta_tag.haml
|
222
224
|
- test/fixtures/render_app/app.rb
|
223
225
|
- test/fixtures/render_app/views/erb/test.erb
|
224
226
|
- test/fixtures/render_app/views/haml/test.haml
|