gravatar_image_tag 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +3 -3
- data/Rakefile +3 -16
- data/lib/gravatar_image_tag.rb +21 -11
- data/spec/gravatar_image_tag_spec.rb +12 -1
- data/spec/test_helper.rb +2 -2
- metadata +91 -46
data/README.textile
CHANGED
@@ -60,9 +60,9 @@ p. *Splat* the default gravatar image !http://www.gravatar.com/avatar/0c821f675f
|
|
60
60
|
|
61
61
|
p. You can set the default gravatar image inline as follows:
|
62
62
|
|
63
|
-
<pre>gravatar_image_tag('junk', :alt => 'Github Default Gravatar', :gravatar => { :default => '
|
63
|
+
<pre>gravatar_image_tag('junk', :alt => 'Github Default Gravatar', :gravatar => { :default => 'https://assets.github.com/images/gravatars/gravatar-140.png' })</pre>
|
64
64
|
|
65
|
-
p. *Ka-Pow* !
|
65
|
+
p. *Ka-Pow* !https://assets.github.com/images/gravatars/gravatar-140.png(Github Default Gravatar)!
|
66
66
|
|
67
67
|
p. Other options supported besides an image url to fall back on include the following:
|
68
68
|
|
@@ -103,6 +103,6 @@ p. You can set the gravatar filetype inline as follows:
|
|
103
103
|
|
104
104
|
h2. Credits
|
105
105
|
|
106
|
-
The ideas
|
106
|
+
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
|
107
107
|
|
108
108
|
Copyright (c) 2009-2010 "Michael Deering(Ruby on Rails Development Edmonton)":http://mdeering.com, released under the MIT license
|
data/Rakefile
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'rake'
|
2
|
-
require '
|
3
|
-
require 'spec/rake/spectask'
|
2
|
+
require 'rspec/core/rake_task'
|
4
3
|
|
5
4
|
begin
|
6
5
|
AUTHOR = "Michael Deering"
|
@@ -28,23 +27,11 @@ desc 'Default: spec tests.'
|
|
28
27
|
task :default => :spec
|
29
28
|
|
30
29
|
desc 'Test the gravatar_image_tag gem.'
|
31
|
-
|
32
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
33
|
-
t.spec_opts = ["-c"]
|
30
|
+
RSpec::Core::RakeTask.new do |t|
|
34
31
|
end
|
35
32
|
|
36
33
|
desc "Run all examples with RCov"
|
37
|
-
|
38
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
34
|
+
RSpec::Core::RakeTask.new(:coverage) do |t|
|
39
35
|
t.rcov = true
|
40
36
|
t.rcov_opts = ['--exclude', '/opt,spec,Library']
|
41
37
|
end
|
42
|
-
|
43
|
-
desc 'Generate documentation for the gravatar_image_tag plugin.'
|
44
|
-
Rake::RDocTask.new(:rdoc) do |rdoc|
|
45
|
-
rdoc.rdoc_dir = 'rdoc'
|
46
|
-
rdoc.title = 'GravatarImageTag'
|
47
|
-
rdoc.options << '--line-numbers' << '--inline-source'
|
48
|
-
rdoc.rdoc_files.include('README.textile')
|
49
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
-
end
|
data/lib/gravatar_image_tag.rb
CHANGED
@@ -13,8 +13,13 @@ module GravatarImageTag
|
|
13
13
|
end
|
14
14
|
|
15
15
|
class Configuration
|
16
|
-
attr_accessor :default_image, :filetype, :rating, :size, :secure
|
17
|
-
|
16
|
+
attr_accessor :default_image, :filetype, :include_size_attributes, :rating, :size, :secure
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@include_size_attributes = true
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
18
23
|
|
19
24
|
def self.included(base)
|
20
25
|
GravatarImageTag.configure { |c| nil }
|
@@ -58,27 +63,32 @@ module GravatarImageTag
|
|
58
63
|
module InstanceMethods
|
59
64
|
|
60
65
|
def gravatar_image_tag(email, options = {})
|
61
|
-
|
66
|
+
gravatar_overrides = options.delete(:gravatar)
|
67
|
+
options[:src] = GravatarImageTag::gravatar_url(email, gravatar_overrides)
|
62
68
|
options[:alt] ||= 'Gravatar'
|
69
|
+
options[:height] = options[:width] = "#{GravatarImageTag::gravatar_options(gravatar_overrides)[:size]}px" if GravatarImageTag.configuration.include_size_attributes
|
63
70
|
tag 'img', options, false, false # Patch submitted to rails to allow image_tag here https://rails.lighthouseapp.com/projects/8994/tickets/2878-image_tag-doesnt-allow-escape-false-option-anymore
|
64
71
|
end
|
65
72
|
|
66
73
|
end
|
67
74
|
|
68
75
|
def self.gravatar_url(email, overrides = {})
|
69
|
-
overrides
|
70
|
-
gravatar_params = {
|
71
|
-
:default => GravatarImageTag.configuration.default_image,
|
72
|
-
:filetype => GravatarImageTag.configuration.filetype,
|
73
|
-
:rating => GravatarImageTag.configuration.rating,
|
74
|
-
:secure => GravatarImageTag.configuration.secure,
|
75
|
-
:size => GravatarImageTag.configuration.size
|
76
|
-
}.merge(overrides).delete_if { |key, value| value.nil? }
|
76
|
+
gravatar_params = gravatar_options(overrides || {})
|
77
77
|
"#{gravatar_url_base(gravatar_params.delete(:secure))}/#{gravatar_id(email, gravatar_params.delete(:filetype))}#{url_params(gravatar_params)}"
|
78
78
|
end
|
79
79
|
|
80
80
|
private
|
81
81
|
|
82
|
+
def self.gravatar_options(overrides = {})
|
83
|
+
{
|
84
|
+
:default => GravatarImageTag.configuration.default_image,
|
85
|
+
:filetype => GravatarImageTag.configuration.filetype,
|
86
|
+
:rating => GravatarImageTag.configuration.rating,
|
87
|
+
:secure => GravatarImageTag.configuration.secure,
|
88
|
+
:size => GravatarImageTag.configuration.size
|
89
|
+
}.merge(overrides || {}).delete_if { |key, value| value.nil? }
|
90
|
+
end
|
91
|
+
|
82
92
|
def self.gravatar_url_base(secure = false)
|
83
93
|
'http' + (!!secure ? 's://secure.' : '://') + 'gravatar.com/avatar'
|
84
94
|
end
|
@@ -75,8 +75,19 @@ describe GravatarImageTag do
|
|
75
75
|
(!!view.gravatar_image_tag(email, { :gravatar => { :secure => true } }).match(/src="https:\/\/secure.gravatar.com\/avatar\//)).should be_true
|
76
76
|
end
|
77
77
|
|
78
|
+
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
|
79
|
+
(!!view.gravatar_image_tag(email).match(/height="50px"/)).should be_true
|
80
|
+
(!!view.gravatar_image_tag(email).match(/width="50px"/)).should be_true
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should not include the height and width attributes on the image tag if it is turned off in the configuration' do
|
84
|
+
GravatarImageTag.configure { |c| c.include_size_attributes = false }
|
85
|
+
(!!view.gravatar_image_tag(email).match(/height=/)).should be_false
|
86
|
+
(!!view.gravatar_image_tag(email).match(/width=/)).should be_false
|
87
|
+
end
|
88
|
+
|
78
89
|
it 'GravatarImageTag#gravitar_id should not error out when email is nil' do
|
79
|
-
lambda { GravatarImageTag::gravatar_id(nil) }.should_not
|
90
|
+
lambda { GravatarImageTag::gravatar_id(nil) }.should_not raise_error(TypeError)
|
80
91
|
end
|
81
92
|
|
82
93
|
end
|
data/spec/test_helper.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require 'spec'
|
2
|
+
#require 'spec'
|
3
3
|
require 'active_support'
|
4
4
|
require 'action_view'
|
5
5
|
require 'digest/md5'
|
6
6
|
require 'uri'
|
7
7
|
|
8
|
-
|
8
|
+
RSpec.configure do |config|
|
9
9
|
end
|
10
10
|
|
11
11
|
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
|
metadata
CHANGED
@@ -1,73 +1,118 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: gravatar_image_tag
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 0
|
10
|
-
version: 1.0.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Michael Deering
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
date: 2012-04-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: &70174494367000 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70174494367000
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: actionpack
|
27
|
+
requirement: &70174494366520 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70174494366520
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: guard
|
38
|
+
requirement: &70174494366040 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70174494366040
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: guard-rspec
|
49
|
+
requirement: &70174494365460 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70174494365460
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: jeweler
|
60
|
+
requirement: &70174494364980 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70174494364980
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: &70174494364400 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70174494364400
|
22
80
|
description:
|
23
81
|
email: mdeering@mdeering.com
|
24
82
|
executables: []
|
25
|
-
|
26
83
|
extensions: []
|
27
|
-
|
28
|
-
extra_rdoc_files:
|
84
|
+
extra_rdoc_files:
|
29
85
|
- README.textile
|
30
|
-
files:
|
86
|
+
files:
|
31
87
|
- MIT-LICENSE
|
32
88
|
- README.textile
|
33
89
|
- Rakefile
|
34
90
|
- lib/gravatar_image_tag.rb
|
35
91
|
- spec/gravatar_image_tag_spec.rb
|
36
92
|
- spec/test_helper.rb
|
37
|
-
has_rdoc: true
|
38
93
|
homepage: http://github.com/mdeering/gravatar_image_tag
|
39
94
|
licenses: []
|
40
|
-
|
41
95
|
post_install_message:
|
42
|
-
rdoc_options:
|
43
|
-
|
44
|
-
require_paths:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
45
98
|
- lib
|
46
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
100
|
none: false
|
48
|
-
requirements:
|
49
|
-
- -
|
50
|
-
- !ruby/object:Gem::Version
|
51
|
-
|
52
|
-
|
53
|
-
- 0
|
54
|
-
version: "0"
|
55
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
106
|
none: false
|
57
|
-
requirements:
|
58
|
-
- -
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
|
61
|
-
segments:
|
62
|
-
- 0
|
63
|
-
version: "0"
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
64
111
|
requirements: []
|
65
|
-
|
66
112
|
rubyforge_project:
|
67
|
-
rubygems_version: 1.
|
113
|
+
rubygems_version: 1.8.10
|
68
114
|
signing_key:
|
69
115
|
specification_version: 3
|
70
|
-
summary: A configurable and documented Rails view helper for adding gravatars into
|
71
|
-
|
72
|
-
|
73
|
-
- spec/test_helper.rb
|
116
|
+
summary: A configurable and documented Rails view helper for adding gravatars into
|
117
|
+
your Rails application.
|
118
|
+
test_files: []
|