anti_image_reflow 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f44d39bbd484acb93d0a7b81c95aba1487dee78ffbc2becb445f91f6c07a140b
4
+ data.tar.gz: fb3e9c5e592c8069c076c2cf0d3d78fa5fea013b1e65fdcc34b43119310c2d27
5
+ SHA512:
6
+ metadata.gz: 30d7b71050eb05e4d0c7441f257e07ce48bd991a65ab27852c88a308e0ca60a6b3ee8ad2423a80ec50acba1a3aa7e9fa06f9ca2c43e598040df492df40867137
7
+ data.tar.gz: 4d4ce5945808868b276739100f06828915673a2a07dd980b172c4654f640707fbd70c5a3953cecd92625f25e0493ddfa101ae0c3e29aa871eec6714b830c8a90
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-11-27
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at 22395357+Cutwell@users.noreply.github.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # AntiImageReflow
2
+ Lazy load images without reflowing the page.
3
+
4
+ ## Installation
5
+
6
+ Install the gem and add to the application's Gemfile by executing:
7
+
8
+ $ bundle add anti_image_reflow
9
+
10
+ If bundler is not being used to manage dependencies, install the gem by executing:
11
+
12
+ $ gem install anti_image_reflow
13
+
14
+ Once installed, the gem hooks into your build process, and will automatically analyse images and add lazy-loading.
15
+
16
+ ## Usage
17
+
18
+ All images are automatically analysed during build. If a parameter (width, height, loading) is manually set, it will be respected and left unchanged.
19
+
20
+ ## Development
21
+
22
+ 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.
23
+
24
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
25
+
26
+ ## Contributing
27
+
28
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Cutwell/anti_image_reflow. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/Cutwell/anti_image_reflow/blob/master/CODE_OF_CONDUCT.md).
29
+
30
+ ## License
31
+
32
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
33
+
34
+ ## Code of Conduct
35
+
36
+ Everyone interacting in the AntiImageReflow project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Cutwell/anti_image_reflow/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/anti_image_reflow/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "anti_image_reflow"
7
+ spec.version = AntiImageReflow::VERSION
8
+ spec.authors = ["Zachary Smith"]
9
+ spec.email = ["zachsmith.dev@gmail.com"]
10
+
11
+ spec.summary = "Lazy load images without reflowing the page."
12
+ spec.homepage = "https://github.com/cutwell/jekyll-anti-image-reflow"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 2.6.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/cutwell/jekyll-anti-image-reflow"
18
+ spec.metadata["changelog_uri"] = "https://github.com/Cutwell/jekyll-anti-image-reflow/blob/main/CHANGELOG.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ spec.files = Dir["LICENSE.*", "Rakefile", "{lib,spec}/**/*", "*.gemspec", "*.md"]
22
+ spec.test_files = spec.files.grep(%r!^(test|spec|features)/!)
23
+
24
+ spec.platform = Gem::Platform::RUBY
25
+ spec.add_runtime_dependency "jekyll", "~> 4.3"
26
+ spec.add_runtime_dependency "nokogiri", '~> 1.12'
27
+ spec.add_runtime_dependency "fastimage", '~> 2.2'
28
+
29
+ # For more information and examples about making a new gem, check out our
30
+ # guide at: https://bundler.io/guides/creating_gem.html
31
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AntiImageReflow
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "anti_image_reflow/version"
4
+
5
+ require "jekyll"
6
+ require "nokogiri"
7
+ require "fastimage"
8
+
9
+ #module AntiImageReflow
10
+ # class Error < StandardError; end
11
+ # # Your code goes here...
12
+ #end
13
+
14
+ module Jekyll
15
+ class AntiImageReflow
16
+ def self.process(content)
17
+ html = content.output
18
+ content.output = process_tags(html) if process_tags?(html)
19
+ end
20
+
21
+ def self.process?(doc)
22
+ (doc.is_a?(Jekyll::Page) || doc.write?) && doc.output_ext == ".html" || doc.permalink&.end_with?("/")
23
+ end
24
+
25
+ def self.process_tags?(html)
26
+ html.include?("<img") || html.include?("<iframe")
27
+ end
28
+
29
+ def self.process_tags(html)
30
+ content = Nokogiri.HTML(html)
31
+ tags = content.css("img[src]")
32
+
33
+ tags.each do |tag|
34
+ # add height and width attributes
35
+ if tag.name == "img"
36
+ size = FastImage.size(File.join(Dir.pwd, tag["src"]))
37
+ tag["width"] = size[0] unless tag["width"] || size.nil?
38
+ tag["height"] = size[1] unless tag["height"] || size.nil?
39
+ tag["loading"] = "lazy" unless tag["loading"]
40
+ end
41
+ end
42
+
43
+ content.to_html
44
+ end
45
+
46
+ private_class_method :process_tags
47
+ private_class_method :process_tags?
48
+ end
49
+ end
50
+
51
+ Jekyll::Hooks.register [:pages, :documents], :post_render do |doc|
52
+ Jekyll::AntiImageReflow.process(doc) if Jekyll::AntiImageReflow.process?(doc)
53
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: anti_image_reflow
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Zachary Smith
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-11-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: fastimage
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.2'
55
+ description:
56
+ email:
57
+ - zachsmith.dev@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - CHANGELOG.md
63
+ - CODE_OF_CONDUCT.md
64
+ - README.md
65
+ - Rakefile
66
+ - anti_image_reflow.gemspec
67
+ - lib/anti_image_reflow.rb
68
+ - lib/anti_image_reflow/version.rb
69
+ homepage: https://github.com/cutwell/jekyll-anti-image-reflow
70
+ licenses:
71
+ - MIT
72
+ metadata:
73
+ homepage_uri: https://github.com/cutwell/jekyll-anti-image-reflow
74
+ source_code_uri: https://github.com/cutwell/jekyll-anti-image-reflow
75
+ changelog_uri: https://github.com/Cutwell/jekyll-anti-image-reflow/blob/main/CHANGELOG.md
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 2.6.0
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubygems_version: 3.3.24
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Lazy load images without reflowing the page.
95
+ test_files: []