jekyll-twoxify 1.0.1
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/.gitignore +34 -0
- data/LICENSE.md +26 -0
- data/README.md +87 -0
- data/jekyll-twoxify.gemspec +17 -0
- data/lib/jekyll-twoxify.rb +8 -0
- data/lib/jekyll-twoxify/jekyll-twoxify-tag.rb +32 -0
- data/lib/jekyll-twoxify/version.rb +5 -0
- metadata +67 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 16afe64002ada926a66c0ff341d23731c9433090
|
4
|
+
data.tar.gz: cbeb8c8bcd85699402df27c05d6156bdee9a0885
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 051c424503c877efd94b9a6cb462d156236a66b8661808d82aec15050577efe6b4b47c78c95f3914f8dffbfcda7e3c2e44aa66e0bcb126b8bcc19e6c645b5924
|
7
|
+
data.tar.gz: 345296debb5003362f6a739998ac12289dfba5b206a180ff3fcd3a3412e60101eebd78c9a1dad25a050d6eb8ea6503c022e1ac1437d03a50907cd70e709f278b
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Documentation cache and generated files:
|
17
|
+
/.yardoc/
|
18
|
+
/_yardoc/
|
19
|
+
/doc/
|
20
|
+
/rdoc/
|
21
|
+
|
22
|
+
## Environment normalization:
|
23
|
+
/.bundle/
|
24
|
+
/vendor/bundle
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
Gemfile.lock
|
30
|
+
.ruby-version
|
31
|
+
.ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/LICENSE.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# DON'T BE A DICK PUBLIC LICENSE
|
2
|
+
|
3
|
+
> Version 1.1, December 2016
|
4
|
+
|
5
|
+
> Copyright (C) 2019 WarrantyNowVoid.com
|
6
|
+
|
7
|
+
Everyone is permitted to copy and distribute verbatim or modified
|
8
|
+
copies of this license document.
|
9
|
+
|
10
|
+
> DON'T BE A DICK PUBLIC LICENSE
|
11
|
+
> TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
12
|
+
|
13
|
+
1. Do whatever you like with the original work, just don't be a dick.
|
14
|
+
|
15
|
+
Being a dick includes - but is not limited to - the following instances:
|
16
|
+
|
17
|
+
1a. Outright copyright infringement - Don't just copy the original work/works and change the name.
|
18
|
+
1b. Selling the unmodified original with no work done what-so-ever, that's REALLY being a dick.
|
19
|
+
1c. Modifying the original work to contain hidden harmful content. That would make you a PROPER dick.
|
20
|
+
|
21
|
+
2. If you become rich through modifications, related works/services, or supporting the original work,
|
22
|
+
share the love. Only a dick would make loads off this work and not buy the original work's
|
23
|
+
creator(s) a pint.
|
24
|
+
|
25
|
+
3. Code is provided with no warranty. Using somebody else's code and bitching when it goes wrong makes
|
26
|
+
you a DONKEY dick. Fix the problem yourself. A non-dick would submit the fix back or submit a [bug report](https://www.chiark.greenend.org.uk/~sgtatham/bugs.html)
|
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# Jekyll TwoXify
|
2
|
+
|
3
|
+
Generate the @2x `img` tag `src` and `srcset` (see <https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-srcset>) attributes for a given image path, only including a 2x `srcset` if it exists on the filesystem.
|
4
|
+
|
5
|
+
## Doesn't this seem like overkill for a simple thing?
|
6
|
+
|
7
|
+
Listen, I got really tired of pasting this absolute nonsense into my templates all over the place:
|
8
|
+
|
9
|
+
````
|
10
|
+
{% assign retinaImage = postImage | split: "" | reverse | join: "" | replace_first: '.', '.x2@' | split: "" | reverse | join: "" %}
|
11
|
+
````
|
12
|
+
|
13
|
+
ugggh
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
(https://jekyllrb.com/docs/plugins/installation/)
|
18
|
+
|
19
|
+
One of two options:
|
20
|
+
|
21
|
+
### Bundler Config
|
22
|
+
:warning: **If using bundler with a vendor prefix, this is the required method**
|
23
|
+
|
24
|
+
1. In your `Gemfile`, add the `jekyll_plugins` group if it doesn't already exist, and add `jekyll-twoxify` to it. For example:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
group :jekyll_plugins do
|
28
|
+
gem "jekyll-twoxify"
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
2. Tell bundler to install any plugins with
|
33
|
+
|
34
|
+
```
|
35
|
+
$ bundle install
|
36
|
+
```
|
37
|
+
|
38
|
+
|
39
|
+
### Jekyll Config
|
40
|
+
|
41
|
+
1. In your `_config.yml`, add the `plugins` key if it doesn't already exist, and add a value of `jekyll-twoxify`. For example:
|
42
|
+
|
43
|
+
```yaml
|
44
|
+
plugins:
|
45
|
+
- jekyll-twoxify
|
46
|
+
```
|
47
|
+
|
48
|
+
2. Install this gem
|
49
|
+
|
50
|
+
```
|
51
|
+
$ gem install jekyll-twoxify
|
52
|
+
```
|
53
|
+
|
54
|
+
## Usage
|
55
|
+
|
56
|
+
### Tag
|
57
|
+
|
58
|
+
Add the `twoxify` template tag to any `img` tag in place of both the `src` and `srcset` attributes, with the desired image path. The tag will output the `src` value and, if it exists in the filesystem, the `srcset` attribute with the @2x path. It will automagically prepend the `site.url` to both paths.
|
59
|
+
|
60
|
+
Pass in image as a string:
|
61
|
+
|
62
|
+
```
|
63
|
+
<img {% twoxify "assets/img/mycoolphoto.jpg" %} />
|
64
|
+
```
|
65
|
+
|
66
|
+
If `mycoolphoto@2x.jpg` exists, results in:
|
67
|
+
|
68
|
+
```
|
69
|
+
<img
|
70
|
+
src="https://mycoolwebsite.com/assets/img/mycoolphoto.jpg"
|
71
|
+
srcset="https://mycoolwebsite.com/assets/img/mycoolphoto@2x.jpg 2x" />
|
72
|
+
```
|
73
|
+
|
74
|
+
Else:
|
75
|
+
|
76
|
+
```
|
77
|
+
<img src="https://mycoolwebsite.com/assets/img/mycoolphoto.jpg" />
|
78
|
+
```
|
79
|
+
|
80
|
+
Variables or frontmatter are also supported:
|
81
|
+
|
82
|
+
```
|
83
|
+
<img {% twoxify post.image %} />
|
84
|
+
|
85
|
+
{% assign copied_image = "/assets/wow/numbertwo.png" %}
|
86
|
+
<img {% twoxify copied_image %} />
|
87
|
+
```
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "jekyll-twoxify/version"
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "jekyll-twoxify"
|
7
|
+
spec.summary = "Generate the src and srcset img tag attributes for an image"
|
8
|
+
spec.description = "Jekyll plugin to generate src attribute for an img tag with the given image, and also the srcset with an appropriate @2x path for the image if one exists on the filesystem."
|
9
|
+
spec.version = Jekyll::TwoXify::VERSION
|
10
|
+
spec.authors = ["Nick Pettazzoni"]
|
11
|
+
spec.email = ["pettazz@gmail.com"]
|
12
|
+
spec.homepage = "https://github.com/warrantynowvoid/jekyll-twoxify"
|
13
|
+
spec.licenses = ["Nonstandard"]
|
14
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|spec|features)/!) }
|
15
|
+
spec.require_paths = ["lib"]
|
16
|
+
spec.add_dependency "jekyll", "~> 3.0"
|
17
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module TwoXify
|
3
|
+
class TwoXifyTag < Liquid::Tag
|
4
|
+
|
5
|
+
def initialize(tagName, image_arg, tokens)
|
6
|
+
super
|
7
|
+
@image_arg = image_arg
|
8
|
+
end
|
9
|
+
|
10
|
+
def render(context)
|
11
|
+
# if we pass in something like "post.image.feature" instead of a path,
|
12
|
+
# the variable name gets passed in as a string, so we can look it up in the context
|
13
|
+
image_path = "#{context[@image_arg.strip]}"
|
14
|
+
image_path[0] = "" if image_path[0] == "/"
|
15
|
+
|
16
|
+
site_url = context["site.url"]
|
17
|
+
|
18
|
+
extension = File.extname(image_path)
|
19
|
+
image_path_stripped = File.join(File.dirname(image_path), File.basename(image_path, extension))
|
20
|
+
image_2x_path = "#{image_path_stripped}@2x#{extension}"
|
21
|
+
|
22
|
+
if File.exist?(image_2x_path)
|
23
|
+
"src=\"#{site_url}/#{image_path}\" srcset=\"#{site_url}/#{image_2x_path}\""
|
24
|
+
else
|
25
|
+
"src=\"#{site_url}/#{image_path}\""
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
Liquid::Template.register_tag "twoxify", self
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-twoxify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Pettazzoni
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-17 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: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
description: Jekyll plugin to generate src attribute for an img tag with the given
|
28
|
+
image, and also the srcset with an appropriate @2x path for the image if one exists
|
29
|
+
on the filesystem.
|
30
|
+
email:
|
31
|
+
- pettazz@gmail.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- ".gitignore"
|
37
|
+
- LICENSE.md
|
38
|
+
- README.md
|
39
|
+
- jekyll-twoxify.gemspec
|
40
|
+
- lib/jekyll-twoxify.rb
|
41
|
+
- lib/jekyll-twoxify/jekyll-twoxify-tag.rb
|
42
|
+
- lib/jekyll-twoxify/version.rb
|
43
|
+
homepage: https://github.com/warrantynowvoid/jekyll-twoxify
|
44
|
+
licenses:
|
45
|
+
- Nonstandard
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 2.6.14
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: Generate the src and srcset img tag attributes for an image
|
67
|
+
test_files: []
|