ve_gravatar_image_tag 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.textile +119 -0
- data/Rakefile +38 -0
- data/lib/gravatar_image_tag.rb +126 -0
- data/spec/gravatar_image_tag_spec.rb +150 -0
- data/spec/test_helper.rb +13 -0
- metadata +148 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b47a98200804c593e310756fc0db7925819ec9758043ab706635ebe2a364cdae
|
4
|
+
data.tar.gz: 3c539d75cd5a2a4ccb57c7bb5c431119ba90acb6d1e9bb897cfcadaad30d9f07
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e03e6f5f3324767c5d3590a120781d79700a22f0a96ffe29f9a4ccc5452cbd1a6450e390d734c5376429e3e4b3c6c48286d2fd0fdecaad57aeeb0ad60dbd7013
|
7
|
+
data.tar.gz: 4181ba53b35e2e44c9ae871f8925890ff98c10c7630f88936b6b52f75c144c2be9ca63d9a7a47cd077ae54532a36548195ef5399897bbd6870ae0f3fa0f7689e
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Michael Deering
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
!http://s.gravatar.com/images/logo.png(Gravatar Logo)!
|
2
|
+
|
3
|
+
h1. Gravatar Image Tag Plugin
|
4
|
+
|
5
|
+
Rails view helper for grabbing "Gravatar":http://en.gravatar.com/ images. The goal here is to be configurable and have those configuration points documented!
|
6
|
+
|
7
|
+
h2. Install as a Ruby Gem
|
8
|
+
|
9
|
+
h3. Rails 2
|
10
|
+
|
11
|
+
p. Include the following line in your Rails environment
|
12
|
+
|
13
|
+
<pre># config/environment
|
14
|
+
config.gem 'gravatar_image_tag'</pre>
|
15
|
+
|
16
|
+
p. Then ensure the gem is installed by running the following rake task from the your application root.
|
17
|
+
|
18
|
+
<pre>rake gems:install</pre>
|
19
|
+
|
20
|
+
h3. Rails 3
|
21
|
+
|
22
|
+
p. Include the following line in your Rails environment
|
23
|
+
|
24
|
+
<pre># Gemfile
|
25
|
+
gem 'gravatar_image_tag'</pre>
|
26
|
+
|
27
|
+
p. Then ensure the gem is installed by running the following command from the application root.
|
28
|
+
|
29
|
+
<pre>bundle install</pre>
|
30
|
+
|
31
|
+
h2. Install as a Ruby on Rails Plugin
|
32
|
+
|
33
|
+
<pre>./script/plugin install git://github.com/mdeering/gravatar_image_tag.git</pre>
|
34
|
+
|
35
|
+
h2. Usage
|
36
|
+
|
37
|
+
h3. Gravatar Image Tag
|
38
|
+
|
39
|
+
p. Once you have installed it as a plugin for your rails app usage is simple.
|
40
|
+
|
41
|
+
<pre>gravatar_image_tag('spam@spam.com'.gsub('spam', 'mdeering'), :alt => 'Michael Deering')</pre>
|
42
|
+
|
43
|
+
*Boom* here is my gravatar !http://www.gravatar.com/avatar/4da9ad2bd4a2d1ce3c428e32c423588a(Michael Deering)!
|
44
|
+
|
45
|
+
h3. Gravatar Image URL
|
46
|
+
|
47
|
+
p. You can also return just the Gravatar URL:
|
48
|
+
|
49
|
+
<pre>gravatar_image_url('spam@spam.com'.gsub('spam', 'mdeering'), filetype: :png, rating: 'pg', size: 15, secure:false )</pre>
|
50
|
+
|
51
|
+
p. Useful when used in your inline CSS.
|
52
|
+
|
53
|
+
<pre><div class="gravatar" style="background:transparent url(<%= gravatar_image_url('spam@spam.com'.gsub('spam', 'mdeering'), size: 100) %>) 0px 0px no-repeat; width:100px; height:100px;"></div></pre>
|
54
|
+
|
55
|
+
h2. Configuration
|
56
|
+
|
57
|
+
h3. Global configuration points
|
58
|
+
|
59
|
+
<pre># config/initializers/gravatar_image_tag.rb
|
60
|
+
GravatarImageTag.configure do |config|
|
61
|
+
config.default_image = nil # Set this to use your own default gravatar image rather then serving up Gravatar's default image [ 'http://example.com/images/default_gravitar.jpg', :identicon, :monsterid, :wavatar, 404 ].
|
62
|
+
config.filetype = nil # Set this if you require a specific image file format ['gif', 'jpg' or 'png']. Gravatar's default is png
|
63
|
+
config.include_size_attributes = true # The height and width attributes of the generated img will be set to avoid page jitter as the gravatars load. Set to false to leave these attributes off.
|
64
|
+
config.rating = nil # Set this if you change the rating of the images that will be returned ['G', 'PG', 'R', 'X']. Gravatar's default is G
|
65
|
+
config.size = nil # Set this to globally set the size of the gravatar image returned (1..512). Gravatar's default is 80
|
66
|
+
config.secure = false # Set this to true if you require secure images on your pages.
|
67
|
+
end
|
68
|
+
</pre>
|
69
|
+
|
70
|
+
h3. Setting the default image inline
|
71
|
+
|
72
|
+
p. *Splat* the default gravatar image !http://www.gravatar.com/avatar/0c821f675f132d790b3f25e79da739a7(Default Gravatar Image)!
|
73
|
+
|
74
|
+
p. You can set the default gravatar image inline as follows:
|
75
|
+
|
76
|
+
<pre>gravatar_image_tag('junk', :alt => 'Github Default Gravatar', :gravatar => { :default => 'https://assets.github.com/images/gravatars/gravatar-140.png' })</pre>
|
77
|
+
|
78
|
+
p. *Ka-Pow* !https://assets.github.com/images/gravatars/gravatar-140.png(Github Default Gravatar)!
|
79
|
+
|
80
|
+
p. Other options supported besides an image url to fall back on include the following:
|
81
|
+
|
82
|
+
* :identicon !http://www.gravatar.com/avatar/0c821f675f132d790b3f25e79da739a7?default=identicon(Identicon Avatar)!
|
83
|
+
* :monsterid !http://www.gravatar.com/avatar/0c821f675f132d790b3f25e79da739a7?default=monsterid(Monster Id Avatar)!
|
84
|
+
* :wavatar !http://www.gravatar.com/avatar/0c821f675f132d790b3f25e79da739a7?default=wavatar(Wavatar Avatar)!
|
85
|
+
* 404: !http://www.gravatar.com/avatar/0c821f675f132d790b3f25e79da739a7?default=404(Not Found)!
|
86
|
+
|
87
|
+
h3. Setting the default image size
|
88
|
+
|
89
|
+
p. You can set the gravatar image size inline as follows:
|
90
|
+
|
91
|
+
<pre>gravatar_image_tag('spam@spam.com'.gsub('spam', 'mdeering'), :alt => 'Michael Deering', :class => 'some-class', :gravatar => { :size => 15 })</pre>
|
92
|
+
|
93
|
+
*Mini Me!* !(some-class)http://www.gravatar.com/avatar/4da9ad2bd4a2d1ce3c428e32c423588a?size=15(Michael Deering)!
|
94
|
+
|
95
|
+
h3. Grabbing gravatars from the secure gravatar server.
|
96
|
+
|
97
|
+
p. You can make a request for a gravatar from the secure server at https://secure.gravatar.com by passing the _:gravatar => { :secure => true }_ option to the gravatar_image_tag call.
|
98
|
+
|
99
|
+
<pre>gravatar_image_tag('spam@spam.com'.gsub('spam', 'mdeering'), :alt => 'Michael Deering', :gravatar => { :secure => true } )</pre>
|
100
|
+
|
101
|
+
Delivered by a secure url! !https://secure.gravatar.com/avatar/4da9ad2bd4a2d1ce3c428e32c423588a(Michael Deering)!
|
102
|
+
|
103
|
+
h3. Using Gravatar's built in rating system
|
104
|
+
|
105
|
+
p. You can set the gravatar rating inline as follows:
|
106
|
+
|
107
|
+
<pre>gravatar_image_tag('spam@spam.com'.gsub('spam', 'mdeering'), :alt => 'Michael Deering', :gravatar => { :rating => 'pg' } )</pre>
|
108
|
+
|
109
|
+
h3. Specifying a filetype
|
110
|
+
|
111
|
+
p. You can set the gravatar filetype inline as follows:
|
112
|
+
|
113
|
+
<pre>gravatar_image_tag('spam@spam.com'.gsub('spam', 'mdeering'), :alt => 'Michael Deering', :gravatar => { :filetype => :gif } )</pre>
|
114
|
+
|
115
|
+
h2. Credits
|
116
|
+
|
117
|
+
The ideas and methods for this plugin are from expanding upon my original blog post "Adding Gravatar To Your Website Or Blog (Gravatar Rails)":http://mdeering.com/posts/005-adding-gravitar-to-your-website-or-blog
|
118
|
+
|
119
|
+
Copyright (c) 2009-2010 "Michael Deering(Ruby on Rails Development Edmonton)":http://mdeering.com, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
begin
|
5
|
+
AUTHOR = "Michael Deering"
|
6
|
+
EMAIL = "mdeering@mdeering.com"
|
7
|
+
GEM = "gravatar_image_tag"
|
8
|
+
HOMEPAGE = "http://github.com/mdeering/gravatar_image_tag"
|
9
|
+
SUMMARY = "A configurable and documented Rails view helper for adding gravatars into your Rails application."
|
10
|
+
|
11
|
+
require 'jeweler'
|
12
|
+
Jeweler::Tasks.new do |s|
|
13
|
+
s.author = AUTHOR
|
14
|
+
s.email = EMAIL
|
15
|
+
s.files = %w(install.rb install.txt MIT-LICENSE README.textile Rakefile) + Dir.glob("{rails,lib,spec}/**/*")
|
16
|
+
s.homepage = HOMEPAGE
|
17
|
+
s.name = GEM
|
18
|
+
s.require_path = 'lib'
|
19
|
+
s.summary = SUMMARY
|
20
|
+
s.license = 'MIT'
|
21
|
+
end
|
22
|
+
Jeweler::GemcutterTasks.new
|
23
|
+
rescue LoadError
|
24
|
+
puts "Jeweler, or one of its dependencies, is not available. Install it with: gem install jeweler"
|
25
|
+
end
|
26
|
+
|
27
|
+
desc 'Test the gravatar_image_tag gem.'
|
28
|
+
RSpec::Core::RakeTask.new do |t|
|
29
|
+
end
|
30
|
+
|
31
|
+
desc 'Default: spec tests.'
|
32
|
+
task :default => :spec
|
33
|
+
|
34
|
+
desc "Run all examples with RCov"
|
35
|
+
RSpec::Core::RakeTask.new(:coverage) do |t|
|
36
|
+
t.rcov = true
|
37
|
+
t.rcov_opts = ['--exclude', '/opt,spec,Library']
|
38
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
module GravatarImageTag
|
2
|
+
|
3
|
+
class << self
|
4
|
+
attr_accessor :configuration
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.configuration
|
8
|
+
@configuration ||= Configuration.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.configure
|
12
|
+
yield(configuration)
|
13
|
+
end
|
14
|
+
|
15
|
+
class Configuration
|
16
|
+
attr_accessor :default_image, :filetype, :include_size_attributes,
|
17
|
+
:rating, :size, :secure
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
@include_size_attributes = true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.included(base)
|
25
|
+
GravatarImageTag.configure { |c| nil }
|
26
|
+
base.extend ClassMethods
|
27
|
+
base.send :include, InstanceMethods
|
28
|
+
end
|
29
|
+
|
30
|
+
module ClassMethods
|
31
|
+
def default_gravatar_filetype=(value)
|
32
|
+
warn "DEPRECATION WARNING: configuration of filetype= through this method is deprecated! Use the block configuration instead. http://github.com/mdeering/gravatar_image_tag"
|
33
|
+
GravatarImageTag.configure do |c|
|
34
|
+
c.filetype = value
|
35
|
+
end
|
36
|
+
end
|
37
|
+
def default_gravatar_image=(value)
|
38
|
+
warn "DEPRECATION WARNING: configuration of default_gravatar_image= through this method is deprecated! Use the block configuration instead. http://github.com/mdeering/gravatar_image_tag"
|
39
|
+
GravatarImageTag.configure do |c|
|
40
|
+
c.default_image = value
|
41
|
+
end
|
42
|
+
end
|
43
|
+
def default_gravatar_rating=(value)
|
44
|
+
warn "DEPRECATION WARNING: configuration of default_gravatar_rating= through this method is deprecated! Use the block configuration instead. http://github.com/mdeering/gravatar_image_tag"
|
45
|
+
GravatarImageTag.configure do |c|
|
46
|
+
c.rating = value
|
47
|
+
end
|
48
|
+
end
|
49
|
+
def default_gravatar_size=(value)
|
50
|
+
warn "DEPRECATION WARNING: configuration of default_gravatar_size= through this method is deprecated! Use the block configuration instead. http://github.com/mdeering/gravatar_image_tag"
|
51
|
+
GravatarImageTag.configure do |c|
|
52
|
+
c.size = value
|
53
|
+
end
|
54
|
+
end
|
55
|
+
def secure_gravatar=(value)
|
56
|
+
warn "DEPRECATION WARNING: configuration of secure_gravatar= through this method is deprecated! Use the block configuration instead. http://github.com/mdeering/gravatar_image_tag"
|
57
|
+
GravatarImageTag.configure do |c|
|
58
|
+
c.secure = value
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
module InstanceMethods
|
64
|
+
def gravatar_image_tag(email, options = {})
|
65
|
+
gravatar_overrides = options.delete(:gravatar)
|
66
|
+
options[:src] = gravatar_image_url(email, gravatar_overrides)
|
67
|
+
options[:alt] ||= 'Gravatar'
|
68
|
+
if GravatarImageTag.configuration.include_size_attributes
|
69
|
+
size = GravatarImageTag::gravatar_options(gravatar_overrides)[:size] || 80
|
70
|
+
options[:height] = options[:width] = size.to_s
|
71
|
+
end
|
72
|
+
|
73
|
+
# Patch submitted to rails to allow image_tag here
|
74
|
+
# https://rails.lighthouseapp.com/projects/8994/tickets/2878
|
75
|
+
tag 'img', options, false, false
|
76
|
+
end
|
77
|
+
|
78
|
+
def gravatar_image_url(email, gravatar_overrides = {})
|
79
|
+
email = email.strip.downcase if email.is_a? String
|
80
|
+
GravatarImageTag::gravatar_url(email, gravatar_overrides)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.gravatar_url(email, overrides = {})
|
85
|
+
gravatar_params = gravatar_options(overrides || {})
|
86
|
+
url_base = gravatar_url_base(gravatar_params.delete(:secure))
|
87
|
+
hash = gravatar_id(email, gravatar_params.delete(:filetype))
|
88
|
+
url_params = url_params(gravatar_params)
|
89
|
+
"#{url_base}/#{hash}#{url_params}"
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def self.gravatar_options(overrides = {})
|
95
|
+
{
|
96
|
+
:default => GravatarImageTag.configuration.default_image,
|
97
|
+
:filetype => GravatarImageTag.configuration.filetype,
|
98
|
+
:rating => GravatarImageTag.configuration.rating,
|
99
|
+
:secure => GravatarImageTag.configuration.secure,
|
100
|
+
:size => GravatarImageTag.configuration.size
|
101
|
+
}.merge(overrides || {}).delete_if { |key, value| value.nil? }
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.gravatar_url_base(secure = false)
|
105
|
+
'http' + (!!secure ? 's://secure.' : '://') + 'gravatar.com/avatar'
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.gravatar_id(email, filetype = nil)
|
109
|
+
return nil unless email
|
110
|
+
"#{ Digest::MD5.hexdigest(email) }#{ ".#{filetype}" unless filetype.nil? }"
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.url_params(gravatar_params)
|
114
|
+
return nil if gravatar_params.keys.size == 0
|
115
|
+
array = gravatar_params.map { |k, v| "#{k}=#{value_cleaner(v)}" }
|
116
|
+
"?#{array.join('&')}"
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.value_cleaner(value)
|
120
|
+
value = value.to_s
|
121
|
+
URI.escape(value, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
ActionView::Base.send(:include, GravatarImageTag) if defined?(ActionView::Base)
|
@@ -0,0 +1,150 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
require 'gravatar_image_tag'
|
4
|
+
|
5
|
+
ActionView::Base.send(:include, GravatarImageTag)
|
6
|
+
|
7
|
+
describe GravatarImageTag do
|
8
|
+
|
9
|
+
email = 'mdeering@mdeering.com'
|
10
|
+
md5 = '4da9ad2bd4a2d1ce3c428e32c423588a'
|
11
|
+
default_filetype = :gif
|
12
|
+
default_image = 'http://mdeering.com/images/default_gravatar.png'
|
13
|
+
default_image_escaped = 'http%3A%2F%2Fmdeering.com%2Fimages%2Fdefault_gravatar.png'
|
14
|
+
default_rating = 'x'
|
15
|
+
default_size = 50
|
16
|
+
other_image = 'http://mdeering.com/images/other_gravatar.png'
|
17
|
+
other_image_escaped = 'http%3A%2F%2Fmdeering.com%2Fimages%2Fother_gravatar.png'
|
18
|
+
secure = false
|
19
|
+
|
20
|
+
view = ActionView::Base.new
|
21
|
+
|
22
|
+
context '#gravatar_image_tag' do
|
23
|
+
|
24
|
+
{
|
25
|
+
{ gravatar_id: md5 } => {},
|
26
|
+
{ gravatar_id: md5 } => { gravatar: { rating: 'x' } },
|
27
|
+
{ gravatar_id: md5, size: 30 } => { gravatar: { size: 30 } },
|
28
|
+
{ gravatar_id: md5, default: other_image_escaped } => { gravatar: { default: other_image } },
|
29
|
+
{ gravatar_id: md5, default: other_image_escaped, size: 30 } => { gravatar: { default: other_image, size: 30 } }
|
30
|
+
}.each do |params, options|
|
31
|
+
it "#gravatar_image_tag should create the provided url with the provided options #{options}" do
|
32
|
+
view = ActionView::Base.new
|
33
|
+
image_tag = view.gravatar_image_tag(email, options)
|
34
|
+
expect(image_tag.include?("#{params.delete(:gravatar_id)}")).to be_truthy
|
35
|
+
expect(params.all? {|key, value| image_tag.include?("#{key}=#{value}")}).to be_truthy
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
{
|
40
|
+
default_gravatar_image: default_image,
|
41
|
+
default_gravatar_filetype: default_filetype,
|
42
|
+
default_gravatar_rating: default_rating,
|
43
|
+
default_gravatar_size: default_size,
|
44
|
+
secure_gravatar: secure
|
45
|
+
}.each do |singleton_variable, value|
|
46
|
+
it "should give a deprication warning for assigning to #{singleton_variable} and passthrough to set the new variable" do
|
47
|
+
expect(ActionView::Base).to receive(:warn)
|
48
|
+
ActionView::Base.send("#{singleton_variable}=", value)
|
49
|
+
GravatarImageTag.configuration.default_image == value if singleton_variable == :default_gravatar_image
|
50
|
+
GravatarImageTag.configuration.filetype == value if singleton_variable == :default_gravatar_filetype
|
51
|
+
GravatarImageTag.configuration.rating == value if singleton_variable == :default_gravatar_rating
|
52
|
+
GravatarImageTag.configuration.size == value if singleton_variable == :default_gravatar_size
|
53
|
+
GravatarImageTag.configuration.secure == value if singleton_variable == :secure_gravatar
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Now that the defaults are set...
|
58
|
+
{
|
59
|
+
{ gravatar_id: md5, size: default_size, default: default_image_escaped } => {},
|
60
|
+
{ gravatar_id: md5, size: 30, default: default_image_escaped } => { gravatar: { size: 30 } },
|
61
|
+
{ gravatar_id: md5, size: default_size, default: other_image_escaped } => { gravatar: { default: other_image } },
|
62
|
+
{ gravatar_id: md5, size: 30, default: other_image_escaped } => { gravatar: { default: other_image, size: 30 } },
|
63
|
+
}.each do |params, options|
|
64
|
+
it "#gravatar_image_tag #{params} should create the provided url when defaults have been set with the provided options #{options}" do
|
65
|
+
view = ActionView::Base.new
|
66
|
+
image_tag = view.gravatar_image_tag(email, options)
|
67
|
+
expect(image_tag.include?("#{params.delete(:gravatar_id)}.#{default_filetype}")).to be_truthy
|
68
|
+
expect(params.all? {|key, value| image_tag.include?("#{key}=#{value}")}).to be_truthy
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should request the gravatar image from the non-secure server when the https: false option is given' do
|
73
|
+
expect(!!view.gravatar_image_tag(email, { gravatar: { secure: false } }).match(/^https:\/\/secure.gravatar.com\/avatar\//)).to be_falsey
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should request the gravatar image from the secure server when the https: true option is given' do
|
77
|
+
expect(!!view.gravatar_image_tag(email, { gravatar: { secure: true } }).match(/src="https:\/\/secure.gravatar.com\/avatar\//)).to be_truthy
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should set the image tags height and width to avoid the page going all jiggy (technical term) when loading a page with lots of Gravatars' do
|
81
|
+
GravatarImageTag.configure { |c| c.size = 30 }
|
82
|
+
expect(!!view.gravatar_image_tag(email).match(/height="30"/)).to be_truthy
|
83
|
+
expect(!!view.gravatar_image_tag(email).match(/width="30"/)).to be_truthy
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should set the image tags height and width attributes to 80px (gravatars default) if no size is given.' do
|
87
|
+
GravatarImageTag.configure { |c| c.size = nil }
|
88
|
+
expect(!!view.gravatar_image_tag(email).match(/height="80"/)).to be_truthy
|
89
|
+
expect(!!view.gravatar_image_tag(email).match(/width="80"/)).to be_truthy
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should set the image tags height and width attributes from the overrides on the size' do
|
93
|
+
GravatarImageTag.configure { |c| c.size = 120 }
|
94
|
+
expect(!!view.gravatar_image_tag(email, gravatar: { size: 45 }).match(/height="45"/)).to be_truthy
|
95
|
+
expect(!!view.gravatar_image_tag(email, gravatar: { size: 75 }).match(/width="75"/)).to be_truthy
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'should not include the height and width attributes on the image tag if it is turned off in the configuration' do
|
99
|
+
GravatarImageTag.configure { |c| c.include_size_attributes = false }
|
100
|
+
expect(!!view.gravatar_image_tag(email).match(/height=/)).to be_falsey
|
101
|
+
expect(!!view.gravatar_image_tag(email).match(/width=/)).to be_falsey
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'GravatarImageTag#gravitar_id should not error out when email is nil' do
|
105
|
+
expect { GravatarImageTag::gravatar_id(nil) }.to_not raise_error
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should normalize the email to Gravatar standards (http://en.gravatar.com/site/implement/hash/)' do
|
109
|
+
expect(view.gravatar_image_tag(" camelCaseEmail@example.com\t\n")).to eq(view.gravatar_image_tag('camelcaseemail@example.com'))
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
context '#gravatar_image_url' do
|
115
|
+
|
116
|
+
it '#gravatar_image_url should return a gravatar URL' do
|
117
|
+
expect(!!view.gravatar_image_url(email).match(/^http:\/\/gravatar.com\/avatar\//)).to be_truthy
|
118
|
+
end
|
119
|
+
|
120
|
+
it '#gravatar_image_url should set the email as an md5 digest' do
|
121
|
+
expect(!!view.gravatar_image_url(email).match("http:\/\/gravatar.com\/avatar\/#{md5}")).to be_truthy
|
122
|
+
end
|
123
|
+
|
124
|
+
it '#gravatar_image_url should set the default_image' do
|
125
|
+
expect(!!view.gravatar_image_url(email).include?("default=#{default_image_escaped}")).to be_truthy
|
126
|
+
end
|
127
|
+
|
128
|
+
it '#gravatar_image_url should set the filetype' do
|
129
|
+
expect(!!view.gravatar_image_url(email, filetype: :png).match("http:\/\/gravatar.com\/avatar\/#{md5}.png")).to be_truthy
|
130
|
+
end
|
131
|
+
|
132
|
+
it '#gravatar_image_url should set the rating' do
|
133
|
+
expect(!!view.gravatar_image_url(email, rating: 'pg').include?("rating=pg")).to be_truthy
|
134
|
+
end
|
135
|
+
|
136
|
+
it '#gravatar_image_url should set the size' do
|
137
|
+
expect(!!view.gravatar_image_url(email, size: 100).match(/size=100/)).to be_truthy
|
138
|
+
end
|
139
|
+
|
140
|
+
it '#gravatar_image_url should use http protocol when the https: false option is given' do
|
141
|
+
expect(!!view.gravatar_image_url(email, secure: false).match("^http:\/\/gravatar.com\/avatar\/")).to be_truthy
|
142
|
+
end
|
143
|
+
|
144
|
+
it '#gravatar_image_url should use https protocol when the https: true option is given' do
|
145
|
+
expect(!!view.gravatar_image_url(email, secure: true).match("^https:\/\/secure.gravatar.com\/avatar\/")).to be_truthy
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
data/spec/test_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
#require 'spec'
|
3
|
+
require 'active_support'
|
4
|
+
require 'action_view'
|
5
|
+
require 'digest/md5'
|
6
|
+
require 'uri'
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.filter_run focus: true
|
10
|
+
config.run_all_when_everything_filtered = true
|
11
|
+
end
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
|
metadata
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ve_gravatar_image_tag
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Deering
|
8
|
+
- VersionEye
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2020-04-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 3.2.0
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 3.2.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: actionpack
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 3.2.0
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 3.2.0
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: guard
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: guard-rspec
|
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
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rb-fsevent
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0.9'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0.9'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: jeweler
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
description:
|
113
|
+
email: rubygems@versioneye.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files:
|
117
|
+
- README.textile
|
118
|
+
files:
|
119
|
+
- MIT-LICENSE
|
120
|
+
- README.textile
|
121
|
+
- Rakefile
|
122
|
+
- lib/gravatar_image_tag.rb
|
123
|
+
- spec/gravatar_image_tag_spec.rb
|
124
|
+
- spec/test_helper.rb
|
125
|
+
homepage: http://github.com/versioneye/gravatar_image_tag
|
126
|
+
licenses: []
|
127
|
+
metadata: {}
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubygems_version: 3.0.8
|
144
|
+
signing_key:
|
145
|
+
specification_version: 3
|
146
|
+
summary: A configurable and documented Rails view helper for adding gravatars into
|
147
|
+
your Rails application.
|
148
|
+
test_files: []
|