adamtanner-aggravatar 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +27 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/lib/aggravatar.rb +51 -0
- data/spec/aggravatar_spec.rb +29 -0
- data/spec/spec_helper.rb +9 -0
- metadata +83 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Adam Tanner
|
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.rdoc
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
= Aggravatar
|
2
|
+
|
3
|
+
You give it an email, it gives you a Gravatar. What more do you want?
|
4
|
+
|
5
|
+
== How to Use It
|
6
|
+
|
7
|
+
First you include Aggravatar.
|
8
|
+
require 'aggravatar'
|
9
|
+
include Aggravatar
|
10
|
+
|
11
|
+
Then you ask it for a Gravatar.
|
12
|
+
gravatar_for("email@example.com")
|
13
|
+
|
14
|
+
Aggravatar even supports the wide array of options Gravatar gives you!
|
15
|
+
gravatar_for("email@example.com", :size => 80, :default => "/my_default_gravatar.png", :rating => 'g')
|
16
|
+
|
17
|
+
I know what you're thinking, and I've already got you covered.
|
18
|
+
You're saying, "Hey, what if I need to add a class/title/id/etc to my Gravatar?!"
|
19
|
+
|
20
|
+
Well here you go:
|
21
|
+
gravatar_for("email@example.com", :html_attributes => {:class => "gravatar", :id => "my_gravatar", :title => "My Gravatar"}")
|
22
|
+
|
23
|
+
You're not limited to just class, title, and id either! You can use any attribute you want! (even ones you make up!)
|
24
|
+
|
25
|
+
== Copyright
|
26
|
+
|
27
|
+
Copyright (c) 2009 Adam Tanner. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "aggravatar"
|
8
|
+
gem.summary = %Q{TODO: one-line summary of your gem}
|
9
|
+
gem.description = %Q{TODO: longer description of your gem}
|
10
|
+
gem.email = "adam@adamtanner.org"
|
11
|
+
gem.homepage = "http://github.com/cxvii/aggravatar"
|
12
|
+
gem.authors = ["Adam Tanner"]
|
13
|
+
gem.add_development_dependency "rspec"
|
14
|
+
gem.add_development_dependency "yard"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'spec/rake/spectask'
|
22
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
+
spec.libs << 'lib' << 'spec'
|
24
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
+
end
|
26
|
+
|
27
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
+
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
spec.rcov = true
|
31
|
+
end
|
32
|
+
|
33
|
+
task :spec => :check_dependencies
|
34
|
+
|
35
|
+
task :default => :spec
|
36
|
+
|
37
|
+
begin
|
38
|
+
require 'yard'
|
39
|
+
YARD::Rake::YardocTask.new
|
40
|
+
rescue LoadError
|
41
|
+
task :yardoc do
|
42
|
+
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
43
|
+
end
|
44
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/aggravatar.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module Aggravatar
|
2
|
+
def self.included(base)
|
3
|
+
base.send(:include, InstanceMethods)
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.host
|
7
|
+
"gravatar.com"
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.path(email_hash)
|
11
|
+
"/avatar/#{email_hash}"
|
12
|
+
end
|
13
|
+
|
14
|
+
module InstanceMethods
|
15
|
+
require 'MD5'
|
16
|
+
require 'URI'
|
17
|
+
|
18
|
+
def gravatar_for(email, options={})
|
19
|
+
build_image_tag(hash(email), options)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def hash(email)
|
24
|
+
MD5.md5(email.strip)
|
25
|
+
end
|
26
|
+
|
27
|
+
def build_image_tag(email_hash, options={})
|
28
|
+
"<img src=\"#{build_url(email_hash, options)}\" #{build_tag_attributes(options[:html_attributes])}/>"
|
29
|
+
end
|
30
|
+
|
31
|
+
def build_tag_attributes(attributes)
|
32
|
+
return nil if attributes.nil?
|
33
|
+
attributes = attributes.inject([]){|array, attribute| array << "#{attribute[0].to_s}=\"#{attribute[1]}\""}.join(" ")
|
34
|
+
end
|
35
|
+
|
36
|
+
def build_query(query_options)
|
37
|
+
query_options = query_options.reject{|key, value| key == :html_attributes}
|
38
|
+
return nil if query_options.empty?
|
39
|
+
query_options[:default] = URI.escape(query_options[:default], ":/")
|
40
|
+
query = query_options.inject([]){|array, option| array << "#{option[0].to_s[0].chr}=#{option[1]}"}.join("&")
|
41
|
+
end
|
42
|
+
|
43
|
+
def build_url(email_hash, query)
|
44
|
+
uri = URI::HTTP.build(
|
45
|
+
:host => Aggravatar.host,
|
46
|
+
:path => Aggravatar.path(email_hash),
|
47
|
+
:query => build_query(query)
|
48
|
+
)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib", "aggravatar.rb")
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
+
|
4
|
+
describe "Aggravatar" do
|
5
|
+
before(:all) do
|
6
|
+
class Helper
|
7
|
+
include Aggravatar
|
8
|
+
end
|
9
|
+
@helper = Helper.new
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should make an image tag for a vanilla Gravatar" do
|
13
|
+
valid_image_tag = "<img src=\"http://gravatar.com/avatar/11591979f29ab9c2bb58868232d07b88\" />"
|
14
|
+
image_tag = @helper.gravatar_for("adam@adamtanner.org")
|
15
|
+
image_tag.should == valid_image_tag
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should make an image tag for a Gravatar using parameters" do
|
19
|
+
valid_image_tag = "<img src=\"http://gravatar.com/avatar/11591979f29ab9c2bb58868232d07b88?d=http%3A%2F%2Fexample.com%2Fimages%2Fdefault.jpg&r=g&s=50\" />"
|
20
|
+
image_tag = @helper.gravatar_for("adam@adamtanner.org", :rating => "g", :default => "http://example.com/images/default.jpg", :size => 50)
|
21
|
+
image_tag.should == valid_image_tag
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should make an image tag for a Gravatar using custom HTML attributes" do
|
25
|
+
valid_image_tag = "<img src=\"http://gravatar.com/avatar/11591979f29ab9c2bb58868232d07b88\" class=\"gravatar\" id=\"my_gravatar\"/>"
|
26
|
+
image_tag = @helper.gravatar_for("adam@adamtanner.org", :html_attributes => {:class => "gravatar", :id => "my_gravatar"})
|
27
|
+
image_tag.should == valid_image_tag
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: adamtanner-aggravatar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Tanner
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-09-23 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: yard
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
description: You give it an email. It gives you a Gravatar. What more do you want?
|
36
|
+
email: adam@adamtanner.org
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .document
|
46
|
+
- .gitignore
|
47
|
+
- LICENSE
|
48
|
+
- README.rdoc
|
49
|
+
- Rakefile
|
50
|
+
- VERSION
|
51
|
+
- lib/aggravatar.rb
|
52
|
+
- spec/aggravatar_spec.rb
|
53
|
+
- spec/spec_helper.rb
|
54
|
+
has_rdoc: true
|
55
|
+
homepage: http://github.com/cxvii/aggravatar
|
56
|
+
licenses:
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options:
|
59
|
+
- --charset=UTF-8
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: "0"
|
73
|
+
version:
|
74
|
+
requirements: []
|
75
|
+
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.3.5
|
78
|
+
signing_key:
|
79
|
+
specification_version: 2
|
80
|
+
summary: "TODO: one-line summary of your gem"
|
81
|
+
test_files:
|
82
|
+
- spec/aggravatar_spec.rb
|
83
|
+
- spec/spec_helper.rb
|