Skip to content

Commit 2ee3087

Browse files
committed
Fix all remaining linting issues
1 parent 1ac6abf commit 2ee3087

File tree

9 files changed

+118
-42
lines changed

9 files changed

+118
-42
lines changed

.gemspec

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# frozen_string_literal: true
22

3-
require_relative 'lib/jekyll-transcode-image-filters/version'
3+
require_relative 'lib/jekyll_transcode_image_filters/version'
44

55
Gem::Specification.new do |spec|
66
spec.name = 'jekyll-transcode-image-filters'
77
spec.version = Jekyll::TranscodeImageFilters::VERSION
8-
spec.date = '2024-12-31'
98
spec.summary = <<~SUMMARY
109
Adds liquid filters to create responsive images and transcode them to browser-friendly formatspec.
1110
SUMMARY
@@ -15,12 +14,12 @@ Gem::Specification.new do |spec|
1514
An optional parameter is available to also resize the image, as an example:
1615
`{{ imagePath | webp: "480x270" }}`
1716
DESCRIPTION
18-
spec.authors = ['Willem \'Jip\' Wijnia']
17+
spec.authors = ["Willem 'Jip' Wijnia"]
1918
spec.files = Dir['lib/**/*']
2019
spec.homepage = 'https://github.com/Garanas/jekyll-transcode-image-filters'
2120
spec.license = 'MIT'
2221

23-
spec.required_ruby_version = '>= 3.0.0'
22+
spec.required_ruby_version = '>= 2.5.0'
2423

2524
spec.add_dependency 'jekyll', '> 3.3', '< 5.0'
2625
spec.add_dependency 'mini_magick', '~> 4.8'

.rubocop.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
inherit_from: .rubocop_todo.yml
2+
3+
Metrics/MethodLength:
4+
Max: 20
5+
6+
AllCops:
7+
Exclude:
8+
- 'spec/**/*'

.rubocop_todo.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This configuration was generated by
2+
# `rubocop --auto-gen-config`
3+
# on 2025-03-03 07:37:46 UTC using RuboCop version 1.18.4.
4+
# The point is for the user to remove these configuration records
5+
# one by one as the offenses are removed from the code base.
6+
# Note that changes in the inspected code, or installation of new
7+
# versions of RuboCop, may require this file to be generated again.
8+
9+
# Offense count: 2
10+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
11+
# IgnoredMethods: refine
12+
Metrics/BlockLength:
13+
Max: 97
14+
15+
# Offense count: 1
16+
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, Regex, IgnoreExecutableScripts, AllowedAcronyms.
17+
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
18+
Naming/FileName:
19+
Exclude:
20+
- 'spec/transcode-image-filters_spec.rb'
21+
22+
# Offense count: 1
23+
# Configuration parameters: AllowedConstants.
24+
Style/Documentation:
25+
Exclude:
26+
- 'spec/**/*'
27+
- 'test/**/*'

lib/jekyll-transcode-image-filters.rb

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,38 @@
44
require 'mini_magick'
55

66
module Jekyll
7+
# Jekyll Image Filters
8+
# =========================
9+
#
10+
# This module provides a set of Liquid filters and tags for creating responsive images in Jekyll.
11+
#
12+
# It allows you to easily generate multiple versions of an image in different formats and resolutions,
13+
# and includes them in your Jekyll site using a simple syntax.
14+
#
15+
# Usage
16+
# -----
17+
#
18+
# To use this module, simply add the following line to your Jekyll site's `Gemfile`:
19+
#
20+
# gem 'jekyll-transcode-image-filters'
21+
#
22+
# Then, in your Jekyll templates, you can use the following Liquid filters and tags:
23+
#
24+
# * `jpg`: Convert an image to JPEG format
25+
# * `webp`: Convert an image to WebP format
26+
# * `avif`: Convert an image to AVIF format
27+
#
28+
# See the documentation for each filter and tag for more information on usage and options.
29+
#
30+
# Contributing
31+
# ------------
32+
#
33+
# Contributions to this module are welcome! Please see the CONTRIBUTING file for more information.
34+
#
35+
# License
36+
# -------
37+
#
38+
# This module is released under the MIT License. See the LICENSE file for more information.
739
module TranscodeImageFilters
840
# Computes a sanitized name for use as a directory.
941
# @param name The (file) name to sanitize.
@@ -30,7 +62,7 @@ def _compute_cache_filename(absolute_path_source, resolution, format)
3062
end
3163

