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 CHANGED
@@ -1,18 +1,6 @@
1
1
  *.gem
2
- *.rbc
3
2
  .bundle
4
- .config
5
- .yardoc
3
+ .DS_Store
4
+ bin
6
5
  Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
6
  pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- .DS_Store
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 1.9.2
data/Gemfile CHANGED
@@ -1,4 +1,7 @@
1
- source 'https://rubygems.org'
1
+ source "http://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in lazyload-rails.gemspec
4
3
  gemspec
4
+
5
+ group :test do
6
+ gem "rake"
7
+ end
@@ -1,6 +1,4 @@
1
- Copyright (c) 2013 Javier Saldana
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
- # Lazyload::Rails
1
+ ## Lazyload-Rails [![Build Status](https://travis-ci.org/jassa/lazyload-rails.png)](https://travis-ci.org/jassa/lazyload-rails)
2
2
 
3
- TODO: Write a gem description
3
+ This project integrates the jQuery Lazy Load Plugin
4
+ for Rails `image_tag` helpers
4
5
 
5
- ## Installation
6
+ ## Documentation
6
7
 
7
- Add this line to your application's Gemfile:
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
- gem 'lazyload-rails'
18
+ Equals:
10
19
 
11
- And then execute:
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
- $ bundle
26
+ gem "lazyload-rails"
14
27
 
15
- Or install it yourself as:
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
- $ gem install lazyload-rails
31
+ *Important: Remember that the Lazy Load Plugin depends on jQuery.*
18
32
 
19
- ## Usage
33
+ ## FAQ
20
34
 
21
- TODO: Write usage instructions here
35
+ * *Q: How can I use the old `image_tag` method?*
36
+ * R: Try with `x_image_tag`
22
37
 
23
- ## Contributing
38
+ ## License
24
39
 
25
- 1. Fork it
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
@@ -1 +1,8 @@
1
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,21 +1,22 @@
1
- lib = File.expand_path('../lib', __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
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.name = "lazyload-rails"
7
- gem.version = Lazyload::Rails::VERSION
8
- gem.authors = ["Javier Saldana"]
9
- gem.email = ["javier@tractical.com"]
10
- gem.summary = %q{jQuery Lazy Load for Rails image_tag helpers}
11
- gem.description = <<-EOF
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
- EOF
15
- gem.homepage = "https://github.com/jassa/lazyload-rails"
15
+ EOS
16
16
 
17
- gem.files = `git ls-files`.split($/)
18
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
- gem.require_paths = ["lib"]
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
@@ -1,7 +1,17 @@
1
+ require "nokogiri"
2
+ require "action_view"
1
3
  require "lazyload-rails/version"
2
4
 
3
- module Lazyload
4
- module Rails
5
- # Your code goes here...
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
@@ -1,5 +1,5 @@
1
1
  module Lazyload
2
2
  module Rails
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  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.1
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-03-06 00:00:00.000000000 Z
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.txt
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