lazyload-rails 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -14
- data/.travis.yml +4 -0
- data/Gemfile +5 -2
- data/{LICENSE.txt → MIT-LICENSE} +2 -4
- data/README.md +28 -17
- data/Rakefile +7 -0
- data/lazyload-rails.gemspec +16 -15
- data/lib/lazyload-rails.rb +13 -3
- data/lib/lazyload-rails/version.rb +1 -1
- data/test/asset_tag_helper_test.rb +57 -0
- metadata +42 -6
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/{LICENSE.txt → MIT-LICENSE}
RENAMED
@@ -1,6 +1,4 @@
|
|
1
|
-
Copyright
|
2
|
-
|
3
|
-
MIT License
|
1
|
+
Copyright 2013 YOURNAME
|
4
2
|
|
5
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
6
4
|
a copy of this software and associated documentation files (the
|
@@ -19,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
17
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
18
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
19
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,29 +1,40 @@
|
|
1
|
-
|
1
|
+
## Lazyload-Rails [![Build Status](https://travis-ci.org/jassa/lazyload-rails.png)](https://travis-ci.org/jassa/lazyload-rails)
|
2
2
|
|
3
|
-
|
3
|
+
This project integrates the jQuery Lazy Load Plugin
|
4
|
+
for Rails `image_tag` helpers
|
4
5
|
|
5
|
-
##
|
6
|
+
## Documentation
|
6
7
|
|
7
|
-
|
8
|
+
### Features
|
9
|
+
|
10
|
+
* Automatically get Rails `image_tag` helpers to render lazyload-friendly
|
11
|
+
html img tags.
|
12
|
+
* Simple, really. That's pretty much it.
|
13
|
+
|
14
|
+
### Example
|
15
|
+
|
16
|
+
<%= image_tag "kittenz.png", alt: "OMG a cat!" %>
|
8
17
|
|
9
|
-
|
18
|
+
Equals:
|
10
19
|
|
11
|
-
|
20
|
+
<img alt="OMG a cat!" data-original="/images/kittenz.png" src="http://www.appelsiini.net/projects/lazyload/img/grey.gif">
|
21
|
+
|
22
|
+
## Install
|
23
|
+
|
24
|
+
Add this line to your application's Gemfile:
|
12
25
|
|
13
|
-
|
26
|
+
gem "lazyload-rails"
|
14
27
|
|
15
|
-
|
28
|
+
Download the [jQuery Lazy Load Plugin](https://raw.github.com/tuupola/jquery_lazyload/master/jquery.lazyload.js)
|
29
|
+
into your `vendor/assets/javascripts` directory and include it however you prefer.
|
16
30
|
|
17
|
-
|
31
|
+
*Important: Remember that the Lazy Load Plugin depends on jQuery.*
|
18
32
|
|
19
|
-
##
|
33
|
+
## FAQ
|
20
34
|
|
21
|
-
|
35
|
+
* *Q: How can I use the old `image_tag` method?*
|
36
|
+
* R: Try with `x_image_tag`
|
22
37
|
|
23
|
-
##
|
38
|
+
## License
|
24
39
|
|
25
|
-
|
26
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create new Pull Request
|
40
|
+
Lazyload-Rails is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
data/lazyload-rails.gemspec
CHANGED
@@ -1,21 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'lazyload-rails/version'
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "lazyload-rails/version"
|
4
3
|
|
5
4
|
Gem::Specification.new do |gem|
|
6
|
-
gem.
|
7
|
-
gem.
|
8
|
-
gem.
|
9
|
-
gem.
|
10
|
-
gem.
|
11
|
-
gem.
|
5
|
+
gem.author = ["Javier Saldana"]
|
6
|
+
gem.email = ["javier@tractical.com"]
|
7
|
+
gem.homepage = "https://github.com/jassa/lazyload-rails"
|
8
|
+
gem.name = "lazyload-rails"
|
9
|
+
gem.license = "MIT"
|
10
|
+
gem.version = Lazyload::Rails::VERSION
|
11
|
+
gem.summary = "jQuery Lazy Load for Rails image_tag helpers"
|
12
|
+
gem.description = <<-EOS
|
12
13
|
lazyload-rails project integrates jQuery Lazy Load
|
13
14
|
Plugin for Rails image_tag helpers
|
14
|
-
|
15
|
-
gem.homepage = "https://github.com/jassa/lazyload-rails"
|
15
|
+
EOS
|
16
16
|
|
17
|
-
gem.files
|
18
|
-
gem.
|
19
|
-
|
20
|
-
gem.
|
17
|
+
gem.files = `git ls-files`.split($/)
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
|
20
|
+
gem.add_dependency "nokogiri", "~> 1.5.9"
|
21
|
+
gem.add_development_dependency "actionpack", ">= 3.1"
|
21
22
|
end
|
data/lib/lazyload-rails.rb
CHANGED
@@ -1,7 +1,17 @@
|
|
1
|
+
require "nokogiri"
|
2
|
+
require "action_view"
|
1
3
|
require "lazyload-rails/version"
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
5
|
+
ActionView::Helpers::AssetTagHelper.module_eval do
|
6
|
+
alias :x_image_tag :image_tag
|
7
|
+
|
8
|
+
def image_tag(*attrs)
|
9
|
+
placeholder = "http://www.appelsiini.net/projects/lazyload/img/grey.gif"
|
10
|
+
img = Nokogiri::HTML::DocumentFragment.parse(x_image_tag(*attrs)).at_css("img")
|
11
|
+
src = img["src"]
|
12
|
+
|
13
|
+
img["src"] = placeholder
|
14
|
+
img["data-original"] = src
|
15
|
+
img.to_s.html_safe
|
6
16
|
end
|
7
17
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__),'..','lib')
|
2
|
+
|
3
|
+
require "test/unit"
|
4
|
+
require "action_view"
|
5
|
+
require "lazyload-rails"
|
6
|
+
|
7
|
+
class BasicController
|
8
|
+
attr_accessor :request
|
9
|
+
|
10
|
+
def config
|
11
|
+
@config ||= ActiveSupport::InheritableOptions.new(ActionController::Base.config).tap do |config|
|
12
|
+
public_dir = File.expand_path("../fixtures/public", __FILE__)
|
13
|
+
config.assets_dir = public_dir
|
14
|
+
config.assets = ActiveSupport::InheritableOptions.new({ :prefix => "assets" })
|
15
|
+
config
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class AssetTagHelperTest < ActionView::TestCase
|
21
|
+
tests ActionView::Helpers::AssetTagHelper
|
22
|
+
|
23
|
+
attr_reader :request
|
24
|
+
|
25
|
+
def setup
|
26
|
+
super
|
27
|
+
|
28
|
+
@controller = BasicController.new
|
29
|
+
|
30
|
+
@request = Class.new do
|
31
|
+
attr_accessor :script_name
|
32
|
+
def protocol() 'http://' end
|
33
|
+
def ssl?() false end
|
34
|
+
def host_with_port() 'localhost' end
|
35
|
+
def base_url() 'http://www.example.com' end
|
36
|
+
end.new
|
37
|
+
|
38
|
+
@controller.request = @request
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_lazy_attributes
|
42
|
+
expected = '<img alt="Foo" height="150"' +
|
43
|
+
' src="http://www.appelsiini.net/projects/lazyload/img/grey.gif"' +
|
44
|
+
' width="100" data-original="/images/foo.png">'
|
45
|
+
|
46
|
+
assert_equal expected, image_tag("foo.png", size: "100x150")
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_lazy_attributes_override
|
50
|
+
expected = '<img alt="Bar" data-original="/images/bar.png" height="150"' +
|
51
|
+
' src="http://www.appelsiini.net/projects/lazyload/img/grey.gif" width="200">'
|
52
|
+
|
53
|
+
actual = image_tag("bar.png", size: "200x150", data: { original: "foo" })
|
54
|
+
|
55
|
+
assert_equal expected, actual
|
56
|
+
end
|
57
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lazyload-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,40 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
13
|
-
dependencies:
|
12
|
+
date: 2013-04-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nokogiri
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.5.9
|
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: 1.5.9
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: actionpack
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.1'
|
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: '3.1'
|
14
46
|
description: ! " lazyload-rails project integrates jQuery Lazy Load\n Plugin
|
15
47
|
for Rails image_tag helpers\n"
|
16
48
|
email:
|
@@ -20,15 +52,18 @@ extensions: []
|
|
20
52
|
extra_rdoc_files: []
|
21
53
|
files:
|
22
54
|
- .gitignore
|
55
|
+
- .travis.yml
|
23
56
|
- Gemfile
|
24
|
-
- LICENSE
|
57
|
+
- MIT-LICENSE
|
25
58
|
- README.md
|
26
59
|
- Rakefile
|
27
60
|
- lazyload-rails.gemspec
|
28
61
|
- lib/lazyload-rails.rb
|
29
62
|
- lib/lazyload-rails/version.rb
|
63
|
+
- test/asset_tag_helper_test.rb
|
30
64
|
homepage: https://github.com/jassa/lazyload-rails
|
31
|
-
licenses:
|
65
|
+
licenses:
|
66
|
+
- MIT
|
32
67
|
post_install_message:
|
33
68
|
rdoc_options: []
|
34
69
|
require_paths:
|
@@ -51,4 +86,5 @@ rubygems_version: 1.8.23
|
|
51
86
|
signing_key:
|
52
87
|
specification_version: 3
|
53
88
|
summary: jQuery Lazy Load for Rails image_tag helpers
|
54
|
-
test_files:
|
89
|
+
test_files:
|
90
|
+
- test/asset_tag_helper_test.rb
|