Skip to content

Commit e390128

Browse files
authored
Merge pull request #13 from benbalter/enterprise-support
Add support for GitHub Enterprise
2 parents cfbcf5b + cb8343b commit e390128

File tree

9 files changed

+91
-27
lines changed

9 files changed

+91
-27
lines changed

.rubocop.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@ Style/FileName:
77
Metrics/LineLength:
88
Exclude:
99
- spec/*/**
10+
11+
Metrics/BlockLength:
12+
Enabled: false
13+
14+
AllCops:
15+
Exclude:
16+
- vendor/**/*

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
2-
source 'https://rubygems.org'
2+
3+
source "https://rubygems.org"
34

45
# Specify your gem's dependencies in jekyll-avatar.gemspec
56
gemspec

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,12 @@ Or, if the variable is someplace a bit more complex, like a loop:
7272
{% avatar user=employee %}
7373
{% endfor %}
7474
```
75+
76+
### Using with GitHub Enterprise
77+
78+
To use Jekyll Avatars with GitHub Enterprise, you must set the `PAGES_AVATARS_URL` environmental variable.
79+
80+
This should be the full URL to the avatars subdomain or subpath. For example:
81+
82+
* With subdomain isolation: `PAGES_AVATARS_URL="https://avatars.github.example.com"`
83+
* Without subdomain isolation: `PAGES_AVATARS_URL="https://github.example.com/avatars"`

Rakefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# frozen_string_literal: true
2-
require 'bundler/gem_tasks'
3-
require 'rspec/core/rake_task'
2+
3+
require "bundler/gem_tasks"
4+
require "rspec/core/rake_task"
45

56
RSpec::Core::RakeTask.new(:spec)
67

7-
task default: :spec
8+
task :default => :spec

jekyll-avatar.gemspec

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
# coding: utf-8
22
# frozen_string_literal: true
3-
lib = File.expand_path('../lib', __FILE__)
3+
4+
lib = File.expand_path("../lib", __FILE__)
45
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5-
require 'jekyll-avatar/version'
6+
require "jekyll-avatar/version"
67

78
Gem::Specification.new do |spec|
8-
spec.name = 'jekyll-avatar'
9+
spec.name = "jekyll-avatar"
910
spec.version = Jekyll::Avatar::VERSION
10-
spec.authors = ['Ben Balter']
11-
spec.email = ['[email protected]']
11+
spec.authors = ["Ben Balter"]
12+
spec.email = ["[email protected]"]
1213

13-
spec.summary = 'A Jekyll plugin for rendering GitHub avatars'
14-
spec.homepage = 'https://github.com/benbalter/jekyll-avatar'
15-
spec.license = 'MIT'
14+
spec.summary = "A Jekyll plugin for rendering GitHub avatars"
15+
spec.homepage = "https://github.com/benbalter/jekyll-avatar"
16+
spec.license = "MIT"
1617

1718
spec.files = `git ls-files -z`.split("\x0").reject do |file|
18-
file.match(%r{^(test|spec|features)/})
19+
file.match(%r!^(test|spec|features)/!)
1920
end
2021

21-
spec.require_paths = ['lib']
22+
spec.require_paths = ["lib"]
2223

23-
spec.add_dependency 'jekyll', '~> 3.0'
24-
spec.add_development_dependency 'bundler', '~> 1.11'
25-
spec.add_development_dependency 'rake', '~> 10.0'
26-
spec.add_development_dependency 'rspec', '~> 3.0'
27-
spec.add_development_dependency 'rubocop'
24+
spec.add_dependency "jekyll", "~> 3.0"
25+
spec.add_development_dependency "bundler", "~> 1.11"
26+
spec.add_development_dependency "rake", "~> 10.0"
27+
spec.add_development_dependency "rspec", "~> 3.0"
28+
spec.add_development_dependency "rubocop"
2829
end

lib/jekyll-avatar.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# frozen_string_literal: true
2+
23
require "zlib"
34

45
module Jekyll
@@ -31,7 +32,7 @@ def attributes
3132
:srcset => srcset,
3233
:width => size,
3334
:height => size,
34-
"data-proofer-ignore" => true
35+
"data-proofer-ignore" => true,
3536
}
3637
end
3738

@@ -58,11 +59,17 @@ def server_number
5859
end
5960

6061
def host
61-
"avatars#{server_number}.githubusercontent.com"
62+
if ENV["PAGES_AVATARS_URL"].to_s.empty?
63+
"https://avatars#{server_number}.githubusercontent.com"
64+
else
65+
ENV["PAGES_AVATARS_URL"]
66+
end
6267
end
6368

6469
def url(scale = 1)
65-
"https://#{host}/#{path(scale)}"
70+
uri = Addressable::URI.parse host
71+
uri.path << "/" unless uri.path.end_with?("/")
72+
uri.join path(scale)
6673
end
6774

6875
def srcset

lib/jekyll-avatar/version.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# frozen_string_literal: true
2+
23
module Liquid; class Tag; end; end
34
module Jekyll
45
class Avatar < Liquid::Tag

spec/jekyll/avatar_spec.rb

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# frozen_string_literal: true
2+
23
require "spec_helper"
34

45
describe Jekyll::Avatar do
@@ -8,11 +9,13 @@
89
let(:text) { "#{username} #{args}".squeeze(" ") }
910
let(:content) { "{% avatar #{text} %}" }
1011
let(:rendered) { subject.render(nil) }
12+
let(:tokenizer) { Liquid::Tokenizer.new("") }
13+
let(:parse_context) { Liquid::ParseContext.new }
1114
let(:output) do
1215
doc.content = content
1316
doc.output = Jekyll::Renderer.new(doc.site, doc).run
1417
end
15-
subject { Jekyll::Avatar.send(:new, "avatar", text, nil) }
18+
subject { described_class.parse "avatar", text, tokenizer, parse_context }
1619

1720
it "has a version number" do
1821
expect(Jekyll::Avatar::VERSION).not_to be nil
@@ -40,7 +43,32 @@
4043
end
4144

4245
it "builds the host" do
43-
expect(subject.send(:host)).to eql("avatars3.githubusercontent.com")
46+
expect(subject.send(:host)).to eql("https://avatars3.githubusercontent.com")
47+
end
48+
49+
context "with a custom host" do
50+
context "with subdomain isolation" do
51+
it "builds the host" do
52+
with_env("PAGES_AVATARS_URL", "http://avatars.example.com") do
53+
expect(subject.send(:host)).to eql("http://avatars.example.com")
54+
end
55+
end
56+
57+
it "builds the URL" do
58+
with_env("PAGES_AVATARS_URL", "http://avatars.example.com") do
59+
expect(subject.send(:url).to_s).to eql("http://avatars.example.com/hubot?v=3&s=40")
60+
end
61+
end
62+
end
63+
64+
context "without subdomain isolation" do
65+
it "builds the URL" do
66+
with_env("PAGES_AVATARS_URL", "http://github.example.com/avatars/") do
67+
expected = "http://github.example.com/avatars/hubot?v=3&s=40"
68+
expect(subject.send(:url).to_s).to eql(expected)
69+
end
70+
end
71+
end
4472
end
4573

4674
it "builds the path" do
@@ -53,14 +81,14 @@
5381

5482
it "builds the URL" do
5583
expected = "https://avatars3.githubusercontent.com/hubot?v=3&s=40"
56-
expect(subject.send(:url)).to eql(expected)
84+
expect(subject.send(:url).to_s).to eql(expected)
5785
end
5886

5987
it "builds the params" do
6088
attrs = subject.send(:attributes)
6189
expect(attrs[:class]).to eql("avatar avatar-small")
6290
expect(attrs[:alt]).to eql("hubot")
63-
expect(attrs[:src]).to eql("https://avatars3.githubusercontent.com/hubot?v=3&s=40")
91+
expect(attrs[:src].to_s).to eql("https://avatars3.githubusercontent.com/hubot?v=3&s=40")
6492
expect(attrs[:width]).to eql(40)
6593
expect(attrs[:height]).to eql(40)
6694
end
@@ -76,7 +104,7 @@
76104

77105
it "builds the URL with a scale" do
78106
expected = "https://avatars3.githubusercontent.com/hubot?v=3&s=80"
79-
expect(subject.send(:url, 2)).to eql(expected)
107+
expect(subject.send(:url, 2).to_s).to eql(expected)
80108
end
81109

82110
it "builds the srcset" do

spec/spec_helper.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# frozen_string_literal: true
2+
23
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
34

45
require "jekyll"
@@ -45,3 +46,11 @@ def fixture(name)
4546
path = File.expand_path "./fixtures/#{name}.json", File.dirname(__FILE__)
4647
File.open(path).read
4748
end
49+
50+
def with_env(key, value)
51+
old_value = ENV[key]
52+
ENV[key] = value
53+
yield
54+
ensure
55+
ENV[key] = old_value
56+
end

0 commit comments

Comments
 (0)