lazyload-rails 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -3,6 +3,16 @@
3
3
  This project integrates the jQuery Lazy Load Plugin
4
4
  for Rails `image_tag` helpers
5
5
 
6
+ ### What's jQuery Lazy Load?
7
+
8
+ From the project page:
9
+
10
+ *Lazy Load is a jQuery plugin written in JavaScript. It delays loading of images in long web pages. Images outside of viewport (visible part of web page) won't be loaded before user scrolls to them. This is opposite of image preloading.*
11
+
12
+ *Using Lazy Load on long web pages containing many large images makes the page load faster. Browser will be in ready state after loading visible images. In some cases it can also help to reduce server load.*
13
+
14
+ See [example](http://backbonejs.org/#examples) (scroll down to see images load)
15
+
6
16
  ## Documentation
7
17
 
8
18
  ### Features
@@ -28,8 +38,23 @@ Add this line to your application's Gemfile:
28
38
  Download the [jQuery Lazy Load Plugin](https://raw.github.com/tuupola/jquery_lazyload/master/jquery.lazyload.js)
29
39
  into your `vendor/assets/javascripts` directory and include it however you prefer.
30
40
 
41
+ And in your JavaScript code do:
42
+
43
+ $("img").lazyload();
44
+
45
+ Lazy Load can be customized, [see more options](http://www.appelsiini.net/projects/lazyload)
46
+
31
47
  *Important: Remember that the Lazy Load Plugin depends on jQuery.*
32
48
 
49
+ ## Configuration
50
+
51
+ By default, a 1x1 grey gif is used as placeholder (from [http://appelsiini.net/projects/lazyload/img/grey.gif](http://www.appelsiini.net/projects/lazyload/img/grey.gif)). This can be easily customized:
52
+
53
+ # config/initializers/lazyload.rb
54
+ Lazyload::Rails.configure do |config|
55
+ config.placeholder = "/public/img/grey.gif"
56
+ end
57
+
33
58
  ## FAQ
34
59
 
35
60
  * *Q: How can I use the old `image_tag` method?*
@@ -1,12 +1,41 @@
1
1
  require "nokogiri"
2
2
  require "action_view"
3
+
3
4
  require "lazyload-rails/version"
5
+ require "lazyload-rails/configuration"
6
+
7
+ module Lazyload
8
+ module Rails
9
+
10
+ def self.configuration
11
+ @configuration ||= Lazyload::Rails::Configuration.new
12
+ end
13
+
14
+ def self.configuration=(new_configuration)
15
+ @configuration = new_configuration
16
+ end
17
+
18
+ # Yields the global configuration to a block.
19
+ #
20
+ # Example:
21
+ # Lazyload::Rails.configure do |config|
22
+ # config.placeholder = '/public/images/foo.gif'
23
+ # end
24
+ def self.configure
25
+ yield configuration if block_given?
26
+ end
27
+
28
+ def self.reset
29
+ @configuration = nil
30
+ end
31
+ end
32
+ end
4
33
 
5
34
  ActionView::Helpers::AssetTagHelper.module_eval do
6
35
  alias :x_image_tag :image_tag
7
36
 
8
37
  def image_tag(*attrs)
9
- placeholder = "http://www.appelsiini.net/projects/lazyload/img/grey.gif"
38
+ placeholder = Lazyload::Rails.configuration.placeholder
10
39
  img = Nokogiri::HTML::DocumentFragment.parse(x_image_tag(*attrs)).at_css("img")
11
40
  src = img["src"]
12
41
 
@@ -0,0 +1,29 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Lazyload
3
+ module Rails
4
+
5
+ # Stores runtime configuration information.
6
+ #
7
+ # Example settings
8
+ # Lazyload::Rails.configure do |c|
9
+ # c.placeholder = "/public/img/grey.gif"
10
+ # end
11
+ class Configuration
12
+
13
+ # The placeholder image to put into the img src attribute
14
+ # (default: 1×1 pixel grey gif at
15
+ # "http://www.appelsiini.net/projects/lazyload/img/grey.gif").
16
+ def placeholder
17
+ @placeholder
18
+ end
19
+ def placeholder=(new_placeholder)
20
+ @placeholder = new_placeholder
21
+ end
22
+
23
+ # Set default settings
24
+ def initialize
25
+ @placeholder = "http://www.appelsiini.net/projects/lazyload/img/grey.gif"
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,5 +1,5 @@
1
1
  module Lazyload
2
2
  module Rails
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  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.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-19 00:00:00.000000000 Z
12
+ date: 2013-04-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 1.5.9
21
+ version: '1.5'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 1.5.9
29
+ version: '1.5'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: actionpack
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -43,24 +43,18 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '3.1'
46
- description: ! " lazyload-rails project integrates jQuery Lazy Load\n Plugin
47
- for Rails image_tag helpers\n"
48
- email:
49
- - javier@tractical.com
46
+ description: lazyload-rails project integrates jQuery Lazy Load Plugin for Rails image_tag
47
+ helpers
48
+ email: javier@tractical.com
50
49
  executables: []
51
50
  extensions: []
52
51
  extra_rdoc_files: []
53
52
  files:
54
- - .gitignore
55
- - .travis.yml
56
- - Gemfile
57
- - MIT-LICENSE
58
53
  - README.md
59
- - Rakefile
60
- - lazyload-rails.gemspec
61
- - lib/lazyload-rails.rb
54
+ - MIT-LICENSE
55
+ - lib/lazyload-rails/configuration.rb
62
56
  - lib/lazyload-rails/version.rb
63
- - test/asset_tag_helper_test.rb
57
+ - lib/lazyload-rails.rb
64
58
  homepage: https://github.com/jassa/lazyload-rails
65
59
  licenses:
66
60
  - MIT
@@ -86,5 +80,4 @@ rubygems_version: 1.8.23
86
80
  signing_key:
87
81
  specification_version: 3
88
82
  summary: jQuery Lazy Load for Rails image_tag helpers
89
- test_files:
90
- - test/asset_tag_helper_test.rb
83
+ test_files: []
data/.gitignore DELETED
@@ -1,6 +0,0 @@
1
- *.gem
2
- .bundle
3
- .DS_Store
4
- bin
5
- Gemfile.lock
6
- pkg
@@ -1,4 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3
4
- - 1.9.2
data/Gemfile DELETED
@@ -1,7 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gemspec
4
-
5
- group :test do
6
- gem "rake"
7
- end
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- Rake::TestTask.new do |t|
5
- t.test_files = FileList['test/*_test.rb']
6
- end
7
-
8
- task :default => :test
@@ -1,22 +0,0 @@
1
- $:.push File.expand_path("../lib", __FILE__)
2
- require "lazyload-rails/version"
3
-
4
- Gem::Specification.new do |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
13
- lazyload-rails project integrates jQuery Lazy Load
14
- Plugin for Rails image_tag helpers
15
- EOS
16
-
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"
22
- end
@@ -1,57 +0,0 @@
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