loadergif 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 36589ec9422c4198c13c175f065a2edcf626198f0561ceeda0b65f16f784795a
4
+ data.tar.gz: e5a3f08de972d9bd8b2e6b30b8bd6427feea630314fe119ddd86e690a360763e
5
+ SHA512:
6
+ metadata.gz: d59f67d3194ed68be29b00a96cb6e434f1095d156711acd17042b42dee1a62cf0dad82bcb0b92aa3e1125eb936aac11beddb6b41f5e89f89a1e2f9f7ad04086a
7
+ data.tar.gz: 70854670eab9b83a2ed1a05c81783ef1b772d6d263a59264f7e1b12e765ebbdd063d8881ac33eb3b1c5c6862a4e82ab82da871f939e53089e8fdb8467eec9e59
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at neelam.j@cisinlabs.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in loadergif.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 cis-neelam
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,97 @@
1
+ ## Loadergif
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/loadergif`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ ### Features
6
+
7
+ * Add `lazy: true` option to Rails `image_tag` helpers to render lazyload-friendly img tags.
8
+ * Global config available to make them lazy by default.
9
+ * Simple (really). That's pretty much it.
10
+
11
+ ### Example
12
+
13
+ ```erb
14
+ <%= image_tag "kittenz.png", lazy: true %>
15
+ ```
16
+
17
+ or
18
+
19
+ ```ruby
20
+ # config/initializers/lazyload.rb
21
+ Loadergif::Rails.configure do |config|
22
+ config.lazy_by_default = true
23
+ end
24
+ ```
25
+ ```erb
26
+ <%= image_tag "kittenz.png" %>
27
+ ```
28
+
29
+ Equals:
30
+
31
+ ```html
32
+ <img src="data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs="
33
+ data-original="/images/kittenz.png" />
34
+ ```
35
+
36
+ **PRO TIP!** You must set image dimensions either as width and height attributes or in CSS. Otherwise it might not work properly.
37
+ ## Installation
38
+
39
+ Add this line to your application's Gemfile:
40
+
41
+ ```ruby
42
+ gem 'loadergif'
43
+ ```
44
+
45
+ And then execute:
46
+
47
+ $ bundle
48
+
49
+ Or install it yourself as:
50
+
51
+ $ gem install loadergif
52
+
53
+ 2. Download the [jQuery Lazy Load Plugin](https://raw.githubusercontent.com/cis-neelam/loder/master/jquery.loader.js)
54
+ into your `vendor/assets/javascripts` directory.
55
+
56
+ 3. Include it however you prefer. For example, in your application.js you could add:
57
+
58
+ //= require jquery.lazyload
59
+
60
+ 4. In your JavaScript code do:
61
+
62
+ $("img").lazyload();
63
+
64
+ *__Important__: Remember that the Lazy Load Plugin depends on jQuery.*
65
+
66
+ ## Configuration
67
+
68
+ ```ruby
69
+ # config/initializers/lazyload.rb
70
+ Loadergif::Rails.configure do |config|
71
+ # By default, a 1x1 grey gif is used as placeholder ("data:image/gif;base64,...").
72
+ # This can be easily customized:
73
+ config.placeholder = "/public/img/grey.gif"
74
+
75
+ # image_tag can return lazyload-friendly images by default,
76
+ # no need to pass the { lazy: true } option
77
+ config.lazy_by_default = true
78
+ end
79
+ ```
80
+
81
+ ## Development
82
+
83
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
84
+
85
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
86
+
87
+ ## Contributing
88
+
89
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/loadergif. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
90
+
91
+ ## License
92
+
93
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
94
+
95
+ ## Code of Conduct
96
+
97
+ Everyone interacting in the Loadergif project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/loadergif/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "loadergif"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/loadergif.rb ADDED
@@ -0,0 +1,73 @@
1
+ require "nokogiri"
2
+ require "action_view"
3
+ require "loadergif/version"
4
+ require "loadergif/config"
5
+
6
+ module Loadergif
7
+ class Error < StandardError; end
8
+ module Rails
9
+
10
+ def self.configuration
11
+ @configuration ||= Loadergif::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
33
+
34
+ ActionView::Helpers::AssetTagHelper.module_eval do
35
+ alias :rails_image_tag :image_tag
36
+
37
+ def image_tag(*attrs)
38
+ options, args = extract_options_and_args(*attrs)
39
+ image_html = rails_image_tag(*args)
40
+
41
+ is_lazy = options.fetch(:lazy) { Loadergif::Rails.configuration.lazy_by_default }
42
+
43
+ if is_lazy
44
+ to_lazy(image_html)
45
+ else
46
+ image_html
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ def to_lazy(image_html)
53
+ img = Nokogiri::HTML::DocumentFragment.parse(image_html).at_css("img")
54
+
55
+ img["data-original"] = img["src"]
56
+ img["src"] = Loadergif::Rails.configuration.placeholder
57
+
58
+ img.to_s.html_safe
59
+ end
60
+
61
+ def extract_options_and_args(*attrs)
62
+ args = attrs
63
+
64
+ if args.size > 1
65
+ options = attrs.last.dup
66
+ args.last.delete(:lazy)
67
+ else
68
+ options = {}
69
+ end
70
+
71
+ [options, args]
72
+ end
73
+ end
@@ -0,0 +1,38 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Loadergif
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
+ # When set to true every image_tag will include { lazy: true } by default
24
+ def lazy_by_default=(lazy_by_default)
25
+ @lazy_by_default = !!lazy_by_default
26
+ end
27
+ def lazy_by_default
28
+ @lazy_by_default
29
+ end
30
+
31
+ # Set default settings
32
+ def initialize
33
+ @placeholder = "data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs="
34
+ @lazy_by_default = false
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Loadergif
2
+ VERSION = "0.1.0"
3
+ end
data/loadergif.gemspec ADDED
@@ -0,0 +1,28 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "loadergif/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "loadergif"
8
+ spec.version = Loadergif::VERSION
9
+ spec.authors = ["cis-neelam"]
10
+ spec.email = ["neelam.j@cisinlabs.com"]
11
+
12
+ spec.summary = %q{Write a short summary, because RubyGems requires one.}
13
+ spec.description = %q{Write a longer description or delete this line.}
14
+ spec.homepage = "http://rubygems.org/gems/loadergif"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 2.0"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: loadergif
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - cis-neelam
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Write a longer description or delete this line.
42
+ email:
43
+ - neelam.j@cisinlabs.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - CODE_OF_CONDUCT.md
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/setup
56
+ - lib/loadergif.rb
57
+ - lib/loadergif/config.rb
58
+ - lib/loadergif/version.rb
59
+ - loadergif.gemspec
60
+ homepage: http://rubygems.org/gems/loadergif
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.7.7
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Write a short summary, because RubyGems requires one.
84
+ test_files: []