middleman-img_loading_attribute 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7f0831a8d271dcd98cfc41948cfa839204aae015014d530ca3efb877ce70cabe
4
+ data.tar.gz: 2965a6c2565dae62b6a89be74e21166c47242269447ac3362b7c51ee1c55290a
5
+ SHA512:
6
+ metadata.gz: e152afaa28bc1987cf2639b17cca8eaf1b2b395b692ca44964dde73eaf42311b61fd3124e7379853c1e2c4822401d276a78d101c701668a277942db18fb1f5ce
7
+ data.tar.gz: d3076107ad3d7d09dd28813d0b715d6c5d67051df6eecb5a7de5cd0d827b13eae32ade1cde561a24dbf416637c00667a50fcbb9df2869e76da2b5477887cb60c
@@ -0,0 +1,29 @@
1
+ name: test
2
+ on:
3
+ push:
4
+ branches:
5
+ - master
6
+ pull_request:
7
+ branches:
8
+ - '*'
9
+ schedule:
10
+ - cron: '0 0 * * 0'
11
+ jobs:
12
+ build:
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ matrix:
16
+ ruby: ['2.6.x', '2.5.x', '2.4.x']
17
+ name: Ruby ${{ matrix.ruby }}
18
+ steps:
19
+ - uses: actions/checkout@master
20
+ - name: Setup ruby ${{ matrix.ruby }}
21
+ uses: actions/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+ architecture: 'x64'
25
+ - name: Build and test with Rake
26
+ run: |
27
+ gem install bundler
28
+ bundle install --jobs 4 --retry 3
29
+ bundle exec rake test
@@ -0,0 +1,5 @@
1
+ # Ignore bundler lock file
2
+ /Gemfile.lock
3
+
4
+ # Ignore pkg folder
5
+ /pkg
@@ -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 yusuke1994525@gmail.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,19 @@
1
+ # If you do not have OpenSSL installed, update
2
+ # the following line to use "http://" instead
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in middleman-img_loading_attribute.gemspec
6
+ gemspec
7
+
8
+ group :development do
9
+ gem 'rake'
10
+ gem 'rdoc'
11
+ gem 'yard'
12
+ end
13
+
14
+ group :test do
15
+ gem 'cucumber'
16
+ gem 'aruba'
17
+ gem 'rspec'
18
+ gem 'capybara'
19
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Yusuke Nakamura
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.
@@ -0,0 +1,64 @@
1
+ # Middleman::ImgLoadingAttribute
2
+ [![Build Status on GitHub Actions](https://github.com/unasuke/middleman-img_loading_attribute/workflows/test/badge.svg)](https://github.com/unasuke/redcarpet-render-html_lazy_img/actions)
3
+ ![RubyGem version](https://badgen.net/rubygems/v/middleman-img_loading_attribute)
4
+ ![MIT License](https://badgen.net/github/license/unasuke/middleman-img_loading_attribute)
5
+
6
+ Specify "loading" attribute value to generated HTML from Middleman
7
+ You can choose "lazy", "auto", and "eager" to loading attribite by configuration.
8
+
9
+ ## Installation
10
+ Add this line to your Middleman project's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'middleman-img_loading_attribute'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ ```shell
19
+ $ bundle
20
+ ```
21
+
22
+ ## Usage
23
+ Activate `img_loading_attribute` in your `config.rb`.
24
+
25
+ ### loading="lazy"
26
+ ```ruby
27
+ activate :img_loading_attribute do |c|
28
+ c.loading = 'lazy'
29
+ end
30
+ ```
31
+
32
+ ### loading="auto"
33
+ ```ruby
34
+ activate :img_loading_attribute do |c|
35
+ c.loading = 'auto'
36
+ end
37
+
38
+ # If no configuration specified, choose "auto" as default value
39
+ activate :img_loading_attribute
40
+ ```
41
+
42
+ ### loading="eager"
43
+ ```ruby
44
+ activate :img_loading_attribute do |c|
45
+ c.loading = 'eager'
46
+ end
47
+ ```
48
+
49
+ ## Development
50
+
51
+
52
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in gemspec, 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).
53
+
54
+ ## Contributing
55
+
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/unasuke/middleman-img_loading_attribute. 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.
57
+
58
+ ## License
59
+
60
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
61
+
62
+ ## Code of Conduct
63
+
64
+ Everyone interacting in the Redcarpet::Render::HTMLLazyImg project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/unasuke/middleman-img_loading_attribute/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,14 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'cucumber/rake/task'
5
+
6
+ Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
7
+ t.cucumber_opts = '--color --tags ~@wip --strict'
8
+ end
9
+
10
+ require 'rake/clean'
11
+
12
+ task test: ['cucumber']
13
+
14
+ task default: :test
@@ -0,0 +1,8 @@
1
+ Feature: Auto
2
+ Scenario: Should add 'auto'
3
+ Given a successfully built app at "auto-app"
4
+ When I cd to "build"
5
+ Then the file "index.html" should contain:
6
+ """
7
+ <img loading="auto"
8
+ """
@@ -0,0 +1,8 @@
1
+ Feature: Auto
2
+ Scenario: Should add 'eager'
3
+ Given a successfully built app at "eager-app"
4
+ When I cd to "build"
5
+ Then the file "index.html" should contain:
6
+ """
7
+ <img loading="eager" src="/images/1x1.png"
8
+ """
@@ -0,0 +1,8 @@
1
+ Feature: Lazy
2
+ Scenario: Should add 'lazy'
3
+ Given a successfully built app at "lazy-app"
4
+ When I cd to "build"
5
+ Then the file "index.html" should contain:
6
+ """
7
+ <img loading="lazy" src="/images/1x1-0ec63b14.png"
8
+ """
@@ -0,0 +1,8 @@
1
+ Given /^a built app$/ do
2
+ step %{I run `middleman build --verbose`}
3
+ end
4
+
5
+ Given /^a successfully built app$/ do
6
+ step %{a built app}
7
+ step %{was successfully built}
8
+ end
@@ -0,0 +1,4 @@
1
+ PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
2
+ require 'middleman-core'
3
+ require 'middleman-core/step_definitions'
4
+ require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-img_loading_attribute')
@@ -0,0 +1 @@
1
+ activate :img_loading_attribute
@@ -0,0 +1 @@
1
+ <%= image_tag 'https://example.com.example.jpg' %>
@@ -0,0 +1,9 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Test App</title>
5
+ </head>
6
+ <body>
7
+ <%= yield %>
8
+ </body>
9
+ </html>
@@ -0,0 +1,3 @@
1
+ activate :img_loading_attribute do |c|
2
+ c.loading = 'eager'
3
+ end
@@ -0,0 +1 @@
1
+ <%= image_tag '1x1.png' %>
@@ -0,0 +1,9 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Test App</title>
5
+ </head>
6
+ <body>
7
+ <%= yield %>
8
+ </body>
9
+ </html>
@@ -0,0 +1,4 @@
1
+ activate :asset_hash
2
+ activate :img_loading_attribute do |c|
3
+ c.loading = 'lazy'
4
+ end
@@ -0,0 +1 @@
1
+ <%= image_tag '1x1.png' %>
@@ -0,0 +1,9 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Test App</title>
5
+ </head>
6
+ <body>
7
+ <%= yield %>
8
+ </body>
9
+ </html>
@@ -0,0 +1,6 @@
1
+ require "middleman-core"
2
+
3
+ Middleman::Extensions.register :img_loading_attribute do
4
+ require "middleman-img_loading_attribute/extension"
5
+ ::Middleman::ImgLoadingAttribute
6
+ end
@@ -0,0 +1,41 @@
1
+ # Require core library
2
+ require 'middleman-core'
3
+
4
+ class Middleman::ImgLoadingAttribute < ::Middleman::Extension
5
+ option :loading, 'auto', 'A value of "loading" attribute in <img> tag'
6
+
7
+ def initialize(app, options_hash={}, &block)
8
+ # Call super to build options from the options_hash
9
+ super
10
+
11
+ # Require libraries only when activated
12
+ # require 'necessary/library'
13
+
14
+ # set up your extension
15
+ # puts options.my_option
16
+ end
17
+
18
+ def after_configuration
19
+ # Do something
20
+ end
21
+
22
+ def after_build(builder)
23
+ files = Dir.glob(File.join(app.config[:build_dir], "**", "*.html"))
24
+ files.each do |file|
25
+ contents = File.read(file)
26
+ replaced = contents.gsub(%r[<img], "<img loading=\"#{options[:loading]}\"")
27
+ File.open(file, 'w') do |f|
28
+ f.write replaced
29
+ end
30
+ end
31
+ end
32
+
33
+ # A Sitemap Manipulator
34
+ # def manipulate_resource_list(resources)
35
+ # end
36
+
37
+ # helpers do
38
+ # def a_helper
39
+ # end
40
+ # end
41
+ end
@@ -0,0 +1,24 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "middleman-img_loading_attribute"
5
+ s.version = "0.1.0"
6
+ s.platform = Gem::Platform::RUBY
7
+ s.authors = ["Yusuke Nakamura"]
8
+ s.email = ['yusuke1994525@gmail.com']
9
+ s.homepage = 'https://github.com/unasuke/middleman-img_loading_attribute'
10
+ s.summary = 'Specify "loading" attribute value to generated HTML from middleman'
11
+ s.description = 'Specify "loading" attribute value to generated HTML from middleman'
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.require_paths = ["lib"]
17
+
18
+ # The version of middleman-core your extension depends on
19
+ s.add_runtime_dependency("middleman-core")
20
+ s.add_runtime_dependency("middleman-cli")
21
+
22
+ # Additional dependencies
23
+ # s.add_runtime_dependency("gem-name", "gem-version")
24
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-img_loading_attribute
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yusuke Nakamura
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-11-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: middleman-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: middleman-cli
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Specify "loading" attribute value to generated HTML from middleman
42
+ email:
43
+ - yusuke1994525@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".github/workflows/ruby.yml"
49
+ - ".gitignore"
50
+ - CODE_OF_CONDUCT.md
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - features/auto.feature
56
+ - features/eager.feature
57
+ - features/lazy.feature
58
+ - features/step_definitions/builder_steps.rb
59
+ - features/support/env.rb
60
+ - fixtures/auto-app/config.rb
61
+ - fixtures/auto-app/source/index.html.erb
62
+ - fixtures/auto-app/source/layout.erb
63
+ - fixtures/eager-app/config.rb
64
+ - fixtures/eager-app/source/images/1x1.png
65
+ - fixtures/eager-app/source/index.html.erb
66
+ - fixtures/eager-app/source/layout.erb
67
+ - fixtures/lazy-app/config.rb
68
+ - fixtures/lazy-app/source/images/1x1.png
69
+ - fixtures/lazy-app/source/index.html.erb
70
+ - fixtures/lazy-app/source/layout.erb
71
+ - lib/middleman-img_loading_attribute.rb
72
+ - lib/middleman-img_loading_attribute/extension.rb
73
+ - middleman-img_loading_attribute.gemspec
74
+ homepage: https://github.com/unasuke/middleman-img_loading_attribute
75
+ licenses: []
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubygems_version: 3.0.3
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Specify "loading" attribute value to generated HTML from middleman
96
+ test_files:
97
+ - features/auto.feature
98
+ - features/eager.feature
99
+ - features/lazy.feature
100
+ - features/step_definitions/builder_steps.rb
101
+ - features/support/env.rb