picture_tag-rails 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +2 -2
- data/README.md +23 -13
- data/lib/picture_tag-rails.rb +19 -0
- data/lib/picture_tag-rails/configuration.rb +12 -0
- data/lib/picture_tag-rails/version.rb +1 -1
- data/lib/picture_tag-rails/view_helpers.rb +13 -7
- data/picture_tag-rails.gemspec +2 -2
- data/spec/lib/view_helpers_spec.rb +54 -27
- metadata +16 -19
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a5f03793d175d320b870bd6b3e89662056c14665
|
4
|
+
data.tar.gz: 68b1d6b25e2fbc38312a2f15fd285ace513942e3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 756535f2cfd4e4569e4cda5db5e3324b6d4bb7fef8cc6ad0ed719a77e6bcf340541b2abc3be637ed79924eda103bd9e7c522c9eec9128dc0bbafec28db9003b8
|
7
|
+
data.tar.gz: d1378e2855858938f68959a52103c57a490603ab2906ddd6688c94ce158f118651a1711a5fa639e8704e51fd780d603cc80ddf78d55de5a26ab425fff9f58222
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -4,18 +4,18 @@
|
|
4
4
|
|
5
5
|
A Rails view helper extension to generate HTML5 `<picture>` tag markup
|
6
6
|
from the W3C HTML Responsive Images Extension Proposal.
|
7
|
-
|
7
|
+
|
8
8
|
[w3.org/community/respimg](http://www.w3.org/community/respimg)
|
9
9
|
|
10
10
|
|
11
11
|
## Current Version
|
12
12
|
|
13
|
-
0.0.
|
13
|
+
0.0.6
|
14
14
|
|
15
15
|
|
16
16
|
## Requirements
|
17
17
|
|
18
|
-
* [Ruby on Rails](http://rubyonrails.org) > 3.0
|
18
|
+
* [Ruby on Rails](http://rubyonrails.org) > 3.0 and < 4.0
|
19
19
|
|
20
20
|
|
21
21
|
|
@@ -107,25 +107,34 @@ Paperclip options for default media queries and sizes.
|
|
107
107
|
|
108
108
|
```ruby
|
109
109
|
has_attached_file :image, {
|
110
|
-
styles: {
|
111
|
-
tiny: "320x",
|
112
|
-
small: "480x",
|
113
|
-
medium: "768x",
|
114
|
-
large: "1000x",
|
110
|
+
styles: {
|
111
|
+
tiny: "320x",
|
112
|
+
small: "480x",
|
113
|
+
medium: "768x",
|
114
|
+
large: "1000x",
|
115
115
|
huge: "1600x",
|
116
|
-
%s(tiny@2x) => "640x",
|
117
|
-
%s(small@2x) => "960x",
|
118
|
-
%s(medium@2x) => "1536x",
|
119
|
-
%s(large@2x) => "2000x",
|
116
|
+
%s(tiny@2x) => "640x",
|
117
|
+
%s(small@2x) => "960x",
|
118
|
+
%s(medium@2x) => "1536x",
|
119
|
+
%s(large@2x) => "2000x",
|
120
120
|
%s(large@2x) => "3200x"
|
121
121
|
}
|
122
122
|
```
|
123
123
|
|
124
|
+
## Configuration
|
125
|
+
- Retina support can be disabled by adding a configure block to your config
|
126
|
+
```ruby
|
127
|
+
PictureTag.configure do |config|
|
128
|
+
config.display_high_def = false
|
129
|
+
end
|
130
|
+
```
|
131
|
+
|
124
132
|
|
125
133
|
## TODO
|
126
134
|
|
127
135
|
- Add optional paperclip integration functionality
|
128
|
-
-
|
136
|
+
- Intergrate with Travis.ci
|
137
|
+
- Implement Rails 4 support
|
129
138
|
|
130
139
|
|
131
140
|
## Authors
|
@@ -134,6 +143,7 @@ has_attached_file :image, {
|
|
134
143
|
* Chad Crissman / [@crissmancd](https://github.com/crissmancd)
|
135
144
|
* John Lucia / [@johnlucia](https://github.com/johnlucia)
|
136
145
|
* Levi Brown / [@levibrown](https://github.com/levibrown)
|
146
|
+
* Colton Fent / [@colto](https://github.com/colto)
|
137
147
|
|
138
148
|
|
139
149
|
## Contributions
|
data/lib/picture_tag-rails.rb
CHANGED
@@ -1,2 +1,21 @@
|
|
1
1
|
require "picture_tag-rails/version"
|
2
2
|
require 'picture_tag-rails/railtie'
|
3
|
+
|
4
|
+
require_relative "./picture_tag-rails/configuration"
|
5
|
+
|
6
|
+
module PictureTag
|
7
|
+
|
8
|
+
class << self
|
9
|
+
attr_accessor :configuration
|
10
|
+
|
11
|
+
def configuration
|
12
|
+
@configuration ||= Configuration.new
|
13
|
+
end
|
14
|
+
|
15
|
+
# Pattern inspired by http://robots.thoughtbot.com/mygem-configure-block/
|
16
|
+
def configure
|
17
|
+
#self.configuration ||= Configuration.new
|
18
|
+
yield(configuration)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,6 +1,11 @@
|
|
1
1
|
module PictureTag
|
2
|
+
|
2
3
|
module ViewHelpers
|
3
4
|
|
5
|
+
def display_high_def
|
6
|
+
PictureTag.configuration.display_high_def
|
7
|
+
end
|
8
|
+
|
4
9
|
def picture_tag(image_path, options={})
|
5
10
|
sizes = determine_sizes(options)
|
6
11
|
|
@@ -11,7 +16,7 @@ module PictureTag
|
|
11
16
|
html << add_default_source_and_image(image_path, sizes.last.first, options)
|
12
17
|
html << "</picture>"
|
13
18
|
|
14
|
-
html
|
19
|
+
raw html
|
15
20
|
end
|
16
21
|
|
17
22
|
def build_file_path(image_path, size, prefix_size=false, options={})
|
@@ -30,13 +35,14 @@ module PictureTag
|
|
30
35
|
|
31
36
|
def build_source_tag(image_path, size, media_query=nil, options={})
|
32
37
|
file = build_file_path(image_path, size, options[:prefix_size])
|
33
|
-
file2x = build_file_path(image_path, "#{size}@2x", options[:prefix_size])
|
34
|
-
srcset = image_path(file) + " 1x
|
35
|
-
srcset
|
38
|
+
file2x = build_file_path(image_path, "#{size}@2x", options[:prefix_size]) if display_high_def
|
39
|
+
srcset = image_path(file) + " 1x"
|
40
|
+
srcset = image_path(file) + " 1x, " if display_high_def
|
41
|
+
srcset << image_path(file2x) + " 2x" if display_high_def
|
36
42
|
srcset = options[:default_image] if options[:default_image].eql?(image_path)
|
37
43
|
"<source #{"media='#{media_query}' " if media_query}srcset='#{srcset}' />"
|
38
44
|
end
|
39
|
-
|
45
|
+
|
40
46
|
def add_default_source_and_image(image_path, size, options)
|
41
47
|
prefix_size = options[:prefix_size]
|
42
48
|
if options[:default_image]
|
@@ -47,7 +53,7 @@ module PictureTag
|
|
47
53
|
options[:prefix_size] = false
|
48
54
|
size = options[:default_size]
|
49
55
|
end
|
50
|
-
|
56
|
+
|
51
57
|
img_src = build_file_path(image_path, size, prefix_size, options)
|
52
58
|
html = build_source_tag(image_path, size, nil, options)
|
53
59
|
html << image_tag(img_src, normalize_options(options, image_path))
|
@@ -92,4 +98,4 @@ module PictureTag
|
|
92
98
|
end
|
93
99
|
|
94
100
|
end
|
95
|
-
end
|
101
|
+
end
|
data/picture_tag-rails.gemspec
CHANGED
@@ -16,6 +16,6 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
|
-
|
20
|
-
gem.add_dependency 'rails', '>= 3.0'
|
19
|
+
|
20
|
+
gem.add_dependency 'rails', '>= 3.0', '<4.0.0'
|
21
21
|
end
|
@@ -1,75 +1,102 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
describe PictureTag::ViewHelpers, :type => :helper do
|
3
|
-
|
3
|
+
|
4
|
+
describe "display_high_def" do
|
5
|
+
it "defaults to true" do
|
6
|
+
PictureTag.configuration.display_high_def.should be_true
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
4
10
|
describe "split image path" do
|
5
11
|
let(:split_image_path) { helper.split_image_path_from_extension("/path/something.s-original.jpg") }
|
6
12
|
it "removes the -original" do
|
7
13
|
split_image_path.first.should eq "/path/something.s"
|
8
14
|
end
|
9
|
-
|
15
|
+
|
10
16
|
it "splits jpg" do
|
11
17
|
split_image_path.last.should eq "jpg"
|
12
18
|
end
|
13
|
-
|
19
|
+
|
14
20
|
end
|
15
|
-
|
21
|
+
|
16
22
|
describe "building the source tag" do
|
17
|
-
|
23
|
+
|
18
24
|
it "builds using a media query" do
|
19
25
|
helper.build_source_tag('test.jpg', 'small', "(min-width: 100px)").
|
20
26
|
should eq "<source media='(min-width: 100px)' srcset='/images/test-small.jpg 1x, /images/test-small@2x.jpg 2x' />"
|
21
27
|
end
|
22
|
-
|
28
|
+
|
23
29
|
it "builds without a media query" do
|
24
30
|
helper.build_source_tag('/path/test.png', 'small').
|
25
31
|
should eq "<source srcset='/path/test-small.png 1x, /path/test-small@2x.png 2x' />"
|
26
32
|
end
|
27
|
-
|
33
|
+
|
34
|
+
context "when display_high_def is set to false" do
|
35
|
+
|
36
|
+
before do
|
37
|
+
PictureTag.configure do |config|
|
38
|
+
config.display_high_def = false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
after do
|
43
|
+
PictureTag.configure do |config|
|
44
|
+
config.display_high_def = true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
it "builds the source tag" do
|
50
|
+
helper.build_source_tag('/path/test.png', 'small').
|
51
|
+
should eq "<source srcset='/path/test-small.png 1x' />"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
28
55
|
it "builds without an external path" do
|
29
56
|
helper.build_source_tag('http://www.image/path/test.png', 'small',"(min-width: 100px)").
|
30
57
|
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
58
|
end
|
32
|
-
|
59
|
+
|
33
60
|
it "builds given a default image" do
|
34
61
|
helper.build_source_tag('/images/test.png', 'small', nil, {:default_image => '/images/test.png'}).
|
35
62
|
should eq "<source srcset='/images/test.png' />"
|
36
63
|
end
|
37
|
-
|
64
|
+
|
38
65
|
end
|
39
|
-
|
66
|
+
|
40
67
|
describe "default source and image" do
|
41
68
|
it "builds source and img" do
|
42
69
|
helper.add_default_source_and_image('test.jpg', 'small', {}).
|
43
70
|
should eq "<source srcset='/images/test-small.jpg 1x, /images/test-small@2x.jpg 2x' /><img alt=\"Test\" src=\"/images/test-small.jpg\" />"
|
44
71
|
end
|
45
|
-
|
72
|
+
|
46
73
|
it "lets you specify a default image size" do
|
47
74
|
helper.add_default_source_and_image('test.jpg', 'any_size', {:default_size => :large}).
|
48
75
|
should eq "<source srcset='/images/test-large.jpg 1x, /images/test-large@2x.jpg 2x' /><img alt=\"Test\" src=\"/images/test-large.jpg\" />"
|
49
76
|
end
|
50
|
-
|
77
|
+
|
51
78
|
it "lets you specify a default image path" do
|
52
79
|
helper.add_default_source_and_image('test.jpg', 'large', {:default_image => '/images/test.png'}).
|
53
80
|
should eq "<source srcset='/images/test.png' /><img alt=\"Test\" src=\"/images/test.png\" />"
|
54
81
|
end
|
55
|
-
|
82
|
+
|
56
83
|
it "adds a class to the img tag" do
|
57
84
|
helper.add_default_source_and_image('test.jpg', 'small', {:class => "span2"}).
|
58
85
|
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\" />"
|
59
86
|
end
|
60
|
-
|
87
|
+
|
61
88
|
end
|
62
|
-
|
89
|
+
|
63
90
|
describe "determine sizes" do
|
64
91
|
let(:sizes) { {:huge => "(min-width: 1600px)", :small => "(min-width: 500px)"} }
|
65
92
|
it "puts the hash into a sorted array" do
|
66
93
|
helper.determine_sizes(:sizes => sizes).should eq [[:huge, "(min-width: 1600px)"], [:small, "(min-width: 500px)"]]
|
67
94
|
end
|
68
|
-
|
95
|
+
|
69
96
|
it "excludes sizes larger than tha max_width" do
|
70
97
|
helper.determine_sizes(:sizes => sizes, :max_width => "501px" ).should eq [[:small, "(min-width: 500px)"]]
|
71
98
|
end
|
72
|
-
|
99
|
+
|
73
100
|
it "keeps with an equal max width" do
|
74
101
|
helper.determine_sizes(:sizes => sizes, :max_width => "500px" ).should eq [[:small, "(min-width: 500px)"]]
|
75
102
|
end
|
@@ -77,9 +104,9 @@ describe PictureTag::ViewHelpers, :type => :helper do
|
|
77
104
|
it "removes with a lesser max width" do
|
78
105
|
helper.determine_sizes(:sizes => sizes, :max_width => "499px" ).should eq []
|
79
106
|
end
|
80
|
-
|
107
|
+
|
81
108
|
end
|
82
|
-
|
109
|
+
|
83
110
|
describe "options" do
|
84
111
|
def html
|
85
112
|
"<picture>" +
|
@@ -95,11 +122,11 @@ describe PictureTag::ViewHelpers, :type => :helper do
|
|
95
122
|
|
96
123
|
|
97
124
|
it "matches the complete html" do
|
98
|
-
helper.picture_tag('/images/cat.jpg').should eq html
|
125
|
+
helper.picture_tag('/images/cat.jpg').should eq html
|
99
126
|
end
|
100
127
|
|
101
128
|
it "matches the complete html with an alt tag" do
|
102
|
-
helper.picture_tag('/images/cat.jpg', :alt => "Kitty!").should eq html.gsub("Cat", "Kitty!")
|
129
|
+
helper.picture_tag('/images/cat.jpg', :alt => "Kitty!").should eq html.gsub("Cat", "Kitty!")
|
103
130
|
end
|
104
131
|
|
105
132
|
it "prefixes the size to the filename" do
|
@@ -117,11 +144,11 @@ describe PictureTag::ViewHelpers, :type => :helper do
|
|
117
144
|
helper.picture_tag('/images/cat.jpg', :sizes => {:hidden => "(min-width: 1px)"}).
|
118
145
|
should eq h
|
119
146
|
end
|
120
|
-
|
147
|
+
|
121
148
|
it "excludes source tags with a media query above the given amount" do
|
122
149
|
helper.picture_tag("cat.jpg", :max_width => "500").split('source').should have(4).things
|
123
150
|
end
|
124
|
-
|
151
|
+
|
125
152
|
describe "prefixes the size to the filename" do
|
126
153
|
it "without x" do
|
127
154
|
helper.build_file_path('/path/test.png', 'small', true).
|
@@ -137,13 +164,13 @@ describe PictureTag::ViewHelpers, :type => :helper do
|
|
137
164
|
helper.build_file_path('path/test.png', 'small@2x', true).
|
138
165
|
should eq "path/small@2x-test.png"
|
139
166
|
end
|
140
|
-
|
167
|
+
|
141
168
|
it "without a path" do
|
142
169
|
helper.build_file_path('test.png', 'small@2x', true).
|
143
170
|
should eq "small@2x-test.png"
|
144
171
|
end
|
145
|
-
|
172
|
+
|
146
173
|
end
|
147
174
|
end
|
148
|
-
|
149
|
-
end
|
175
|
+
|
176
|
+
end
|
metadata
CHANGED
@@ -1,32 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: picture_tag-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.6
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Bookis Smuin
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-01-21 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rails
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '3.0'
|
20
|
+
- - <
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 4.0.0
|
22
23
|
type: :runtime
|
23
24
|
prerelease: false
|
24
25
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '3.0'
|
30
|
+
- - <
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 4.0.0
|
30
33
|
description: Rails View Helper picture_tag extension
|
31
34
|
email:
|
32
35
|
- vegan.bookis@gmail.com
|
@@ -42,6 +45,7 @@ files:
|
|
42
45
|
- README.md
|
43
46
|
- Rakefile
|
44
47
|
- lib/picture_tag-rails.rb
|
48
|
+
- lib/picture_tag-rails/configuration.rb
|
45
49
|
- lib/picture_tag-rails/railtie.rb
|
46
50
|
- lib/picture_tag-rails/version.rb
|
47
51
|
- lib/picture_tag-rails/view_helpers.rb
|
@@ -50,33 +54,26 @@ files:
|
|
50
54
|
- spec/spec_helper.rb
|
51
55
|
homepage: ''
|
52
56
|
licenses: []
|
57
|
+
metadata: {}
|
53
58
|
post_install_message:
|
54
59
|
rdoc_options: []
|
55
60
|
require_paths:
|
56
61
|
- lib
|
57
62
|
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
63
|
requirements:
|
60
|
-
- -
|
64
|
+
- - '>='
|
61
65
|
- !ruby/object:Gem::Version
|
62
66
|
version: '0'
|
63
|
-
segments:
|
64
|
-
- 0
|
65
|
-
hash: -2348883054798486407
|
66
67
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
-
none: false
|
68
68
|
requirements:
|
69
|
-
- -
|
69
|
+
- - '>='
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: '0'
|
72
|
-
segments:
|
73
|
-
- 0
|
74
|
-
hash: -2348883054798486407
|
75
72
|
requirements: []
|
76
73
|
rubyforge_project:
|
77
|
-
rubygems_version:
|
74
|
+
rubygems_version: 2.4.3
|
78
75
|
signing_key:
|
79
|
-
specification_version:
|
76
|
+
specification_version: 4
|
80
77
|
summary: A Rails view helper extension to generate the proposed HTML5 picture tag
|
81
78
|
markup.
|
82
79
|
test_files:
|