bunto-avatar 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8385ed18d90fe2378f0f5f2b3a006f4a44dfa4e5
4
+ data.tar.gz: 4af75a556a285c310bd06abc224fc1ddcf1b8afb
5
+ SHA512:
6
+ metadata.gz: 2244566729cb5c19382cfcb22ea6eb2ae9eb675df6ba86b7fd1d0657f770809cde3d76a74dc5b9f9824b1d5a552c4f35d3af13c748fc20fd214efbbecd7c079c
7
+ data.tar.gz: 26679f334829bb073d1c6b43f93ee32ecaf5f6a510baf40b99d906758f8cdb5cfb91307be634b53a2914d0009d308cbca53596456942dd601902b21f012d29e1
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,20 @@
1
+ Style/AlignHash:
2
+ EnforcedHashRocketStyle: table
3
+ EnforcedColonStyle: table
4
+
5
+ Style/Documentation:
6
+ Enabled: false
7
+
8
+ Lint/EndAlignment:
9
+ AlignWith: variable
10
+ AutoCorrect: true
11
+
12
+ Style/FileName:
13
+ Enabled: false
14
+
15
+ Metrics/LineLength:
16
+ Exclude:
17
+ - spec/*/**
18
+
19
+ Style/DeprecatedHashMethods:
20
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.0
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
5
+ sudo: false
6
+ cache: bundler
7
+ script: script/cibuild
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bunto-avatar.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016-present Ben Balter
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.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # Bunto Avatar
2
+
3
+ *A Bunto plugin for rendering GitHub avatars*
4
+
5
+ [![Build Status](https://travis-ci.org/benbalter/bunto-avatar.svg)](https://travis-ci.org/benbalter/bunto-avatar)
6
+
7
+ Bunto Avatar makes it easy to add GitHub avatars to your Bunto site by specifying a username. If performance is a concern, Bunto 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.
8
+
9
+ ## Installation
10
+
11
+ Add the following to your site's `Gemfile`:
12
+
13
+ ```ruby
14
+ gem 'bunto-avatar'
15
+ ```
16
+
17
+ And add the following to your site's `_config.yml` file:
18
+
19
+ ```yaml
20
+ gems:
21
+ - bunto-avatar
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ Simply add the following, anywhere you'd like a user's avatar to appear:
27
+
28
+ ```
29
+ {% avatar [USERNAME] %}
30
+ ```
31
+
32
+ With `[USERNAME]` being the user's GitHub username:
33
+
34
+ ```
35
+ {% avatar hubot %}
36
+ ```
37
+
38
+ That will output:
39
+
40
+ ```html
41
+ <img class="avatar avatar-small" src="https://avatars3.githubusercontent.com/hubot?v=3&amp;s=40" alt="hubot" srcset="https://avatars3.githubusercontent.com/hubot?v=3&amp;s=40 1x, https://avatars3.githubusercontent.com/hubot?v=3&amp;s=80 2x, https://avatars3.githubusercontent.com/hubot?v=3&amp;s=120 3x, https://avatars3.githubusercontent.com/hubot?v=3&amp;s=160 4x" width="40" height="40" />
42
+ ```
43
+
44
+ ### Customizing
45
+
46
+ You can customize the size of the resulting avatar by passing the size argument:
47
+
48
+ ```
49
+ {% avatar hubot size=50 %}
50
+ ```
51
+
52
+ That will output:
53
+
54
+ ```html
55
+ <img class="avatar" src="https://avatars3.githubusercontent.com/hubot?v=3&amp;s=50" alt="hubot" srcset="https://avatars3.githubusercontent.com/hubot?v=3&amp;s=50 1x, https://avatars3.githubusercontent.com/hubot?v=3&amp;s=100 2x, https://avatars3.githubusercontent.com/hubot?v=3&amp;s=150 3x, https://avatars3.githubusercontent.com/hubot?v=3&amp;s=200 4x" width="50" height="50" />
56
+ ```
57
+
58
+ ### Passing the username as variable
59
+
60
+ You can also pass the username as a variable, like this:
61
+
62
+ ```
63
+ {% assign username="hubot" %}
64
+ {% avatar {{ username }} %}
65
+ ```
66
+
67
+ Or, if the variable is someplace a bit more complex, like a loop:
68
+
69
+ ```
70
+ {% assign employees = "alice|bob" | split:"|" %}
71
+ {% for employee in employees %}
72
+ {% avatar user=employee %}
73
+ {% endfor %}
74
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bunto-avatar/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'bunto-avatar'
8
+ spec.version = Bunto::Avatar::VERSION
9
+ spec.authors = ['Ben Balter', 'Suriyaa Kudo']
10
+ spec.email = ['ben.balter@github.com', 'SuriyaaKudoIsc@users.noreply.github.com']
11
+
12
+ spec.summary = 'A Bunto plugin for rendering GitHub avatars'
13
+ spec.homepage = 'https://github.com/benbalter/bunto-avatar'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |file|
17
+ file.match(%r{^(test|spec|features)/})
18
+ end
19
+
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'bunto', '~> 1.0'
23
+ spec.add_development_dependency 'bundler', '~> 1.11'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.0'
26
+ spec.add_development_dependency 'rubocop'
27
+ end
@@ -0,0 +1,76 @@
1
+ require 'zlib'
2
+
3
+ module Bunto
4
+ class Avatar < Liquid::Tag
5
+ SERVERS = 4
6
+ DEFAULT_SIZE = 40
7
+ API_VERSION = 3
8
+
9
+ def initialize(_tag_name, text, _tokens)
10
+ super
11
+ @text = text
12
+ end
13
+
14
+ def render(context)
15
+ @context = context
16
+ @text = Liquid::Template.parse(@text).render(@context)
17
+ attrs = attributes.map { |k, v| "#{k}=\"#{v}\"" }.join(' ')
18
+ "<img #{attrs} />"
19
+ end
20
+
21
+ private
22
+
23
+ def attributes
24
+ {
25
+ :class => classes,
26
+ :src => url,
27
+ :alt => username,
28
+ :srcset => srcset,
29
+ :width => size,
30
+ :height => size,
31
+ :'data-proofer-ignore' => true
32
+ }
33
+ end
34
+
35
+ def username
36
+ matches = @text.match(/\buser=(\w+)\b/)
37
+ if matches && @context.has_key?(matches[1])
38
+ @context[matches[1]]
39
+ else
40
+ @text.split(' ').first.sub('@', '')
41
+ end
42
+ end
43
+
44
+ def size
45
+ matches = @text.match(/\bsize=(\d+)\b/i)
46
+ matches ? matches[1].to_i : DEFAULT_SIZE
47
+ end
48
+
49
+ def path(scale = 1)
50
+ "#{username}?v=#{API_VERSION}&s=#{size * scale}"
51
+ end
52
+
53
+ def server_number
54
+ Zlib.crc32(path) % SERVERS
55
+ end
56
+
57
+ def host
58
+ "avatars#{server_number}.githubusercontent.com"
59
+ end
60
+
61
+ def url(scale = 1)
62
+ "https://#{host}/#{path(scale)}"
63
+ end
64
+
65
+ def srcset
66
+ (1..4).map { |scale| "#{url(scale)} #{scale}x" }.join(', ')
67
+ end
68
+
69
+ # See http://primercss.io/avatars/#small-avatars
70
+ def classes
71
+ size < 48 ? 'avatar avatar-small' : 'avatar'
72
+ end
73
+ end
74
+ end
75
+
76
+ Liquid::Template.register_tag('avatar', Bunto::Avatar)
@@ -0,0 +1,6 @@
1
+ module Liquid; class Tag; end; end
2
+ module Bunto
3
+ class Avatar < Liquid::Tag
4
+ VERSION = '1.0.0'.freeze
5
+ end
6
+ end
data/script/bootstrap ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+
3
+ set -ex
4
+
5
+ bundle install
data/script/cibuild ADDED
@@ -0,0 +1,6 @@
1
+ #!/bin/sh
2
+
3
+ set -ex
4
+
5
+ bundle exec rake spec
6
+ bundle exec rubocop
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bunto-avatar
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ben Balter
8
+ - Suriyaa Kudo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-03-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bunto
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.11'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.11'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '10.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '10.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '3.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3.0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rubocop
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ description:
85
+ email:
86
+ - ben.balter@github.com
87
+ - SuriyaaKudoIsc@users.noreply.github.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".rubocop.yml"
95
+ - ".ruby-version"
96
+ - ".travis.yml"
97
+ - Gemfile
98
+ - LICENSE.txt
99
+ - README.md
100
+ - Rakefile
101
+ - bunto-avatar.gemspec
102
+ - lib/bunto-avatar.rb
103
+ - lib/bunto-avatar/version.rb
104
+ - script/bootstrap
105
+ - script/cibuild
106
+ homepage: https://github.com/benbalter/bunto-avatar
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.2.2
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: A Bunto plugin for rendering GitHub avatars
130
+ test_files: []