unveil-rails 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -5
- data/lib/unveil/rails/version.rb +1 -1
- data/lib/unveil/rails/view_helper.rb +2 -2
- data/spec/helpers/view_helper_spec.rb +21 -6
- data/spec/mocks/context_mock.rb +1 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54f93550291407b2f15222f3ae4dd458d2f726c8
|
4
|
+
data.tar.gz: fdc41bff5a571597264d1af293201f637e0594ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a82c646a4272422ccfecd354e8ad57449588d122e3220958dd6075dcf9b738d4bf1a393ae621cfae148ac50fe3e43608b264701c1f5ab06919fd7be3411c7704
|
7
|
+
data.tar.gz: 9762a3d277cd0d1c4383922aaa9f1b6c798df033a3aa1b56925c61820021f4305354ecc3d508c0acc00c2d3cd7951bbbb0d4a12da295ca2b551189057fb38550
|
data/README.md
CHANGED
@@ -1,28 +1,32 @@
|
|
1
1
|
# Unveil.js for Rails
|
2
2
|
|
3
|
-
|
3
|
+
Lazy loaded images on rails. If you want a quick start using
|
4
|
+
[unveil.js][unveil-github] with rails there is now a gem for that.
|
5
|
+
|
6
|
+
By loading your images as they appear in the viewport rather than on load you
|
7
|
+
can improve your rails application's page speed.
|
4
8
|
|
5
9
|
## Installation
|
6
10
|
|
7
|
-
Add the gem
|
11
|
+
Add the unveil-rails gem into your `Gemfile`:
|
8
12
|
|
9
13
|
``` ruby
|
10
14
|
gem 'unveil-rails', '~> 0.1.0'
|
11
15
|
```
|
12
16
|
|
13
|
-
Install
|
17
|
+
Install unveil.js and initializer into your rails app:
|
14
18
|
|
15
19
|
```
|
16
20
|
bin/rails g unveil:rails:install
|
17
21
|
```
|
18
22
|
|
19
|
-
Include the
|
23
|
+
Include the unveil.js initializer in `app/assets/javascripts/application.js`:
|
20
24
|
|
21
25
|
``` js
|
22
26
|
//= require unveil_init
|
23
27
|
```
|
24
28
|
|
25
|
-
Now use the helper method
|
29
|
+
Now use the helper method where ever you want lazy images:
|
26
30
|
|
27
31
|
```erb
|
28
32
|
<%= lazy_image_tag('an-image.png') %>
|
@@ -66,6 +70,8 @@ Developed and maintained by [Made Tech][made]. Key contributions:
|
|
66
70
|
|
67
71
|
* [Luke Morton](https://github.com/DrPheltRight)
|
68
72
|
|
73
|
+
And of course [Luís Almeida][luis-github] creator of [unveil.js][unveil-github].
|
74
|
+
|
69
75
|
## License
|
70
76
|
|
71
77
|
Copyright © 2014 Made Tech Ltd. It is free software, and may be
|
@@ -75,3 +81,4 @@ redistributed under the terms specified in the [LICENSE][license] file.
|
|
75
81
|
[license]: https://github.com/madebymade/cf-deploy/blob/master/LICENSE
|
76
82
|
[unveil-github]: https://github.com/luis-almeida/unveil
|
77
83
|
[unveil-docs]: http://luis-almeida.github.io/unveil/
|
84
|
+
[luis-github]: https://github.com/luis-almeida
|
data/lib/unveil/rails/version.rb
CHANGED
@@ -3,9 +3,9 @@ module Unveil
|
|
3
3
|
module ViewHelper
|
4
4
|
def lazy_image_tag(source, options = {})
|
5
5
|
placeholder_source = options[:placeholder] || Unveil::Rails.config.default_placeholder
|
6
|
+
options[:alt] = options[:alt] || image_alt(source)
|
6
7
|
|
7
|
-
lazy_options = options.merge('data-src' => image_path(source)
|
8
|
-
alt: image_alt(source))
|
8
|
+
lazy_options = options.merge('data-src' => image_path(source))
|
9
9
|
|
10
10
|
if options.has_key?(:retina)
|
11
11
|
lazy_options['data-src-retina'] = image_path(options[:retina])
|
@@ -18,9 +18,9 @@ describe Unveil::Rails::ViewHelper do
|
|
18
18
|
|
19
19
|
let(:expected_html) do
|
20
20
|
<<-HTML
|
21
|
-
<img src="/blank.gif" data-src="/my-image.png" />
|
21
|
+
<img src="/blank.gif" alt="my-image.png" data-src="/my-image.png" />
|
22
22
|
<noscript>
|
23
|
-
<img src="/my-image.png" />
|
23
|
+
<img src="/my-image.png" alt="my-image.png" />
|
24
24
|
</noscript>
|
25
25
|
HTML
|
26
26
|
end
|
@@ -33,9 +33,9 @@ describe Unveil::Rails::ViewHelper do
|
|
33
33
|
|
34
34
|
let(:expected_html) do
|
35
35
|
<<-HTML
|
36
|
-
<img src="/place.gif" data-src="/my-image.png" />
|
36
|
+
<img src="/place.gif" alt="my-image.png" data-src="/my-image.png" />
|
37
37
|
<noscript>
|
38
|
-
<img src="/my-image.png" />
|
38
|
+
<img src="/my-image.png" alt="my-image.png" />
|
39
39
|
</noscript>
|
40
40
|
HTML
|
41
41
|
end
|
@@ -48,9 +48,24 @@ describe Unveil::Rails::ViewHelper do
|
|
48
48
|
|
49
49
|
let(:expected_html) do
|
50
50
|
<<-HTML
|
51
|
-
<img src="/blank.gif" data-src="/my-image.png" data-src-retina="/my-retina-image.png" />
|
51
|
+
<img src="/blank.gif" alt="my-image.png" data-src="/my-image.png" data-src-retina="/my-retina-image.png" />
|
52
52
|
<noscript>
|
53
|
-
<img src="/my-image.png" />
|
53
|
+
<img src="/my-image.png" alt="my-image.png" />
|
54
|
+
</noscript>
|
55
|
+
HTML
|
56
|
+
end
|
57
|
+
|
58
|
+
it { is_expected.to eq(expected_html.strip) }
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'when alt text provided' do
|
62
|
+
let(:options) { { alt: 'Alt text' } }
|
63
|
+
|
64
|
+
let(:expected_html) do
|
65
|
+
<<-HTML
|
66
|
+
<img src="/blank.gif" alt="Alt text" data-src="/my-image.png" />
|
67
|
+
<noscript>
|
68
|
+
<img src="/my-image.png" alt="Alt text" />
|
54
69
|
</noscript>
|
55
70
|
HTML
|
56
71
|
end
|
data/spec/mocks/context_mock.rb
CHANGED
@@ -11,6 +11,7 @@ class ContextMock
|
|
11
11
|
|
12
12
|
def image_tag(source, options = {})
|
13
13
|
options_html = ''
|
14
|
+
options_html << " alt=\"#{options[:alt]}\"" if options[:alt]
|
14
15
|
options_html << " data-src=\"#{options['data-src']}\"" if options['data-src']
|
15
16
|
options_html << " data-src-retina=\"#{options['data-src-retina']}\"" if options['data-src-retina']
|
16
17
|
"<img src=\"#{image_path(source)}\"#{options_html} />"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unveil-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luke Morton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -91,9 +91,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
91
|
version: '0'
|
92
92
|
requirements: []
|
93
93
|
rubyforge_project:
|
94
|
-
rubygems_version: 2.
|
94
|
+
rubygems_version: 2.4.5
|
95
95
|
signing_key:
|
96
96
|
specification_version: 4
|
97
97
|
summary: Lazy loaded images for rails
|
98
98
|
test_files: []
|
99
|
-
has_rdoc:
|