picturefill-rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +109 -0
- data/LICENSE.txt +20 -0
- data/README.md +79 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/lib/picturefill-rails.rb +3 -0
- data/lib/picturefill/engine.rb +9 -0
- data/lib/picturefill/view_helper.rb +103 -0
- data/picturefill-rails.gemspec +68 -0
- data/spec/picturefill/view_helper_spec.rb +70 -0
- data/spec/spec_helper.rb +46 -0
- metadata +160 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
actionmailer (3.2.8)
|
5
|
+
actionpack (= 3.2.8)
|
6
|
+
mail (~> 2.4.4)
|
7
|
+
actionpack (3.2.8)
|
8
|
+
activemodel (= 3.2.8)
|
9
|
+
activesupport (= 3.2.8)
|
10
|
+
builder (~> 3.0.0)
|
11
|
+
erubis (~> 2.7.0)
|
12
|
+
journey (~> 1.0.4)
|
13
|
+
rack (~> 1.4.0)
|
14
|
+
rack-cache (~> 1.2)
|
15
|
+
rack-test (~> 0.6.1)
|
16
|
+
sprockets (~> 2.1.3)
|
17
|
+
activemodel (3.2.8)
|
18
|
+
activesupport (= 3.2.8)
|
19
|
+
builder (~> 3.0.0)
|
20
|
+
activerecord (3.2.8)
|
21
|
+
activemodel (= 3.2.8)
|
22
|
+
activesupport (= 3.2.8)
|
23
|
+
arel (~> 3.0.2)
|
24
|
+
tzinfo (~> 0.3.29)
|
25
|
+
activeresource (3.2.8)
|
26
|
+
activemodel (= 3.2.8)
|
27
|
+
activesupport (= 3.2.8)
|
28
|
+
activesupport (3.2.8)
|
29
|
+
i18n (~> 0.6)
|
30
|
+
multi_json (~> 1.0)
|
31
|
+
arel (3.0.2)
|
32
|
+
builder (3.0.0)
|
33
|
+
diff-lcs (1.1.3)
|
34
|
+
erubis (2.7.0)
|
35
|
+
git (1.2.5)
|
36
|
+
hike (1.2.1)
|
37
|
+
i18n (0.6.0)
|
38
|
+
jeweler (1.8.4)
|
39
|
+
bundler (~> 1.0)
|
40
|
+
git (>= 1.2.5)
|
41
|
+
rake
|
42
|
+
rdoc
|
43
|
+
journey (1.0.4)
|
44
|
+
json (1.7.4)
|
45
|
+
mail (2.4.4)
|
46
|
+
i18n (>= 0.4.0)
|
47
|
+
mime-types (~> 1.16)
|
48
|
+
treetop (~> 1.4.8)
|
49
|
+
mime-types (1.19)
|
50
|
+
multi_json (1.3.6)
|
51
|
+
polyglot (0.3.3)
|
52
|
+
rack (1.4.1)
|
53
|
+
rack-cache (1.2)
|
54
|
+
rack (>= 0.4)
|
55
|
+
rack-ssl (1.3.2)
|
56
|
+
rack
|
57
|
+
rack-test (0.6.1)
|
58
|
+
rack (>= 1.0)
|
59
|
+
rails (3.2.8)
|
60
|
+
actionmailer (= 3.2.8)
|
61
|
+
actionpack (= 3.2.8)
|
62
|
+
activerecord (= 3.2.8)
|
63
|
+
activeresource (= 3.2.8)
|
64
|
+
activesupport (= 3.2.8)
|
65
|
+
bundler (~> 1.0)
|
66
|
+
railties (= 3.2.8)
|
67
|
+
railties (3.2.8)
|
68
|
+
actionpack (= 3.2.8)
|
69
|
+
activesupport (= 3.2.8)
|
70
|
+
rack-ssl (~> 1.3.2)
|
71
|
+
rake (>= 0.8.7)
|
72
|
+
rdoc (~> 3.4)
|
73
|
+
thor (>= 0.14.6, < 2.0)
|
74
|
+
rake (0.9.2.2)
|
75
|
+
rdoc (3.12)
|
76
|
+
json (~> 1.4)
|
77
|
+
rspec (2.11.0)
|
78
|
+
rspec-core (~> 2.11.0)
|
79
|
+
rspec-expectations (~> 2.11.0)
|
80
|
+
rspec-mocks (~> 2.11.0)
|
81
|
+
rspec-core (2.11.1)
|
82
|
+
rspec-expectations (2.11.2)
|
83
|
+
diff-lcs (~> 1.1.3)
|
84
|
+
rspec-mocks (2.11.2)
|
85
|
+
simplecov (0.6.4)
|
86
|
+
multi_json (~> 1.0)
|
87
|
+
simplecov-html (~> 0.5.3)
|
88
|
+
simplecov-html (0.5.3)
|
89
|
+
sprockets (2.1.3)
|
90
|
+
hike (~> 1.2)
|
91
|
+
rack (~> 1.0)
|
92
|
+
tilt (~> 1.1, != 1.3.0)
|
93
|
+
thor (0.16.0)
|
94
|
+
tilt (1.3.3)
|
95
|
+
treetop (1.4.10)
|
96
|
+
polyglot
|
97
|
+
polyglot (>= 0.3.1)
|
98
|
+
tzinfo (0.3.33)
|
99
|
+
|
100
|
+
PLATFORMS
|
101
|
+
ruby
|
102
|
+
|
103
|
+
DEPENDENCIES
|
104
|
+
bundler (>= 1.0.0)
|
105
|
+
jeweler (~> 1.8.4)
|
106
|
+
rails (>= 3.0.0)
|
107
|
+
rdoc (>= 3.12)
|
108
|
+
rspec (>= 2.8.0)
|
109
|
+
simplecov (>= 0.5)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Kristian Mandrup
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# Picturefill View helpers for Rails
|
2
|
+
|
3
|
+
[picturefill](https://github.com/scottjehl/picturefill) is currently the best way for rendering [Responsive Images](http://5by5.tv/webahead/25) on a web page.
|
4
|
+
|
5
|
+
*picturefill-rails* provides nice view helper methods to render the picturefill.
|
6
|
+
|
7
|
+
```html
|
8
|
+
<div data-picture data-alt="A giant stone face at The Bayon temple in Angkor Thom, Cambodia">
|
9
|
+
<div data-src="small.jpg"></div>
|
10
|
+
<div data-src="small.jpg" data-media="(min-device-pixel-ratio: 2.0)"></div>
|
11
|
+
<div data-src="medium.jpg" data-media="(min-width: 400px)"></div>
|
12
|
+
<div data-src="medium_x2.jpg" data-media="(min-width: 400px) and (min-device-pixel-ratio: 2.0)"></div>
|
13
|
+
<div data-src="large.jpg" data-media="(min-width: 800px)"></div>
|
14
|
+
<div data-src="large_x2.jpg" data-media="(min-width: 800px) and (min-device-pixel-ratio: 2.0)"></div>
|
15
|
+
<div data-src="extralarge.jpg" data-media="(min-width: 1000px)"></div>
|
16
|
+
<div data-src="extralarge_x2.jpg" data-media="(min-width: 1000px) and (min-device-pixel-ratio: 2.0)"></div>
|
17
|
+
|
18
|
+
<!-- Fallback content for non-JS browsers. Same img src as the initial, unqualified source element. -->
|
19
|
+
<noscript>
|
20
|
+
<img src="external/imgs/small.jpg" alt="A giant stone face at The Bayon temple in Angkor Thom, Cambodia">
|
21
|
+
</noscript>
|
22
|
+
</div>
|
23
|
+
```
|
24
|
+
|
25
|
+
The above can be rendered in Rails 3+ by writing the following code, using the View helpers provided by the Rails engine included:
|
26
|
+
|
27
|
+
```haml
|
28
|
+
= picturefill 'A giant stone face at The Bayon temple in Angkor Thom, Cambodia' do
|
29
|
+
= picture_src 'small.jpg'
|
30
|
+
= picture_src 'small.jpg', "(min-device-pixel-ratio: 2.0)"
|
31
|
+
= picture_src 'medium.jpg', "(min-width: 400px)"
|
32
|
+
= picture_src 'medium_x2.jpg', "(min-width: 400px) and (min-device-pixel-ratio: 2.0)"
|
33
|
+
= picture_src 'largs.jpg', "(min-width: 800px)"
|
34
|
+
= picture_src 'large_x2.jpg', "(min-width: 800px) and (min-device-pixel-ratio: 2.0)"
|
35
|
+
```
|
36
|
+
|
37
|
+
Note: This example uses [HAML](https://github.com/haml/haml) as the rendering engine.
|
38
|
+
|
39
|
+
### Optimizations using conventions
|
40
|
+
|
41
|
+
Using conventions, and an extra `ratio:` option, the following shorthand is possible:
|
42
|
+
|
43
|
+
```haml
|
44
|
+
= picturefill 'A giant stone face at The Bayon temple in Angkor Thom, Cambodia' do
|
45
|
+
= picture_src 'small.jpg', ratio: 'x2'
|
46
|
+
= picture_src 'medium.jpg', "400", ratio: 'x2'
|
47
|
+
= picture_src 'large.jpg', "800", ratio: 'x2'
|
48
|
+
```
|
49
|
+
|
50
|
+
This will ouput exactly the same HTML as the previous example :)
|
51
|
+
See the specs for more details...
|
52
|
+
|
53
|
+
## Usage
|
54
|
+
|
55
|
+
In your Gemfile:
|
56
|
+
|
57
|
+
`gem 'picturefill-rails'`
|
58
|
+
|
59
|
+
A number of specs are included which all pass and should ensure that the view helpers work as expected.
|
60
|
+
|
61
|
+
## TODO
|
62
|
+
|
63
|
+
The `#picture_src` method works, but could use some heavy refactoring! I don't like methods of more than 10 lines! Is a bad sign. Reponsibilities should be off-loaded to other methods (or classes)
|
64
|
+
|
65
|
+
## Contributing to picturefill-rails
|
66
|
+
|
67
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
68
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
69
|
+
* Fork the project.
|
70
|
+
* Start a feature/bugfix branch.
|
71
|
+
* Commit and push until you are happy with your contribution.
|
72
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
73
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
74
|
+
|
75
|
+
## Copyright
|
76
|
+
|
77
|
+
Copyright (c) 2012 Kristian Mandrup. See LICENSE.txt for
|
78
|
+
further details.
|
79
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "picturefill-rails"
|
18
|
+
gem.homepage = "http://github.com/kristianmandrup/picturefill-rails"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Picturefill view helpers for Rails to facilitate Responsive Images}
|
21
|
+
gem.description = %Q{Use picturefill with Rails :)}
|
22
|
+
gem.email = "kmandrup@gmail.com"
|
23
|
+
gem.authors = ["Kristian Mandrup"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "picturefill-rails #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module Picturefill
|
2
|
+
module ViewHelper
|
3
|
+
def picturefill options = {}, &block
|
4
|
+
opts = {}
|
5
|
+
alt = options.delete :alt
|
6
|
+
clazz = options.delete :class
|
7
|
+
opts.merge! :"data-alt" => alt unless alt.blank?
|
8
|
+
opts.merge! "class" => clazz unless clazz.blank?
|
9
|
+
opts.merge! :"data-picture" => true
|
10
|
+
|
11
|
+
content = block_given? ? capture(&block) : ''
|
12
|
+
content_tag :div, content, opts
|
13
|
+
end
|
14
|
+
|
15
|
+
# UGLY AS HELL!!! Needs refactor :P
|
16
|
+
def picture_src src, *args
|
17
|
+
options = args.extract_options!
|
18
|
+
media = args.first.to_s if args.first.kind_of?(String) || args.first.kind_of?(Fixnum)
|
19
|
+
|
20
|
+
ratio_opt = options.delete(:ratio)
|
21
|
+
media_opt = Picturefill::ViewHelper.extract media unless media.blank?
|
22
|
+
|
23
|
+
unless media_opt && media_opt =~ /min-device-pixel-ratio/
|
24
|
+
# use filename to provide ratio_opt
|
25
|
+
filename = Picturefill::ViewHelper.filename(src).first
|
26
|
+
fn = filename =~ /_x\d(\d)?/
|
27
|
+
if fn && !ratio_opt
|
28
|
+
ratio_opt = filename.match(/x\d(\d)?$/).to_s
|
29
|
+
else
|
30
|
+
auto_ratio_tag = ratio_opt[0] == 'x' unless ratio_opt.blank?
|
31
|
+
end
|
32
|
+
ratio = Picturefill::ViewHelper.ratio_attrib(ratio_opt) unless ratio_opt.blank?
|
33
|
+
media_opt = [media_opt, ratio].compact.join(' and ')
|
34
|
+
end
|
35
|
+
|
36
|
+
next_content = if auto_ratio_tag
|
37
|
+
opts = options.dup
|
38
|
+
filename = Picturefill::ViewHelper.ratio_file_name src, ratio_opt
|
39
|
+
opts.merge!(:ratio => ratio_opt.delete('x'))
|
40
|
+
picture_src filename, media, opts
|
41
|
+
end
|
42
|
+
|
43
|
+
options.merge! :"data-media" => media_opt unless auto_ratio_tag || media_opt.blank?
|
44
|
+
options.merge! :"data-src" => src
|
45
|
+
|
46
|
+
content_tag(:div, nil, options) + next_content
|
47
|
+
end
|
48
|
+
|
49
|
+
def picture_fallback src, options = {}
|
50
|
+
content_tag :noscript, content_tag(:img, nil, options.merge(src: src))
|
51
|
+
end
|
52
|
+
|
53
|
+
class << self
|
54
|
+
def filename src
|
55
|
+
src_parts = src.split('.')
|
56
|
+
ext = src_parts[1..-1].join('.')
|
57
|
+
[src_parts.first, ext]
|
58
|
+
end
|
59
|
+
|
60
|
+
def ratio_file_name src, ratio_opt
|
61
|
+
fn_parts = filename(src)
|
62
|
+
ratio_opt = ratio_opt.delete('x')
|
63
|
+
"#{fn_parts.first}_x2.#{fn_parts.last}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def extract media
|
67
|
+
return if media.blank?
|
68
|
+
case media
|
69
|
+
when /^(\d+)$/
|
70
|
+
"(min-width: #{media}px)"
|
71
|
+
when /^(\d+)px$/
|
72
|
+
"(min-width: #{media})"
|
73
|
+
when /min-width: (\d+)$/
|
74
|
+
"(#{media}px)"
|
75
|
+
when /min-width: (\d+)px$/
|
76
|
+
"(#{media})"
|
77
|
+
else
|
78
|
+
raise ArgumentError, "Picturefill :media attribute could not be parsed, was: #{media}"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def ratio_attrib ratio
|
83
|
+
ratio = ratio.to_s.delete('x')
|
84
|
+
minor = 0
|
85
|
+
case ratio.to_s
|
86
|
+
when /^\d/
|
87
|
+
major = ratio
|
88
|
+
when /^\d.\d/
|
89
|
+
major, minor = ratio.split '.'
|
90
|
+
else
|
91
|
+
raise ArgumentError, "Invalid ratio: #{ratio}, must be a number, fx '2.5' or '2' (even 'x2' or 'x2.5')"
|
92
|
+
end
|
93
|
+
ratio_attribute major, minor
|
94
|
+
end
|
95
|
+
|
96
|
+
protected
|
97
|
+
|
98
|
+
def ratio_attribute major, minor
|
99
|
+
"(min-device-pixel-ratio: #{major}.#{minor})"
|
100
|
+
end
|
101
|
+
end # class methods
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "picturefill-rails"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kristian Mandrup"]
|
12
|
+
s.date = "2012-08-16"
|
13
|
+
s.description = "Use picturefill with Rails :)"
|
14
|
+
s.email = "kmandrup@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.md",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/picturefill-rails.rb",
|
29
|
+
"lib/picturefill/engine.rb",
|
30
|
+
"lib/picturefill/view_helper.rb",
|
31
|
+
"picturefill-rails.gemspec",
|
32
|
+
"spec/picturefill/view_helper_spec.rb",
|
33
|
+
"spec/spec_helper.rb"
|
34
|
+
]
|
35
|
+
s.homepage = "http://github.com/kristianmandrup/picturefill-rails"
|
36
|
+
s.licenses = ["MIT"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = "1.8.24"
|
39
|
+
s.summary = "Picturefill view helpers for Rails to facilitate Responsive Images"
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_runtime_dependency(%q<rails>, [">= 3.0.0"])
|
46
|
+
s.add_development_dependency(%q<rspec>, [">= 2.8.0"])
|
47
|
+
s.add_development_dependency(%q<rdoc>, [">= 3.12"])
|
48
|
+
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
49
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
50
|
+
s.add_development_dependency(%q<simplecov>, [">= 0.5"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<rails>, [">= 3.0.0"])
|
53
|
+
s.add_dependency(%q<rspec>, [">= 2.8.0"])
|
54
|
+
s.add_dependency(%q<rdoc>, [">= 3.12"])
|
55
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
56
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
57
|
+
s.add_dependency(%q<simplecov>, [">= 0.5"])
|
58
|
+
end
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<rails>, [">= 3.0.0"])
|
61
|
+
s.add_dependency(%q<rspec>, [">= 2.8.0"])
|
62
|
+
s.add_dependency(%q<rdoc>, [">= 3.12"])
|
63
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
64
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
65
|
+
s.add_dependency(%q<simplecov>, [">= 0.5"])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Picturefill::ViewHelper do
|
4
|
+
include ControllerTestHelpers,
|
5
|
+
Picturefill::ViewHelper
|
6
|
+
|
7
|
+
describe '#picturefill' do
|
8
|
+
context 'no arguments' do
|
9
|
+
it "should be empty with a data-picture attribute" do
|
10
|
+
output = picturefill do
|
11
|
+
end
|
12
|
+
output.should == "<div data-picture=\"true\"></div>"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'alt option' do
|
17
|
+
it "should add the data-alt atribute" do
|
18
|
+
output = picturefill alt: 'nice pic' do
|
19
|
+
end
|
20
|
+
output.should == "<div data-alt=\"nice pic\" data-picture=\"true\"></div>"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'alt option and block' do
|
25
|
+
it "should add a piture src" do
|
26
|
+
output = picturefill alt: 'nice pic' do
|
27
|
+
picture_src 'small.jpg'
|
28
|
+
end
|
29
|
+
output.should == "<div data-alt=\"nice pic\" data-picture=\"true\"><div data-src=\"small.jpg\"></div></div>"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#picture_src' do
|
35
|
+
context 'filename with media: 400' do
|
36
|
+
it "should add a piture src with ratio and 400px min width" do
|
37
|
+
output = picture_src 'small.jpg', 400
|
38
|
+
output.should == "<div data-media=\"(min-width: 400px)\" data-src=\"small.jpg\"></div>"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'filename with _x2' do
|
43
|
+
it "should add a piture src" do
|
44
|
+
output = picture_src 'small_x2.jpg'
|
45
|
+
output.should == "<div data-media=\"(min-device-pixel-ratio: 2.0)\" data-src=\"small_x2.jpg\"></div>"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'filename with _x2 and media: 400' do
|
50
|
+
it "should add a piture src with ratio and 400px min width" do
|
51
|
+
output = picture_src 'small_x2.jpg', 400
|
52
|
+
output.should == "<div data-media=\"(min-width: 400px) and (min-device-pixel-ratio: 2.0)\" data-src=\"small_x2.jpg\"></div>"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "filename and ratio: 'x2'" do
|
57
|
+
it "should add an extra piture src for Retina with x2" do
|
58
|
+
output = picture_src 'small.jpg', ratio: 'x2'
|
59
|
+
output.should == "<div data-src=\"small.jpg\"></div><div data-media=\"(min-device-pixel-ratio: 2.0)\" data-src=\"small_x2.jpg\"></div>"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#pic_fallback' do
|
65
|
+
it "should add a <noscript> fallback with a normal <img> tag as fallback" do
|
66
|
+
output = picture_fallback 'small.jpg'
|
67
|
+
output.should == "<noscript><img src=\"small.jpg\"></img></noscript>"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rails'
|
4
|
+
require 'json'
|
5
|
+
require 'active_support'
|
6
|
+
require 'action_pack'
|
7
|
+
require 'action_view'
|
8
|
+
require 'action_controller'
|
9
|
+
require 'action_view/template'
|
10
|
+
|
11
|
+
require 'rspec'
|
12
|
+
require 'picturefill-rails'
|
13
|
+
|
14
|
+
# WorldFlags::Rails::Engine.add_view_ext
|
15
|
+
|
16
|
+
SPEC_DIR = File.dirname(__FILE__)
|
17
|
+
|
18
|
+
module ControllerTestHelpers
|
19
|
+
|
20
|
+
def self.included(base)
|
21
|
+
base.class_eval do
|
22
|
+
|
23
|
+
include ActionView::Helpers,
|
24
|
+
ActionView::Helpers::CaptureHelper,
|
25
|
+
ActionView::Helpers::JavaScriptHelper,
|
26
|
+
ActionView::Helpers::AssetTagHelper
|
27
|
+
|
28
|
+
# allow tabs.create to run by stubbing an output_buffer
|
29
|
+
attr_accessor :output_buffer
|
30
|
+
@output_buffer = ""
|
31
|
+
|
32
|
+
# stub content_for for testing
|
33
|
+
def content_for(name, content = nil, &block)
|
34
|
+
# this doesn't exist, and causes errors
|
35
|
+
@_content_for = {} unless defined? @_content_for
|
36
|
+
# we've got to initialize this, so we can concat to it
|
37
|
+
@_content_for[name] = '' if @_content_for[name].nil?
|
38
|
+
# now the rest is the same as in rails
|
39
|
+
content = capture(&block) if block_given?
|
40
|
+
@_content_for[name] << content if content
|
41
|
+
@_content_for[name] unless content
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: picturefill-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kristian Mandrup
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.0
|
22
|
+
type: :runtime
|
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.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.8.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.8.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rdoc
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.12'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.12'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bundler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.0.0
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.0.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: jeweler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.8.4
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.8.4
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: simplecov
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0.5'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0.5'
|
110
|
+
description: Use picturefill with Rails :)
|
111
|
+
email: kmandrup@gmail.com
|
112
|
+
executables: []
|
113
|
+
extensions: []
|
114
|
+
extra_rdoc_files:
|
115
|
+
- LICENSE.txt
|
116
|
+
- README.md
|
117
|
+
files:
|
118
|
+
- .document
|
119
|
+
- .rspec
|
120
|
+
- Gemfile
|
121
|
+
- Gemfile.lock
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- VERSION
|
126
|
+
- lib/picturefill-rails.rb
|
127
|
+
- lib/picturefill/engine.rb
|
128
|
+
- lib/picturefill/view_helper.rb
|
129
|
+
- picturefill-rails.gemspec
|
130
|
+
- spec/picturefill/view_helper_spec.rb
|
131
|
+
- spec/spec_helper.rb
|
132
|
+
homepage: http://github.com/kristianmandrup/picturefill-rails
|
133
|
+
licenses:
|
134
|
+
- MIT
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
none: false
|
141
|
+
requirements:
|
142
|
+
- - ! '>='
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
segments:
|
146
|
+
- 0
|
147
|
+
hash: -1817757138162411960
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
none: false
|
150
|
+
requirements:
|
151
|
+
- - ! '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
requirements: []
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 1.8.24
|
157
|
+
signing_key:
|
158
|
+
specification_version: 3
|
159
|
+
summary: Picturefill view helpers for Rails to facilitate Responsive Images
|
160
|
+
test_files: []
|