pax_global_header 0000666 0000000 0000000 00000000064 14226244076 0014521 g ustar 00root root 0000000 0000000 52 comment=4e12e7b55f24fc3e0c20ae494d0ef35d33745353
jekyll-avatar-0.8.0/ 0000775 0000000 0000000 00000000000 14226244076 0014274 5 ustar 00root root 0000000 0000000 jekyll-avatar-0.8.0/.github/ 0000775 0000000 0000000 00000000000 14226244076 0015634 5 ustar 00root root 0000000 0000000 jekyll-avatar-0.8.0/.github/workflows/ 0000775 0000000 0000000 00000000000 14226244076 0017671 5 ustar 00root root 0000000 0000000 jekyll-avatar-0.8.0/.github/workflows/ci.yml 0000664 0000000 0000000 00000001206 14226244076 0021006 0 ustar 00root root 0000000 0000000 name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
name: "Test Jekyll ${{ matrix.jekyll-version }} (Ruby ${{ matrix.ruby-version }})"
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.7', '3.0']
jekyll-version: ["~> 3.0", "~> 4.0"]
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true
env:
JEKYLL_VERSION: ${{ matrix.jekyll-version }}
- name: Run tests
run: script/cibuild
jekyll-avatar-0.8.0/.github/workflows/release.yml 0000664 0000000 0000000 00000001451 14226244076 0022035 0 ustar 00root root 0000000 0000000 name: Release Gem
on:
push:
branches:
- main
paths:
- "lib/**/version.rb"
jobs:
release:
if: "github.repository_owner == 'jekyll'"
name: "Release Gem (Ruby ${{ matrix.ruby_version }})"
runs-on: "ubuntu-latest"
strategy:
fail-fast: true
matrix:
ruby_version:
- 2.7
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: "Set up Ruby ${{ matrix.ruby_version }}"
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby_version }}
bundler-cache: true
- name: Build and Publish Gem
uses: ashmaroli/release-gem@dist
with:
gemspec_name: jekyll-avatar
env:
GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_GEM_PUSH_API_KEY }}
jekyll-avatar-0.8.0/.gitignore 0000664 0000000 0000000 00000000135 14226244076 0016263 0 ustar 00root root 0000000 0000000 /.bundle/
/.yardoc
/Gemfile.lock
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
*.gem
jekyll-avatar-0.8.0/.rspec 0000664 0000000 0000000 00000000037 14226244076 0015411 0 ustar 00root root 0000000 0000000 --format documentation
--color
jekyll-avatar-0.8.0/.rubocop.yml 0000664 0000000 0000000 00000000310 14226244076 0016540 0 ustar 00root root 0000000 0000000 inherit_from: .rubocop_todo.yml
require:
- rubocop-jekyll
- rubocop-rspec
inherit_gem:
rubocop-jekyll: .rubocop.yml
AllCops:
NewCops: enable
Exclude:
- script/**/*
- vendor/**/*
jekyll-avatar-0.8.0/.rubocop_todo.yml 0000664 0000000 0000000 00000002207 14226244076 0017574 0 ustar 00root root 0000000 0000000 # This configuration was generated by
# `rubocop --auto-gen-config`
# on 2021-09-16 18:53:19 UTC using RuboCop version 1.18.4.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 1
# Configuration parameters: AllowComments.
Lint/EmptyClass:
Exclude:
- 'lib/jekyll-avatar/version.rb'
# Offense count: 3
# Configuration parameters: Prefixes.
# Prefixes: when, with, without
RSpec/ContextWording:
Exclude:
- 'spec/jekyll/avatar_spec.rb'
# Offense count: 3
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 11
# Offense count: 15
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 18
# Offense count: 17
# Configuration parameters: IgnoreSharedExamples.
RSpec/NamedSubject:
Exclude:
- 'spec/jekyll/avatar_spec.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: Methods.
Style/RedundantArgument:
Exclude:
- 'lib/jekyll-avatar.rb'
jekyll-avatar-0.8.0/Gemfile 0000664 0000000 0000000 00000000232 14226244076 0015564 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
source "https://rubygems.org"
gemspec
gem "jekyll", ENV["JEKYLL_VERSION"] if ENV["JEKYLL_VERSION"]
gem "memory_profiler"
jekyll-avatar-0.8.0/History.markdown 0000664 0000000 0000000 00000002127 14226244076 0017503 0 ustar 00root root 0000000 0000000 ## 0.8.0 / 2022-04-15
### Minor Enhancements
* Use `Kernel#format` to render `
` HTML tag (#46)
* Check if username and size matches a pattern once (#48)
### Bug Fixes
* Reduce allocations from computing username (#44)
* Stringify keys of `:attributes` hash (#42)
* Parse tag markup once per instance (#40)
* Compute `:srcset` with an array of integer strings (#43)
* Assign string values for attributes (#47)
* Parse only custom-host provided through ENV (#45)
### Development Fixes
* Profile memory usage from rendering avatars (#41)
* Bundle only relevant files in the gem (#50)
* Upgrade to GitHub-native Dependabot (#52)
* Remove redundant specifications (#56)
* Improve context in workflow job names (#57)
* Remove `@benbalter`-specific community health files (#58)
* Update gem specification (#60)
* Add workflow to release gem via GH Actions (#63)
### Documentation
* Fix typo in README.md (#62)
## 0.7.0 / 2019-08-12
Refer [`v0.7.0` Release Note](https://github.com/jekyll/jekyll-avatar/releases/tag/v0.7.0) to see
what changed since previous release.
jekyll-avatar-0.8.0/LICENSE.txt 0000664 0000000 0000000 00000002065 14226244076 0016122 0 ustar 00root root 0000000 0000000 The MIT License (MIT)
Copyright (c) 2016 Ben Balter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
jekyll-avatar-0.8.0/README.md 0000664 0000000 0000000 00000006067 14226244076 0015564 0 ustar 00root root 0000000 0000000 # Jekyll Avatar
*A Jekyll plugin for rendering GitHub avatars*
[](https://github.com/jekyll/jekyll-avatar/actions/workflows/ci.yml)
Jekyll Avatar makes it easy to add GitHub avatars to your Jekyll site by specifying a username. If performance is a concern, Jekyll Avatar is deeply integrated with the GitHub avatar API, ensuring avatars are cached and load in parallel. It even automatically upgrades users to Retina images, when supported.
## Installation
Add the following to your site's `Gemfile`:
```ruby
gem 'jekyll-avatar'
```
And add the following to your site's `_config.yml` file:
```yaml
plugins:
- jekyll-avatar
```
Note: If you are using a Jekyll version less than 3.5.0, use the `gems` key instead of `plugins`.
## Usage
Simply add the following, anywhere you'd like a user's avatar to appear:
```
{% avatar [USERNAME] %}
```
With `[USERNAME]` being the user's GitHub username:
```
{% avatar hubot %}
```
That will output:
```html
```
### Customizing
You can customize the size of the resulting avatar by passing the size argument:
```
{% avatar hubot size=50 %}
```
That will output:
```html
```
### Passing the username as variable
You can also pass the username as a variable, like this:
```
{% assign user="hubot" %}
{% avatar {{ user }} %}
```
Or, if the variable is someplace a bit more complex, like a loop:
```
{% assign employees = "alice|bob" | split:"|" %}
{% for employee in employees %}
{% avatar user=employee %}
{% endfor %}
```
### Lazy loading images
For pages showing a large number of avatars, you may want to load the images lazily.
```liquid
{% avatar hubot lazy=true %}
```
This will set the `data-src` and `data-srcset` attributes on the `
` tag, which is compatible with many lazy load JavaScript plugins, such as:
* https://www.andreaverlicchi.eu/lazyload/
* https://appelsiini.net/projects/lazyload/
### Using with GitHub Enterprise
To use Jekyll Avatars with GitHub Enterprise, you must set the `PAGES_AVATARS_URL` environmental variable.
This should be the full URL to the avatars subdomain or subpath. For example:
* With subdomain isolation: `PAGES_AVATARS_URL="https://avatars.github.example.com"`
* Without subdomain isolation: `PAGES_AVATARS_URL="https://github.example.com/avatars"`
jekyll-avatar-0.8.0/docs/ 0000775 0000000 0000000 00000000000 14226244076 0015224 5 ustar 00root root 0000000 0000000 jekyll-avatar-0.8.0/docs/CODE_OF_CONDUCT.md 0000664 0000000 0000000 00000006213 14226244076 0020025 0 ustar 00root root 0000000 0000000 # Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
Project maintainers 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, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at ben@balter.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
jekyll-avatar-0.8.0/docs/CONTRIBUTING.md 0000664 0000000 0000000 00000013150 14226244076 0017455 0 ustar 00root root 0000000 0000000 # Contributing to Jekyll Avatar
Hi there! We're thrilled that you'd like to contribute to Jekyll Avatar. Your help is essential for keeping it great.
Jekyll Avatar is an open source project supported by the efforts of an entire community and built one contribution at a time by users like you. We'd love for you to get involved. Whatever your level of skill or however much time you can give, your contribution is greatly appreciated. There are many ways to contribute, from writing tutorials or blog posts, improving the documentation, submitting bug reports and feature requests, helping other users by commenting on issues, or writing code which can be incorporated into Jekyll Avatar itself.
Following these guidelines helps to communicate that you respect the time of the developers managing and developing this open source project. In return, they should reciprocate that respect in addressing your issue, assessing changes, and helping you finalize your pull requests.
## How to report a bug
Think you found a bug? Please check [the list of open issues](https://github.com/benbalter/jekyll-avatar/issues) to see if your bug has already been reported. If it hasn't please [submit a new issue](https://github.com/benbalter/jekyll-avatar/issues/new).
Here are a few tips for writing *great* bug reports:
* Describe the specific problem (e.g., "widget doesn't turn clockwise" versus "getting an error")
* Include the steps to reproduce the bug, what you expected to happen, and what happened instead
* Check that you are using the latest version of the project and its dependencies
* Include what version of the project your using, as well as any relevant dependencies
* Only include one bug per issue. If you have discovered two bugs, please file two issues
* Include screenshots or screencasts whenever possible
* Even if you don't know how to fix the bug, including a failing test may help others track it down
**If you find a security vulnerability, do not open an issue. Please email ben@balter.com instead.**
## How to suggest a feature or enhancement
If you find yourself wishing for a feature that doesn't exist in Jekyll Avatar, you are probably not alone. There are bound to be others out there with similar needs. Many of the features that Jekyll Avatar has today have been added because our users saw the need.
Feature requests are welcome. But take a moment to find out whether your idea fits with the scope and goals of the project. It's up to you to make a strong case to convince the project's developers of the merits of this feature. Please provide as much detail and context as possible, including describing the problem you're trying to solve.
[Open an issue](https://github.com/benbalter/jekyll-avatar/issues/new) which describes the feature you would like to see, why you want it, how it should work, etc.
## Your first contribution
We'd love for you to contribute to the project. Unsure where to begin contributing to Jekyll Avatar? You can start by looking through these "good first issue" and "help wanted" issues:
* [Good first issues](https://github.com/benbalter/jekyll-avatar/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) - issues which should only require a few lines of code and a test or two
* [Help wanted issues](https://github.com/benbalter/jekyll-avatar/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) - issues which may be a bit more involved, but are specifically seeking community contributions
*p.s. Feel free to ask for help; everyone is a beginner at first* :smiley_cat:
## How to propose changes
Here's a few general guidelines for proposing changes:
* If you are changing any user-facing functionality, please be sure to update the documentation
* If you are adding a new behavior or changing an existing behavior, please be sure to update the corresponding test(s)
* Each pull request should implement **one** feature or bug fix. If you want to add or fix more than one thing, submit more than one pull request
* Do not commit changes to files that are irrelevant to your feature or bug fix
* Don't bump the version number in your pull request (it will be bumped prior to release)
* Write [a good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)
At a high level, [the process for proposing changes](https://guides.github.com/introduction/flow/) is:
1. [Fork](https://github.com/benbalter/jekyll-avatar/fork) and clone the project
2. Configure and install the dependencies: `script/bootstrap`
3. Make sure the tests pass on your machine: `script/cibuild`
4. Create a descriptively named branch: `git checkout -b my-branch-name`
5. Make your change, add tests and documentation, and make sure the tests still pass
6. Push to your fork and [submit a pull request](https://github.com/benbalter/jekyll-avatar/compare) describing your change
7. Pat your self on the back and wait for your pull request to be reviewed and merged
**Interesting in submitting your first Pull Request?** It's easy! You can learn how from this *free* series [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github)
## Bootstrapping your local development environment
`script/bootstrap`
## Running tests
`script/cibuild`
## Code of conduct
This project is governed by [the Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code.
## Additional Resources
* [Contributing to Open Source on GitHub](https://guides.github.com/activities/contributing-to-open-source/)
* [Using Pull Requests](https://help.github.com/articles/using-pull-requests/)
* [GitHub Help](https://help.github.com)
jekyll-avatar-0.8.0/jekyll-avatar.gemspec 0000664 0000000 0000000 00000002015 14226244076 0020405 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require_relative "lib/jekyll-avatar/version"
Gem::Specification.new do |spec|
spec.name = "jekyll-avatar"
spec.version = Jekyll::Avatar::VERSION
spec.authors = ["Ben Balter"]
spec.email = ["ben.balter@github.com"]
spec.summary = "A Jekyll plugin for rendering GitHub avatars"
spec.homepage = "https://github.com/jekyll/jekyll-avatar"
spec.license = "MIT"
spec.files = `git ls-files lib`.split("\n").concat(%w(LICENSE.txt README.md))
spec.require_paths = ["lib"]
spec.required_ruby_version = ">= 2.5.0"
spec.add_dependency "jekyll", ">= 3.0", "< 5.0"
spec.add_development_dependency "bundler", "> 1.0", "< 3.0"
spec.add_development_dependency "kramdown-parser-gfm", "~> 1.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "rspec-html-matchers", "~> 0.9"
spec.add_development_dependency "rubocop-jekyll", "~> 0.12.0"
spec.add_development_dependency "rubocop-rspec", "~> 2.0"
end
jekyll-avatar-0.8.0/lib/ 0000775 0000000 0000000 00000000000 14226244076 0015042 5 ustar 00root root 0000000 0000000 jekyll-avatar-0.8.0/lib/jekyll-avatar.rb 0000664 0000000 0000000 00000007355 14226244076 0020147 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "zlib"
module Jekyll
class Avatar < Liquid::Tag
def self.generate_template_with(keys)
attrs = (BASE_ATTRIBUTES + keys).map! { |key| %(#{key}="%<#{key}>s") }.join(" ")
"
"
end
private_class_method :generate_template_with
#
SERVERS = 4
DEFAULT_SIZE = "40"
API_VERSION = "3"
BASE_ATTRIBUTES = %w(
class alt width height data-proofer-ignore src
).freeze
BASE_TEMPLATE = generate_template_with %w(srcset)
LAZY_TEMPLATE = generate_template_with %w(data-src data-srcset)
private_constant :BASE_ATTRIBUTES, :BASE_TEMPLATE, :LAZY_TEMPLATE
def initialize(_tag_name, text, _tokens)
super
@text = text.strip
@markup = Liquid::Template.parse(@text)
@size = compute_size
@user_variable = extract_user_variable
@custom_host = ENV["PAGES_AVATARS_URL"]
@custom_host = "" unless @custom_host.is_a?(String)
end
def render(context)
@context = context
@text = @markup.render(@context)
template = lazy_load? ? LAZY_TEMPLATE : BASE_TEMPLATE
format(template, attributes)
end
private
def attributes
result = {
:class => classes,
:alt => username,
:width => size,
:height => size,
:"data-proofer-ignore" => "true",
}
if lazy_load?
result[:src] = ""
result[:"data-src"] = url
result[:"data-srcset"] = srcset
else
result[:src] = url
result[:srcset] = srcset
end
result
end
def lazy_load?
@text.include?("lazy=true")
end
def extract_user_variable
matches = @text.match(%r!\buser=([\w.]+)\b!)
matches[1] if matches
end
def username
return lookup_variable(@user_variable) if @user_variable
result = @text.include?(" ") ? @text.split(" ")[0] : @text
result.start_with?("@") ? result.sub("@", "") : result
end
# Lookup a Liquid variable in the current context.
#
# variable - the variable name, as a string.
#
# Returns the value of the variable in the context or the variable name if not found.
def lookup_variable(variable)
lookup = @context
if variable.include?(".")
variable.split(".").each do |value|
lookup = lookup[value]
end
else
lookup = lookup[variable]
end
lookup || variable
end
# Returns a string value
def compute_size
matches = @text.match(%r!\bsize=(\d+)\b!i)
matches ? matches[1] : DEFAULT_SIZE
end
attr_reader :size
def path(scale = 1)
"#{username}?v=#{API_VERSION}&s=#{scale == 1 ? size : (size.to_i * scale)}"
end
def server_number
Zlib.crc32(path) % SERVERS
end
def host
if @custom_host.empty?
"https://avatars#{server_number}.githubusercontent.com"
else
@custom_host
end
end
def parsed_host
@parsed_host ||= {}
@parsed_host[host] ||= Addressable::URI.parse(host)
end
def url_with_custom_host(scale = 1)
uri = parsed_host
uri.path << "/" unless uri.path.end_with?("/")
uri = uri.join path(scale)
uri.to_s
end
def url(scale = 1)
return url_with_custom_host(scale) unless @custom_host.empty?
"#{host}/#{path(scale)}"
end
SCALES = %w(1 2 3 4).freeze
private_constant :SCALES
def srcset
SCALES.map { |scale| "#{url(scale.to_i)} #{scale}x" }.join(", ")
end
# See http://primercss.io/avatars/#small-avatars
def classes
size.to_i < 48 ? "avatar avatar-small" : "avatar"
end
end
end
Liquid::Template.register_tag("avatar", Jekyll::Avatar)
jekyll-avatar-0.8.0/lib/jekyll-avatar/ 0000775 0000000 0000000 00000000000 14226244076 0017610 5 ustar 00root root 0000000 0000000 jekyll-avatar-0.8.0/lib/jekyll-avatar/version.rb 0000664 0000000 0000000 00000000216 14226244076 0021621 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
module Liquid; class Tag; end; end
module Jekyll
class Avatar < Liquid::Tag
VERSION = "0.8.0"
end
end
jekyll-avatar-0.8.0/script/ 0000775 0000000 0000000 00000000000 14226244076 0015600 5 ustar 00root root 0000000 0000000 jekyll-avatar-0.8.0/script/bootstrap 0000775 0000000 0000000 00000000043 14226244076 0017540 0 ustar 00root root 0000000 0000000 #!/bin/sh
set -ex
bundle install
jekyll-avatar-0.8.0/script/cibuild 0000775 0000000 0000000 00000000137 14226244076 0017142 0 ustar 00root root 0000000 0000000 #!/bin/sh
set -ex
bundle exec rspec
bundle exec rubocop -S -D
gem build jekyll-avatar.gemspec jekyll-avatar-0.8.0/script/memprof 0000775 0000000 0000000 00000003240 14226244076 0017172 0 ustar 00root root 0000000 0000000 #!/usr/bin/env ruby
# frozen_string_literal: true
require "jekyll"
require "jekyll-avatar"
require "memory_profiler"
# An array of 100 strings
AUTHORS = ("a".."j").to_a.each_with_object([]) do |str, res|
count = 10
until count.zero?
res << (str * count)
count -= 1
end
end
CONSTRUCTS = [
"{% avatar benbalter %}",
"{% avatar octocat size=24 %}",
"{% avatar jekyllbot size=96 %}",
"{% avatar hubot lazy=true %}",
]
TEMPLATE_1 = Liquid::Template.parse(<<~TEXT)
{% for author in authors %}
{% avatar user=author %}
{% endfor %}
TEXT
TEMPLATE_2 = Liquid::Template.parse(CONSTRUCTS.join("\n"))
# ---
report = MemoryProfiler.report do
Jekyll.logger.info "Profiling:", "100 #{'different avatars'.cyan} via Liquid loop.."
TEMPLATE_1.render("authors" => AUTHORS)
CONSTRUCTS.each do |entry|
Jekyll.logger.info "Profiling:", "100 renders of #{entry.cyan}.."
end
100.times { TEMPLATE_2.render }
Jekyll.logger.info "", "done. Generating results.."
Jekyll.logger.info ""
end
if ENV["CI"]
report.pretty_print(scale_bytes: true, color_output: false, normalize_paths: true)
else
FileUtils.mkdir_p("tmp")
total_allocated_output = report.scale_bytes(report.total_allocated_memsize)
total_retained_output = report.scale_bytes(report.total_retained_memsize)
Jekyll.logger.info "Total allocated:", "#{total_allocated_output} (#{report.total_allocated} objects)".cyan
Jekyll.logger.info "Total retained:", "#{total_retained_output} (#{report.total_retained} objects)".cyan
report.pretty_print(to_file: "tmp/memprof.txt", normalize_paths: true, scale_bytes: true)
Jekyll.logger.info "\nDetailed Report saved into:", "tmp/memprof.txt".cyan
end
jekyll-avatar-0.8.0/spec/ 0000775 0000000 0000000 00000000000 14226244076 0015226 5 ustar 00root root 0000000 0000000 jekyll-avatar-0.8.0/spec/jekyll/ 0000775 0000000 0000000 00000000000 14226244076 0016520 5 ustar 00root root 0000000 0000000 jekyll-avatar-0.8.0/spec/jekyll/avatar_spec.rb 0000664 0000000 0000000 00000014743 14226244076 0021346 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "spec_helper"
describe Jekyll::Avatar do
subject { described_class.parse "avatar", text, tokenizer, parse_context }
let(:doc) { doc_with_content(content) }
let(:username) { "hubot" }
let(:args) { "" }
let(:text) { "#{username} #{args}".squeeze(" ") }
let(:content) { "{% avatar #{text} %}" }
let(:rendered) { subject.render(nil) }
let(:tokenizer) { Liquid::Tokenizer.new("") }
let(:parse_context) { Liquid::ParseContext.new }
let(:output) do
doc.content = content
doc.output = Jekyll::Renderer.new(doc.site, doc).run
end
let(:server_number) { 3 }
let(:host) { "https://avatars#{server_number}.githubusercontent.com" }
let(:uri) do
uri = Addressable::URI.parse(host)
uri.path = "#{uri.path}/#{username}"
uri.query_values = { :v => 3, :s => width }.to_a
uri
end
let(:height) { "40" }
let(:width) { "40" }
let(:scales) { (1..4) }
let(:src) { src_hash["1x"] }
let(:src_hash) do
scales.map do |scale|
uri.query_values = { "v" => 3, "s" => width.to_i * scale }.to_a
["#{scale}x", uri.to_s]
end.to_h
end
let(:srcset) { src_hash.map { |scale, src| "#{src} #{scale}" }.join(", ") }
it "has a version number" do
expect(Jekyll::Avatar::VERSION).not_to be nil
end
it "outputs the HTML" do
expect(output).to have_tag("p") do
with_tag "img", :with => {
"alt" => username,
"class" => "avatar avatar-small",
"data-proofer-ignore" => "true",
"height" => height,
"src" => src,
"srcset" => srcset,
"width" => width,
}
end
end
it "parses the username" do
expect(subject.send(:username)).to eql(username)
end
it "determines the server number" do
expect(subject.send(:server_number)).to eql(server_number)
end
it "builds the host" do
expect(subject.send(:host)).to eql(host)
end
context "with a custom host" do
let(:host) { "http://avatars.example.com" }
context "with subdomain isolation" do
it "builds the host" do
with_env("PAGES_AVATARS_URL", host) do
expect(subject.send(:host)).to eql(host)
end
end
it "builds the URL" do
with_env("PAGES_AVATARS_URL", host) do
expect(subject.send(:url)).to eql(src)
end
end
end
context "without subdomain isolation" do
let(:host) { "http://github.example.com/avatars" }
it "builds the URL" do
with_env("PAGES_AVATARS_URL", host) do
expect(subject.send(:url)).to eql(src)
end
end
end
end
it "builds the path" do
expect(subject.send(:path)).to eql("hubot?v=3&s=40")
end
it "defaults to the default size" do
expect(subject.send(:size)).to eql(width)
end
it "builds the URL" do
expect(subject.send(:url)).to eql(src)
end
it "builds the params" do
attrs = subject.send(:attributes)
expect(attrs).to eql({
:"data-proofer-ignore" => "true",
:class => "avatar avatar-small",
:alt => username,
:src => src,
:srcset => srcset,
:width => width,
:height => height,
})
end
it "includes data-proofer-ignore" do
expect(output).to have_tag "img", :with => {
"data-proofer-ignore" => "true",
}
end
context "retina" do
it "builds the path with a scale" do
expect(subject.send(:path, 2)).to eql("hubot?v=3&s=80")
end
context "when given a scale" do
let(:width) { "80" }
it "builds the URL with a scale" do
expect(subject.send(:url, 2)).to eql(src)
end
end
it "builds the srcset" do
srcset = subject.send(:srcset)
src_hash.each do |scale, url|
regex = Regexp.escape("#{url} #{scale}")
expect(srcset).to match(regex)
end
end
end
context "when passed @hubot as a username" do
let(:username) { "@hubot" }
it "parses the username" do
expect(subject.send(:username)).to eql("hubot")
end
end
context "with a size is passed" do
let(:width) { "45" }
let(:args) { "size=#{width}" }
it "parses the user's requested size" do
expect(subject.send(:size)).to eql(width)
end
end
context "with a size < 48" do
it "includes the avatar-small class" do
expect(rendered).to match(%r!avatar-small!)
end
it "calculates the classes" do
expect(subject.send(:classes)).to eql("avatar avatar-small")
end
end
context "with a size > 48" do
let(:width) { "80" }
let(:args) { "size=#{width}" }
it "doesn't include the avatar-small class" do
expect(rendered).not_to match(%r!avatar-small!)
end
it "calculates the classes" do
expect(subject.send(:classes)).to eql("avatar")
end
end
context "when passed the username as a rendered variable" do
let(:username) { "hubot2" }
let(:server_number) { 0 }
let(:content) { "{% assign user='#{username}' %}{% avatar {{ user }} %}" }
it "parses the variable" do
expect(output).to have_tag "img", :with => { "src" => src }
end
end
context "when passed the username as a variable-argument" do
let(:username) { "hubot2" }
let(:server_number) { 0 }
let(:content) { "{% assign user='hubot2' %}{% avatar user=user %}" }
it "parses the variable" do
expect(output).to have_tag "img", :with => { "src" => src }
end
end
context "when passed the username as a sub-variable-argument" do
let(:username) { "hubot2" }
let(:server_number) { 0 }
let(:content) { "{% avatar user=page.author %}" }
it "parses the variable" do
expect(output).to have_tag "img", :with => { "src" => src }
end
end
context "loops" do
let(:content) do
<<~LIQUID
{% assign users = "a|b" | split:"|" %}
{% for user in users %}
{% avatar user=user %}
{% endfor %}
LIQUID
end
it "renders each avatar" do
expect(output).to have_tag("p") do
with_tag "img", :with => { "alt" => "a" }
with_tag "img", :with => { "alt" => "b" }
end
end
end
context "lazy loading" do
let(:args) { "lazy=true" }
it "sets the image URL as the data-src" do
expect(output).to have_tag "img", :with => {
"src" => "",
"data-src" => src,
"data-srcset" => srcset,
}, :without => {
"srcset" => %r!.*!,
}
end
end
end
jekyll-avatar-0.8.0/spec/spec_helper.rb 0000664 0000000 0000000 00000002376 14226244076 0020054 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
require "jekyll"
require "jekyll-avatar"
require "rspec-html-matchers"
TEST_DIR = File.dirname(__FILE__)
TMP_DIR = File.expand_path("../tmp", TEST_DIR)
RSpec.configure do |config|
config.include RSpecHtmlMatchers
end
def doc_with_content(_content, opts = {})
my_site = site(opts)
options = { :site => my_site, :collection => collection(my_site) }
doc = Jekyll::Document.new(source_dir("_test/doc.md"), options)
doc.merge_data!({ "author" => "hubot2" })
doc
end
def tmp_dir(*files)
File.join(TMP_DIR, *files)
end
def source_dir(*files)
tmp_dir("source", *files)
end
def dest_dir(*files)
tmp_dir("dest", *files)
end
def collection(site, label = "test")
Jekyll::Collection.new(site, label)
end
def site(opts = {})
defaults = Jekyll::Configuration::DEFAULTS
opts = opts.merge(
"source" => source_dir,
"destination" => dest_dir
)
conf = Jekyll::Utils.deep_merge_hashes(defaults, opts)
Jekyll::Site.new(conf)
end
def fixture(name)
path = File.expand_path "./fixtures/#{name}.json", File.dirname(__FILE__)
File.open(path).read
end
def with_env(key, value)
old_value = ENV[key]
ENV[key] = value
yield
ensure
ENV[key] = old_value
end