Permalink
Browse files

bump version

  • Loading branch information...
1 parent d59d93b commit 16f0456237d02250786c6e7bb104051d546de72c @kristianmandrup committed Aug 29, 2012
Showing with 63 additions and 3 deletions.
  1. +20 −2 README.md
  2. +1 −1 VERSION
  3. +7 −0 lib/picturefill/view_helper.rb
  4. +35 −0 spec/srcset/view_helper_spec.rb
View
22 README.md
@@ -135,9 +135,27 @@ Use the `srcset` attribute of `<img>` elements. For example:
Include `srcset.min.js` in your page.
-`= img_srcset ...`
+*View helper*
-TODO: Implement the Rails View Helper method!
+* `imgset_tag src, srcset, options = {}` (alias `imageset_tag`)
+
+```haml
+= imgset_tag "banner.jpeg", "banner-HD.jpeg 2x, banner-phone.jpeg 100w,banner-phone-HD.jpeg 100w 2x", alt: "The Breakfast Combo"
+```
+
+outputs the HTML code shown above.
+
+If you leave out the srcset argument it will fallback to a single src image
+
+```haml
+= imgset_tag "banner.jpeg", alt: "The Breakfast Combo"
+```
+
+Same as
+
+```haml
+= image_tag "banner.jpeg", alt: "The Breakfast Combo"
+```
### Assets
View
2 VERSION
@@ -1 +1 @@
-0.2.0
+0.2.1
View
7 lib/picturefill/view_helper.rb
@@ -1,5 +1,12 @@
module Picturefill
module ViewHelper
+ def imgset_tag src, srcset = nil, options = {}
+ options.merge!(:src => src)
+ options.merge!(:srcset => srcset) if srcset
+ content_tag :img, nil, options
+ end
+ alias_method :imageset_tag, :imgset_tag
+
def picture_tag alt = nil
options = {}
options.merge alt: alt if alt
View
35 spec/srcset/view_helper_spec.rb
@@ -0,0 +1,35 @@
+require 'spec_helper'
+
+describe Picturefill::ViewHelper do
+ include ControllerTestHelpers,
+ Picturefill::ViewHelper
+
+ describe '#imgset_tag' do
+ context 'no arguments' do
+ specify do
+ expect { imgset_tag }.to raise_error
+ end
+ end
+
+ context 'one argument' do
+ specify do
+ output = imgset_tag('hello.jpg')
+ output.should == "<img src=\"hello.jpg\"></img>"
+ end
+ end
+
+ context 'alt option' do
+ it "should add the data-alt atribute" do
+ output = imgset_tag "banner.jpeg", "banner-HD.jpeg 2x, banner-phone.jpeg 100w,banner-phone-HD.jpeg 100w 2x"
+ output.should == "<img src=\"banner.jpeg\" srcset=\"banner-HD.jpeg 2x, banner-phone.jpeg 100w,banner-phone-HD.jpeg 100w 2x\"></img>"
+ end
+ end
+
+ context 'alt option and block' do
+ it "should add a piture src" do
+ output = imgset_tag "banner.jpeg", "banner-HD.jpeg 2x, banner-phone.jpeg 100w,banner-phone-HD.jpeg 100w 2x", alt: "The Breakfast Combo"
+ output.should == "<img alt=\"The Breakfast Combo\" src=\"banner.jpeg\" srcset=\"banner-HD.jpeg 2x, banner-phone.jpeg 100w,banner-phone-HD.jpeg 100w 2x\"></img>"
+ end
+ end
+ end
+end

0 comments on commit 16f0456

Please sign in to comment.