picture_tag-rails 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +5 -0
- data/README.md +14 -3
- data/lib/picture_tag-rails/version.rb +1 -1
- data/lib/picture_tag-rails/view_helpers.rb +21 -5
- data/spec/lib/view_helpers_spec.rb +16 -0
- metadata +42 -51
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
# Picture-Tag Rails
|
2
|
+
[![Build Status](https://travis-ci.org/G5/picture_tag-rails.png?branch=master)](https://travis-ci.org/G5/picture_tag-rails)
|
3
|
+
[![Code Climate](https://codeclimate.com/github/G5/picture_tag-rails.png)](https://codeclimate.com/github/G5/picture_tag-rails)
|
2
4
|
|
3
5
|
A Rails view helper extension to generate HTML5 `<picture>` tag markup
|
4
6
|
from the W3C HTML Responsive Images Extension Proposal.
|
@@ -8,7 +10,7 @@ from the W3C HTML Responsive Images Extension Proposal.
|
|
8
10
|
|
9
11
|
## Current Version
|
10
12
|
|
11
|
-
0.0.
|
13
|
+
0.0.5
|
12
14
|
|
13
15
|
|
14
16
|
## Requirements
|
@@ -85,9 +87,16 @@ To override the default media queries and names:
|
|
85
87
|
To prefix (opposed to suffix) the filename with size ('/images/small-kitty.jpg'):
|
86
88
|
|
87
89
|
```erb
|
88
|
-
<%= picture_tag(image_path,
|
90
|
+
<%= picture_tag(image_path, prefix_size: true}) %>
|
89
91
|
```
|
90
92
|
|
93
|
+
To preload a custom default placeholder image:
|
94
|
+
|
95
|
+
```erb
|
96
|
+
<%= picture_tag(image_path, default_image: '/images/placeholder.png'}) %>
|
97
|
+
```
|
98
|
+
|
99
|
+
|
91
100
|
All `image_tag` options are valid for `picture_tag`.
|
92
101
|
See [image_tag Docs](http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html)
|
93
102
|
|
@@ -123,6 +132,8 @@ has_attached_file :image, {
|
|
123
132
|
|
124
133
|
* Bookis Smuin / [@bookis](https://github.com/bookis)
|
125
134
|
* Chad Crissman / [@crissmancd](https://github.com/crissmancd)
|
135
|
+
* John Lucia / [@johnlucia](https://github.com/johnlucia)
|
136
|
+
* Levi Brown / [@levibrown](https://github.com/levibrown)
|
126
137
|
|
127
138
|
|
128
139
|
## Contributions
|
@@ -174,4 +185,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
174
185
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
175
186
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
176
187
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
177
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
188
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -14,12 +14,15 @@ module PictureTag
|
|
14
14
|
html
|
15
15
|
end
|
16
16
|
|
17
|
-
def build_file_path(image_path, size, prefix_size=false)
|
17
|
+
def build_file_path(image_path, size, prefix_size=false, options={})
|
18
18
|
filename, extension = split_image_path_from_extension(image_path)
|
19
19
|
if prefix_size
|
20
20
|
# Splits on last '/' before the first whitespace.
|
21
21
|
path, file = filename.split(/\/(?=[^\/]+(?: |$))| /)
|
22
22
|
file ? "#{path}/#{size}-#{file}.#{extension}" : "#{size}-#{path}.#{extension}"
|
23
|
+
elsif options[:default_image]
|
24
|
+
#binding.pry
|
25
|
+
image_path
|
23
26
|
else
|
24
27
|
"#{filename}-#{size}.#{extension}"
|
25
28
|
end
|
@@ -30,11 +33,22 @@ module PictureTag
|
|
30
33
|
file2x = build_file_path(image_path, "#{size}@2x", options[:prefix_size])
|
31
34
|
srcset = image_path(file) + " 1x, "
|
32
35
|
srcset << image_path(file2x) + " 2x"
|
36
|
+
srcset = options[:default_image] if options[:default_image].eql?(image_path)
|
33
37
|
"<source #{"media='#{media_query}' " if media_query}srcset='#{srcset}' />"
|
34
38
|
end
|
35
|
-
|
39
|
+
|
36
40
|
def add_default_source_and_image(image_path, size, options)
|
37
|
-
|
41
|
+
prefix_size = options[:prefix_size]
|
42
|
+
if options[:default_image]
|
43
|
+
prefix_size = false
|
44
|
+
image_path = options[:default_image]
|
45
|
+
size = nil
|
46
|
+
elsif options[:default_size]
|
47
|
+
options[:prefix_size] = false
|
48
|
+
size = options[:default_size]
|
49
|
+
end
|
50
|
+
|
51
|
+
img_src = build_file_path(image_path, size, prefix_size, options)
|
38
52
|
html = build_source_tag(image_path, size, nil, options)
|
39
53
|
html << image_tag(img_src, normalize_options(options, image_path))
|
40
54
|
html
|
@@ -42,8 +56,10 @@ module PictureTag
|
|
42
56
|
|
43
57
|
def normalize_options(options, image_path)
|
44
58
|
options[:alt] ||= alt_tag(image_path)
|
45
|
-
options[:prefix_size]
|
46
|
-
options[:max_width]
|
59
|
+
options[:prefix_size] = nil
|
60
|
+
options[:max_width] = nil
|
61
|
+
options[:default_size] = nil
|
62
|
+
options[:default_image] = nil
|
47
63
|
options
|
48
64
|
end
|
49
65
|
|
@@ -29,6 +29,12 @@ describe PictureTag::ViewHelpers, :type => :helper do
|
|
29
29
|
helper.build_source_tag('http://www.image/path/test.png', 'small',"(min-width: 100px)").
|
30
30
|
should eq "<source media='(min-width: 100px)' srcset='http://www.image/path/test-small.png 1x, http://www.image/path/test-small@2x.png 2x' />"
|
31
31
|
end
|
32
|
+
|
33
|
+
it "builds given a default image" do
|
34
|
+
helper.build_source_tag('/images/test.png', 'small', nil, {:default_image => '/images/test.png'}).
|
35
|
+
should eq "<source srcset='/images/test.png' />"
|
36
|
+
end
|
37
|
+
|
32
38
|
end
|
33
39
|
|
34
40
|
describe "default source and image" do
|
@@ -37,6 +43,16 @@ describe PictureTag::ViewHelpers, :type => :helper do
|
|
37
43
|
should eq "<source srcset='/images/test-small.jpg 1x, /images/test-small@2x.jpg 2x' /><img alt=\"Test\" src=\"/images/test-small.jpg\" />"
|
38
44
|
end
|
39
45
|
|
46
|
+
it "lets you specify a default image size" do
|
47
|
+
helper.add_default_source_and_image('test.jpg', 'any_size', {:default_size => :large}).
|
48
|
+
should eq "<source srcset='/images/test-large.jpg 1x, /images/test-large@2x.jpg 2x' /><img alt=\"Test\" src=\"/images/test-large.jpg\" />"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "lets you specify a default image path" do
|
52
|
+
helper.add_default_source_and_image('test.jpg', 'large', {:default_image => '/images/test.png'}).
|
53
|
+
should eq "<source srcset='/images/test.png' /><img alt=\"Test\" src=\"/images/test.png\" />"
|
54
|
+
end
|
55
|
+
|
40
56
|
it "adds a class to the img tag" do
|
41
57
|
helper.add_default_source_and_image('test.jpg', 'small', {:class => "span2"}).
|
42
58
|
should eq "<source srcset='/images/test-small.jpg 1x, /images/test-small@2x.jpg 2x' /><img alt=\"Test\" class=\"span2\" src=\"/images/test-small.jpg\" />"
|
metadata
CHANGED
@@ -1,48 +1,41 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: picture_tag-rails
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 4
|
10
|
-
version: 0.0.4
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Bookis Smuin
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
date: 2013-04-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
22
17
|
none: false
|
23
|
-
requirements:
|
24
|
-
- -
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
|
27
|
-
segments:
|
28
|
-
- 3
|
29
|
-
- 0
|
30
|
-
version: "3.0"
|
31
|
-
prerelease: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
32
22
|
type: :runtime
|
33
|
-
|
34
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
35
30
|
description: Rails View Helper picture_tag extension
|
36
|
-
email:
|
31
|
+
email:
|
37
32
|
- vegan.bookis@gmail.com
|
38
33
|
executables: []
|
39
|
-
|
40
34
|
extensions: []
|
41
|
-
|
42
35
|
extra_rdoc_files: []
|
43
|
-
|
44
|
-
files:
|
36
|
+
files:
|
45
37
|
- .gitignore
|
38
|
+
- .travis.yml
|
46
39
|
- Gemfile
|
47
40
|
- Guardfile
|
48
41
|
- LICENSE.txt
|
@@ -55,39 +48,37 @@ files:
|
|
55
48
|
- picture_tag-rails.gemspec
|
56
49
|
- spec/lib/view_helpers_spec.rb
|
57
50
|
- spec/spec_helper.rb
|
58
|
-
homepage:
|
51
|
+
homepage: ''
|
59
52
|
licenses: []
|
60
|
-
|
61
53
|
post_install_message:
|
62
54
|
rdoc_options: []
|
63
|
-
|
64
|
-
require_paths:
|
55
|
+
require_paths:
|
65
56
|
- lib
|
66
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
58
|
none: false
|
68
|
-
requirements:
|
69
|
-
- -
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
|
72
|
-
segments:
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
segments:
|
73
64
|
- 0
|
74
|
-
|
75
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
hash: -2348883054798486407
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
67
|
none: false
|
77
|
-
requirements:
|
78
|
-
- -
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
|
81
|
-
segments:
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
segments:
|
82
73
|
- 0
|
83
|
-
|
74
|
+
hash: -2348883054798486407
|
84
75
|
requirements: []
|
85
|
-
|
86
76
|
rubyforge_project:
|
87
77
|
rubygems_version: 1.8.24
|
88
78
|
signing_key:
|
89
79
|
specification_version: 3
|
90
|
-
summary: A Rails view helper extension to generate the proposed HTML5 picture tag
|
91
|
-
|
80
|
+
summary: A Rails view helper extension to generate the proposed HTML5 picture tag
|
81
|
+
markup.
|
82
|
+
test_files:
|
92
83
|
- spec/lib/view_helpers_spec.rb
|
93
84
|
- spec/spec_helper.rb
|