aggravatar 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
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,39 @@
1
+
2
+ = Aggravatar
3
+
4
+ You give it an email, it gives you a Gravatar. What more do you want?
5
+
6
+ == How to Use It
7
+ Step 1: First you install it. (Assuming you already have Github sources added.)
8
+ gem install adamtanner-aggravatar
9
+
10
+ Step 2: Then you include Aggravatar in your class.
11
+ require 'aggravatar'
12
+ include Aggravatar
13
+
14
+ == How to Use It From Rails
15
+ Step 1: First you install it as a plugin.
16
+ script/plugin install git://github.com/adamtanner/aggravatar.git
17
+
18
+ Step 2: Skip to Step 3.
19
+
20
+ ----------------------------
21
+
22
+ Step 3: Then you ask it for a Gravatar.
23
+ gravatar_for("email@example.com")
24
+
25
+ Aggravatar even supports the wide array of options Gravatar gives you!
26
+ gravatar_for("email@example.com", :size => 80, :default => "/my_default_gravatar.png", :rating => 'g')
27
+
28
+ I know what you're thinking, and I've already got you covered.
29
+ You're saying, "Hey, what if I need to add a class/title/id/etc to my Gravatar?!"
30
+
31
+ Well here you go:
32
+ gravatar_for("email@example.com", :html_attributes => {:class => "gravatar", :id => "my_gravatar", :title => "My Gravatar"}")
33
+
34
+ You're not limited to just class, title, and id either! You can use any attribute you want! (even ones you make up!)
35
+
36
+ == Copyright
37
+
38
+ Copyright (c) 2009 Adam Tanner. See LICENSE for details.
39
+
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.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_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
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'aggravatar'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: 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 -04: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
+
58
+ post_install_message:
59
+ rdoc_options:
60
+ - --charset=UTF-8
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ requirements: []
76
+
77
+ rubyforge_project:
78
+ rubygems_version: 1.3.5
79
+ signing_key:
80
+ specification_version: 2
81
+ summary: Helper method for generating Gravatars.
82
+ test_files:
83
+ - spec/aggravatar_spec.rb
84
+ - spec/spec_helper.rb