3264
# Compute all necessary paths for the plugin.
33-
# @param absolute_path_site [String] As an example: "C:/jekyll/jekyll-transcode-image-filters"
65+
# @param absolute_path_site [String] As an example: "C:/jekyll/jekyll_transcode_image_filters"
3466
# @param relative_path_source [String] As an example: "/assets/image-a.png" or "/assets/style/main.css"
3567
# @param relative_cache_dir [String] Directory of the cache folder, as an example: "cache/bmp/"
3668
# @param resolution [String] As an example: 900x900
@@ -51,25 +83,30 @@ def _compute_paths(absolute_path_site, relative_path_source, relative_cache_dir,
5183
file_name_destination = _compute_cache_filename(absolute_path_source, resolution, format)
5284

5385
relative_path_cache = File.join(relative_cache_dir, file_name_source_sanitized)
54-
absolute_path_cache = File.join(absolute_path_site, relative_cache_dir, file_name_source_sanitized)
86+
absolute_path_cache = File.join(absolute_path_site, relative_cache_dir,
87+
file_name_source_sanitized)
5588
absolute_path_destination = File.join(absolute_path_cache, file_name_destination)
56-
relative_path_destination = File.join(relative_cache_dir, file_name_source_sanitized, file_name_destination)
57-
58-
[absolute_path_source, absolute_path_destination, absolute_path_cache, file_name_destination,
59-
relative_path_destination, relative_path_cache]
89+
relative_path_destination = File.join(relative_cache_dir, file_name_source_sanitized,
90+
file_name_destination)
91+
92+
[
93+
absolute_path_source, absolute_path_destination,
94+
absolute_path_cache, file_name_destination,
95+
relative_path_destination, relative_path_cache
96+
]
6097
end
6198

6299
# Determine whether the file exists in the cache.
63-
# @param absolute_path_source [String] As an example: "C:/jekyll/jekyll-transcode-image-filters"
100+
# @param absolute_path_source [String] As an example: "C:/jekyll"
64101
# @param absolute_path_destination [String] As an example: "/assets/image-a.png" or "/assets/image-a.bmp"
65102
# @return [Boolean] If true, the file exists in the cache.
66103
def _in_cache?(_absolute_path_source, absolute_path_destination)
67104
File.exist?(absolute_path_destination)
68105
end
69106

70107
# Read, process, and write the (new) image to disk.
71-
# @param absolute_path_source [String] As an example: "C:/jekyll/jekyll-transcode-image-filters/assets/image-a.png"
72-
# @param absolute_path_destination [String] As an example: "C:/jekyll/jekyll-transcode-image-filters/assets/image-a-processed.png"
108+
# @param absolute_path_source [String] As an example: "C:/jekyll/assets/image-a.png"
109+
# @param absolute_path_destination [String] As an example: "C:/jekyll/assets/image-a-processed.png"
73110
def _process_img(absolute_path_source, absolute_path_destination, resolution, format)
74111
image = MiniMagick::Image.open(absolute_path_source)
75112
initial_size = image.size
@@ -86,7 +123,8 @@ def _process_img(absolute_path_source, absolute_path_destination, resolution, fo
86123

87124
image.write absolute_path_destination
88125

89-
puts "Transcoded image '#{absolute_path_source}' to '#{absolute_path_destination}' (#{initial_size / 1024}kb -> #{image.size / 1024}kb)"
126+
statistics = "#{initial_size / 1024}kb -> #{image.size / 1024}kb"
127+
puts "Transcoded image '#{absolute_path_source}' to '#{absolute_path_destination}' (#{statistics})"
90128
end
91129

92130
# Transcodes an image to the given format and resolution. Processed files are cached to speed up builds.
@@ -98,24 +136,24 @@ def _process_img(absolute_path_source, absolute_path_destination, resolution, fo
98136
def _transcode_image(relative_source_path, cache_dir, resolution, format)
99137
site = @context.registers[:site]
100138

101-
absolute_path_source, absolute_path_destination, absolute_path_cache, file_name_destination, relative_path_destination, relative_path_cache = _compute_paths(
139+
absolute_path_source,
140+
absolute_path_destination,
141+
absolute_path_cache,
142+
file_name_destination,
143+
relative_path_destination,
144+
relative_path_cache = _compute_paths(
102145
site.source, relative_source_path, cache_dir, resolution, format
103146
)
104147

105148
# Guarantee the existence of the cache directory
106149
FileUtils.mkdir_p(absolute_path_cache)
107150

108-
if _in_cache?(absolute_path_source, absolute_path_destination)
109-
# if the file is cached and valid we can just return the relative path
110-
return relative_path_destination
111-
else
112-
# otherwise, we process the file and add it to the cache
113-
114-
_process_img(absolute_path_source, absolute_path_destination, resolution, format)
115-
site.static_files << Jekyll::StaticFile.new(site, site.source, relative_path_cache, file_name_destination)
116-
end
151+
# if the file is cached and valid we can just return the relative path
152+
return relative_path_destination if _in_cache?(absolute_path_source, absolute_path_destination)
117153

118-
relative_path_destination
154+
# otherwise, we process the file and add it to the cache
155+
_process_img(absolute_path_source, absolute_path_destination, resolution, format)
156+
site.static_files << Jekyll::StaticFile.new(site, site.source, relative_path_cache, file_name_destination)
119157
end
120158

121159
# Transcodes an image to the webp format in the given resolution. Processed files are cached to speed up builds.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# frozen_string_literal: true
2+
3+
require 'jekyll/transcode_image_filters'
File renamed without changes.

spec/spec_helper.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
require 'jekyll'
44
require 'mini_magick'
5-
require File.expand_path('../lib/jekyll-transcode-image-filters', __dir__)
5+
require File.expand_path('../lib/jekyll_transcode_image_filters', __dir__)
66

77
Jekyll.logger.log_level = :error
88

9+
SOURCE_DIR = File.expand_path('fixture', __dir__)
10+
DEST_DIR = File.expand_path('dest', __dir__)
11+
912
RSpec.configure do |config|
1013
config.run_all_when_everything_filtered = true
1114
config.filter_run :focus
@@ -16,9 +19,6 @@
1619
FileUtils.rm_rf(File.join(SOURCE_DIR, 'cache'))
1720
end
1821

19-
SOURCE_DIR = File.expand_path('fixture', __dir__)
20-
DEST_DIR = File.expand_path('dest', __dir__)
21-
2222
def source_dir(*files)
2323
File.join(SOURCE_DIR, *files)
2424
end

spec/transcode-image-filters_spec.rb

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@
55
describe(Jekyll::TranscodeImageFilters) do
66
let(:overrides) { {} }
77
let(:config) do
8-
Jekyll.configuration(Jekyll::Utils.deep_merge_hashes({
9-
'full_rebuild' => true,
10-
'source' => source_dir,
11-
'destination' => dest_dir,
12-
'url' => 'https://jipwijnia.nl',
13-
'name' => 'My awesome test',
14-
'author' => {
15-
'name' => 'Dr. Jekyll'
16-
}
17-
}, overrides))
8+
Jekyll.configuration(
9+
Jekyll::Utils.deep_merge_hashes(
10+
{
11+
'full_rebuild' => true,
12+
'source' => source_dir,
13+
'destination' => dest_dir,
14+
'url' => 'https://jipwijnia.nl',
15+
'name' => 'My awesome test',
16+
'author' => {
17+
'name' => 'Dr. Jekyll'
18+
}
19+
}, overrides
20+
)
21+
)
1822
end
1923
let(:site) { Jekyll::Site.new(config) }
2024
let(:jekyll_env) { 'development' }

0 commit comments

Comments
 (0)