sinatra_more 0.2.0 → 0.2.1
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/README.rdoc +3 -0
- data/VERSION +1 -1
- data/lib/sinatra_more/markup_plugin/asset_tag_helpers.rb +6 -6
- data/lib/sinatra_more/markup_plugin/form_builder/abstract_form_builder.rb +5 -0
- data/lib/sinatra_more/markup_plugin/form_builder/standard_form_builder.rb +8 -2
- data/lib/sinatra_more/markup_plugin/form_helpers.rb +7 -0
- data/lib/sinatra_more/support_lite.rb +1 -0
- data/sinatra_more.gemspec +1 -1
- data/test/fixtures/markup_app/views/form_for.erb +3 -1
- data/test/fixtures/markup_app/views/form_for.haml +4 -1
- data/test/fixtures/markup_app/views/form_tag.erb +1 -0
- data/test/fixtures/markup_app/views/form_tag.haml +2 -1
- data/test/helper.rb +1 -0
- data/test/markup_plugin/test_asset_tag_helpers.rb +3 -0
- data/test/markup_plugin/test_form_builder.rb +41 -0
- data/test/markup_plugin/test_form_helpers.rb +22 -0
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -173,6 +173,9 @@ methods should be very familiar to anyone who has used rails view helpers.
|
|
173
173
|
* <tt>submit_tag(caption, options={})</tt>
|
174
174
|
* Constructs a submit button from the given options
|
175
175
|
* <tt>submit_tag "Create", :class => 'success'</tt>
|
176
|
+
* <tt>image_submit_tag(source, options={})</tt>
|
177
|
+
* Constructs an image submit button from the given options
|
178
|
+
* <tt>image_submit_tag "submit.png", :class => 'success'</tt>
|
176
179
|
|
177
180
|
A form_tag might look like:
|
178
181
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
@@ -48,6 +48,12 @@ module SinatraMore
|
|
48
48
|
sources.collect { |script| javascript_tag(script, options) }.join("\n")
|
49
49
|
end
|
50
50
|
|
51
|
+
# Returns the path to the image, either relative or absolute
|
52
|
+
def image_path(src)
|
53
|
+
src.gsub!(/\s/, '')
|
54
|
+
src =~ %r{^\s*(/|http)} ? src : File.join('/images', src)
|
55
|
+
end
|
56
|
+
|
51
57
|
protected
|
52
58
|
|
53
59
|
# stylesheet_tag('style', :media => 'screen')
|
@@ -62,12 +68,6 @@ module SinatraMore
|
|
62
68
|
tag(:script, options)
|
63
69
|
end
|
64
70
|
|
65
|
-
# Returns the path to the image, either relative or absolute
|
66
|
-
def image_path(src)
|
67
|
-
src.gsub!(/\s/, '')
|
68
|
-
src =~ %r{^\s*/} ? src : File.join('/images', src)
|
69
|
-
end
|
70
|
-
|
71
71
|
def javascript_path(source)
|
72
72
|
return source if source =~ /^http/
|
73
73
|
result_path = "/javascripts/#{File.basename(source, '.js')}.js"
|
@@ -70,6 +70,11 @@ class AbstractFormBuilder
|
|
70
70
|
@template.submit_tag caption, options
|
71
71
|
end
|
72
72
|
|
73
|
+
# f.simage_submitubmit "buttons/submit.png", :class => 'large'
|
74
|
+
def image_submit(source, options={})
|
75
|
+
@template.image_submit_tag source, options
|
76
|
+
end
|
77
|
+
|
73
78
|
protected
|
74
79
|
|
75
80
|
# Returns the known field types for a formbuilder
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class StandardFormBuilder < AbstractFormBuilder
|
2
|
-
|
2
|
+
|
3
3
|
# text_field_block(:username, { :class => 'long' }, { :class => 'wide-label' })
|
4
4
|
# text_area_block(:username, { :class => 'long' }, { :class => 'wide-label' })
|
5
5
|
# password_field_block(:username, { :class => 'long' }, { :class => 'wide-label' })
|
@@ -17,7 +17,13 @@ class StandardFormBuilder < AbstractFormBuilder
|
|
17
17
|
|
18
18
|
# submit_block("Update")
|
19
19
|
def submit_block(caption, options={})
|
20
|
-
submit_html =
|
20
|
+
submit_html = self.submit(caption, options)
|
21
|
+
@template.content_tag(:p, submit_html)
|
22
|
+
end
|
23
|
+
|
24
|
+
# image_submit_block("submit.png")
|
25
|
+
def image_submit_block(source, options={})
|
26
|
+
submit_html = self.image_submit(source, options)
|
21
27
|
@template.content_tag(:p, submit_html)
|
22
28
|
end
|
23
29
|
end
|
@@ -110,6 +110,13 @@ module SinatraMore
|
|
110
110
|
input_tag(:submit, options)
|
111
111
|
end
|
112
112
|
|
113
|
+
# Constructs a submit button from the given options
|
114
|
+
# submit_tag "Create", :class => 'success'
|
115
|
+
def image_submit_tag(source, options={})
|
116
|
+
options.reverse_merge!(:src => image_path(source))
|
117
|
+
input_tag(:image, options)
|
118
|
+
end
|
119
|
+
|
113
120
|
protected
|
114
121
|
|
115
122
|
# returns the hidden method field for 'put' and 'delete' forms
|
data/sinatra_more.gemspec
CHANGED
@@ -30,6 +30,7 @@
|
|
30
30
|
<%= f.check_box :remember_me, :value => '1' %>
|
31
31
|
</p>
|
32
32
|
<p><%= f.submit "Create", :class => 'success', :id => 'demo-button' %></p>
|
33
|
+
<p><%= f.image_submit "buttons/post.png", :class => 'success', :id => 'image-button' %></p>
|
33
34
|
<% end %>
|
34
35
|
|
35
36
|
<% form_for MarkupUser.new, '/another_demo', :id => 'demo2', :method => 'get' do |f| %>
|
@@ -39,5 +40,6 @@
|
|
39
40
|
<%= f.password_field_block :code, { :class => 'input' } %>
|
40
41
|
<%= f.text_area_block :about, { :class => 'textarea' } %>
|
41
42
|
<%= f.file_field_block :photo, { :class => 'upload' } %>
|
42
|
-
<%= f.submit_block "Create", { :class => 'button'
|
43
|
+
<%= f.submit_block "Create", { :class => 'button' } %>
|
44
|
+
<%= f.image_submit_block "buttons/ok.png", { :class => 'image' } %>
|
43
45
|
<% end %>
|
@@ -24,6 +24,8 @@
|
|
24
24
|
= f.check_box :remember_me, :value => "1"
|
25
25
|
%p
|
26
26
|
= f.submit "Create", :class => 'success', :id => 'demo-button'
|
27
|
+
%p
|
28
|
+
= f.image_submit "buttons/post.png", :class => 'success', :id => 'image-button'
|
27
29
|
|
28
30
|
- form_for MarkupUser.new, '/another_demo', :id => 'demo2', :method => 'get' do |f|
|
29
31
|
= f.error_messages :header_message => "custom MarkupUser cannot be saved!"
|
@@ -32,4 +34,5 @@
|
|
32
34
|
= f.password_field_block :code, { :class => 'input' }
|
33
35
|
= f.text_area_block :about, { :class => 'textarea' }
|
34
36
|
= f.file_field_block :photo, { :class => 'upload' }
|
35
|
-
= f.submit_block "Create", { :class => 'button' }
|
37
|
+
= f.submit_block "Create", { :class => 'button' }
|
38
|
+
= f.image_submit_block "buttons/ok.png", { :class => 'image' }
|
data/test/helper.rb
CHANGED
@@ -53,6 +53,9 @@ class TestAssetTagHelpers < Test::Unit::TestCase
|
|
53
53
|
should "display image tag relative link with options" do
|
54
54
|
assert_has_tag('img.photo', :src => "/images/relative/pic.gif") { image_tag('relative/pic.gif', :class => 'photo') }
|
55
55
|
end
|
56
|
+
should "display image tag uri link with options" do
|
57
|
+
assert_has_tag('img.photo', :src => "http://demo.org/pic.gif") { image_tag('http://demo.org/pic.gif', :class => 'photo') }
|
58
|
+
end
|
56
59
|
should "display image tag relative link with incorrect spacing" do
|
57
60
|
assert_has_tag('img.photo', :src => "/images/relative/pic.gif") { image_tag(' relative/ pic.gif ', :class => 'photo') }
|
58
61
|
end
|
@@ -316,6 +316,30 @@ class TestFormBuilder < Test::Unit::TestCase
|
|
316
316
|
end
|
317
317
|
end
|
318
318
|
|
319
|
+
context 'for #image_submit method' do
|
320
|
+
should "display correct image submit button html with no options" do
|
321
|
+
actual_html = standard_builder.image_submit('buttons/ok.png')
|
322
|
+
assert_has_tag('input[type=image]', :src => "/images/buttons/ok.png") { actual_html }
|
323
|
+
end
|
324
|
+
|
325
|
+
should "display correct image submit button html" do
|
326
|
+
actual_html = standard_builder.image_submit('/system/ok.png', :class => 'large')
|
327
|
+
assert_has_tag('input.large[type=image]', :src => "/system/ok.png") { actual_html }
|
328
|
+
end
|
329
|
+
|
330
|
+
should "display correct image submit button in haml" do
|
331
|
+
visit '/haml/form_for'
|
332
|
+
assert_have_selector '#demo input', :type => 'image', :id => 'image-button', :src => '/images/buttons/post.png'
|
333
|
+
assert_have_selector '#demo2 input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png"
|
334
|
+
end
|
335
|
+
|
336
|
+
should "display correct image submit button in erb" do
|
337
|
+
visit '/erb/form_for'
|
338
|
+
assert_have_selector '#demo input', :type => 'image', :id => 'image-button', :src => '/images/buttons/post.png'
|
339
|
+
assert_have_selector '#demo2 input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png"
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
319
343
|
# ===========================
|
320
344
|
# StandardFormBuilder
|
321
345
|
# ===========================
|
@@ -416,4 +440,21 @@ class TestFormBuilder < Test::Unit::TestCase
|
|
416
440
|
assert_have_selector '#demo2 p input', :type => 'submit', :class => 'button'
|
417
441
|
end
|
418
442
|
end
|
443
|
+
|
444
|
+
context 'for #image_submit_block method' do
|
445
|
+
should "display correct image submit block html" do
|
446
|
+
actual_html = standard_builder.image_submit_block("buttons/ok.png", :class => 'large')
|
447
|
+
assert_has_tag('p input.large[type=image]', :src => '/images/buttons/ok.png') { actual_html }
|
448
|
+
end
|
449
|
+
|
450
|
+
should "display correct image submit block in haml" do
|
451
|
+
visit '/haml/form_for'
|
452
|
+
assert_have_selector '#demo2 p input', :type => 'image', :class => 'image', :src => '/images/buttons/ok.png'
|
453
|
+
end
|
454
|
+
|
455
|
+
should "display correct image submit block in erb" do
|
456
|
+
visit '/erb/form_for'
|
457
|
+
assert_have_selector '#demo2 p input', :type => 'image', :class => 'image', :src => '/images/buttons/ok.png'
|
458
|
+
end
|
459
|
+
end
|
419
460
|
end
|
@@ -308,4 +308,26 @@ class TestFormHelpers < Test::Unit::TestCase
|
|
308
308
|
end
|
309
309
|
end
|
310
310
|
|
311
|
+
context 'for #image_submit_tag method' do
|
312
|
+
should "display image submit tag in ruby with relative path" do
|
313
|
+
actual_html = image_submit_tag('buttons/ok.png', :class => 'success')
|
314
|
+
assert_has_tag(:input, :type => 'image', :class => "success", :src => '/images/buttons/ok.png') { actual_html }
|
315
|
+
end
|
316
|
+
|
317
|
+
should "display image submit tag in ruby with absolute path" do
|
318
|
+
actual_html = image_submit_tag('/system/ok.png', :class => 'success')
|
319
|
+
assert_has_tag(:input, :type => 'image', :class => "success", :src => '/system/ok.png') { actual_html }
|
320
|
+
end
|
321
|
+
|
322
|
+
should "display image submit tag in erb" do
|
323
|
+
visit '/erb/form_tag'
|
324
|
+
assert_have_selector 'form.advanced-form input[type=image]', :count => 1, :src => "/images/buttons/submit.png"
|
325
|
+
end
|
326
|
+
|
327
|
+
should "display image submit tag in haml" do
|
328
|
+
visit '/haml/form_tag'
|
329
|
+
assert_have_selector 'form.advanced-form input[type=image]', :count => 1, :src => "/images/buttons/submit.png"
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
311
333
|
end
|