camaleon_lazy_loader 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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +32 -0
- data/app/helpers/plugins/camaleon_lazy_loader/main_helper.rb +25 -0
- data/config/camaleon_plugin.json +14 -0
- data/config/routes.rb +4 -0
- data/lib/camaleon_lazy_loader.rb +3 -0
- data/lib/camaleon_lazy_loader/engine.rb +4 -0
- data/lib/camaleon_lazy_loader/version.rb +3 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 99d95927998d9190267e103d225c2bd99afcf333d0b38735bf2367b69eabc3f1
|
4
|
+
data.tar.gz: 6df42f838d97c1c86b88800ad1730b24bf426982be90a68ec867ec1d66fd2d92
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d45e431f0c1c0a6d01393437c8bfa2fc7b7f660e51eba0c0e797baef36440cb19a889bb1dfdcce70df5cc92e2225b4916cafd7418c0a73fcfff9f9839ac89913
|
7
|
+
data.tar.gz: 925c55e4794ac8396497d8c70dbd9d3a8fc7b70be044152f0617849ff555e74a92ddb2cf3b65d05d103e77a05b108dbe255f31957eb45c16ce4a424d6542e670
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2020 Brian Kephart
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# CamaleonLazyLoader
|
2
|
+
This plugin adds a `loading="lazy"` attribute to `<img>` and `<iframe>` tags rendered by [Camaleon CMS](https://github.com/owen2345/camaleon-cms).
|
3
|
+
- This attribute will be added to tags on all server-rendered pages.
|
4
|
+
- Existing loading attributes will not be overwritten, so you can still set individual tags to `loading="eager"` or `loading="auto"`
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
Just turn on the plugin in your admin settings.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'camaleon_lazy_loader'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
```bash
|
18
|
+
$ bundle
|
19
|
+
```
|
20
|
+
|
21
|
+
## Contributing
|
22
|
+
- Fork the repo.
|
23
|
+
- Make your changes and add tests as necessary.
|
24
|
+
- Run `standardrb` to lint your code.
|
25
|
+
- Submit a pull request.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
begin
|
2
|
+
require "bundler/setup"
|
3
|
+
rescue LoadError
|
4
|
+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
5
|
+
end
|
6
|
+
|
7
|
+
require "rdoc/task"
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = "rdoc"
|
11
|
+
rdoc.title = "CamaleonLazyLoader"
|
12
|
+
rdoc.options << "--line-numbers"
|
13
|
+
rdoc.rdoc_files.include("README.md")
|
14
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
|
18
|
+
load "rails/tasks/engine.rake"
|
19
|
+
|
20
|
+
load "rails/tasks/statistics.rake"
|
21
|
+
|
22
|
+
require "bundler/gem_tasks"
|
23
|
+
|
24
|
+
require "rake/testtask"
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << "test"
|
28
|
+
t.pattern = "test/**/*_test.rb"
|
29
|
+
t.verbose = false
|
30
|
+
end
|
31
|
+
|
32
|
+
task default: :test
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Plugins::CamaleonLazyLoader::MainHelper
|
2
|
+
def self.included(klass)
|
3
|
+
end
|
4
|
+
|
5
|
+
def clear_front_cache(_plugin)
|
6
|
+
front_cache_clean
|
7
|
+
end
|
8
|
+
|
9
|
+
def apply_lazy_loading(html)
|
10
|
+
doc = Nokogiri::HTML::DocumentFragment.parse html
|
11
|
+
nodes = doc.css "img, iframe"
|
12
|
+
nodes.each { |node| node["loading"] ||= "lazy" }
|
13
|
+
doc.to_html
|
14
|
+
end
|
15
|
+
|
16
|
+
def camaleon_lazy_loader_front_after_load
|
17
|
+
return if @_plugin_do_cache # Do not process when reading from cache.
|
18
|
+
response.body = apply_lazy_loading response.body
|
19
|
+
end
|
20
|
+
|
21
|
+
def camaleon_lazy_loader_front_cache_writing_cache(args)
|
22
|
+
args[:data] = apply_lazy_loading args[:data] # Save processed HTML to cache.
|
23
|
+
response.body = apply_lazy_loading response.body
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
"title": "Camaleon Lazy Loader",
|
3
|
+
"descr": "Adds a browser-native loading=\"lazy\" attribute to images and iframes.",
|
4
|
+
"key": "camaleon_lazy_loader",
|
5
|
+
"helpers": [
|
6
|
+
"Plugins::CamaleonLazyLoader::MainHelper"
|
7
|
+
],
|
8
|
+
"hooks": {
|
9
|
+
"on_active": ["clear_front_cache"],
|
10
|
+
"on_inactive": ["clear_front_cache"],
|
11
|
+
"front_cache_writing_cache": ["camaleon_lazy_loader_front_cache_writing_cache"],
|
12
|
+
"front_after_load": ["camaleon_lazy_loader_front_after_load"]
|
13
|
+
}
|
14
|
+
}
|
data/config/routes.rb
ADDED
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: camaleon_lazy_loader
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Kephart
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: camaleon_cms
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
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: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: standard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Adds browser-native loading="lazy" attribute to images and iframes rendered
|
70
|
+
by Camaleon CMS.
|
71
|
+
email:
|
72
|
+
- briantkephart@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- MIT-LICENSE
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- app/helpers/plugins/camaleon_lazy_loader/main_helper.rb
|
81
|
+
- config/camaleon_plugin.json
|
82
|
+
- config/routes.rb
|
83
|
+
- lib/camaleon_lazy_loader.rb
|
84
|
+
- lib/camaleon_lazy_loader/engine.rb
|
85
|
+
- lib/camaleon_lazy_loader/version.rb
|
86
|
+
homepage: https://github.com/brian-kephart/camaleon_lazy_loader
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - "~>"
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '2.5'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubygems_version: 3.1.2
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Adds browser-native loading="lazy" attribute to images and iframes rendered
|
109
|
+
by Camaleon CMS.
|
110
|
+
test_files: []
|