img_gravatar 0.1.1

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/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Till Salzer
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/Manifest ADDED
@@ -0,0 +1,12 @@
1
+ img_gravatar.gemspec
2
+ init.rb
3
+ install.rb
4
+ lib/img_gravatar.rb
5
+ Manifest
6
+ MIT-LICENSE
7
+ Rakefile
8
+ README.rdoc
9
+ tasks/img_gravatar_tasks.rake
10
+ test/img_gravatar_test.rb
11
+ test/module_gravatar_test.rb
12
+ uninstall.rb
data/README.rdoc ADDED
@@ -0,0 +1,75 @@
1
+ = Image Gravatar
2
+
3
+ A simple plugin adding the +img_gravatar+ image link helper to ActionViews.
4
+
5
+ == Install
6
+
7
+ gem install tsalzer-img_gravatar --source http://gems.github.com
8
+
9
+
10
+ == What is a Gravatar?
11
+
12
+ A gravatar is a globally recognized avatar. It is an image hosted on the site
13
+ http://site.gravatar.com, uploaded by the user and referred to on base of
14
+ an eMail address. News on gravatar can be found at http://blog.gravatar.com.
15
+
16
+ Each gravatar image can be rated with respect to its content being suiteable to
17
+ audience.
18
+
19
+ == Usage
20
+
21
+ To use a gravatar on your system, your view needs the eMail address of the
22
+ individual to be displayed. The most simple case is like this:
23
+
24
+ <p>
25
+ <%= img_gravatar('me@email.com') %> That's me.
26
+ </p>
27
+
28
+ This will render the image of the person known under the eMail me@email.com
29
+ in your browser. If there is no person known with this name, it will render
30
+ the Gravatar logo.
31
+
32
+ A more complex szenario would include a size definition, and an alt image tag:
33
+
34
+ <p>
35
+ <%= img_gravetar('me@email.com', { :size => 40, :alt => "That's me." }) %>
36
+ </p>
37
+
38
+ This would render a downsized image of 40x40 with the alt-tag "That's me.".
39
+
40
+ For a complete description of available parameters see
41
+ Gravatar::InstanceMethods#gravatar in the Gravatar::InstanceMethods.
42
+
43
+ === Configuration Options
44
+
45
+ You can modify the following aspects of the displayed gravatar image:
46
+ * :alt - the alternative text for this image
47
+ * :default_url - the default URL for this gravatar
48
+ * :size - the requested gravatar size
49
+ * :rating - the requested maximum rating
50
+
51
+ == Building a new Gem
52
+
53
+ To create a new gem, you need to install the echoe gem (see
54
+ http://blog.evanweaver.com/files/doc/fauna/echoe/files/README.html).
55
+ Next, edit the Rakefile to reflect your changes, then run:
56
+
57
+ rake clobber # remove generated stuff for a clean manifest
58
+ rake manifest # only needed if you changed the file set
59
+ rake build_gemspec # update the gemspec
60
+
61
+ Now, you can either publish the gem, or build a gem package. See rake -T for
62
+ available targets.
63
+
64
+ == License
65
+
66
+ The img_gravatar gem comes to you under the MIT License. You should find the
67
+ license text in the file MIT-LICENSE in the gem folder.
68
+
69
+ The img_gravatar gem is not affiliated with the Gravatar service. Usage terms
70
+ of the Gravatar service should be looked up at http://gravatar.com.
71
+
72
+ Please note that changes to the Gravatar API or their terms of service or the
73
+ cease of Gravatar service may result in breaking the img_gravatar gem
74
+ functionality. This is considered out of the responsibility of the author of
75
+ the img_gravatar gem.
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # Rakefile for img_gravatar
2
+ require 'rubygems'
3
+ require 'rake'
4
+ require 'echoe'
5
+
6
+ Echoe.new('img_gravatar', '0.1.1') do |p|
7
+ p.description = "Add a img_gravatar helper to ActiveView."
8
+ p.url = "http://github.com/tsalzer/img_gravatar"
9
+ p.author = "Till Salzer"
10
+ p.email = "till.salzer@googlemail.com"
11
+ p.ignore_pattern = ["tmp/*", "script/*", "rdoc/*", "pkg/*", "gravatar.tmproj"]
12
+ p.development_dependencies = []
13
+ p.rdoc_pattern = /^(lib|bin|tasks|ext)|^README.rdoc|^CHANGELOG|^TODO|^MIT-LICENSE|^COPYING$/
14
+ end
15
+
16
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{img_gravatar}
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Till Salzer"]
9
+ s.date = %q{2009-02-18}
10
+ s.description = %q{Add a img_gravatar helper to ActiveView.}
11
+ s.email = %q{till.salzer@googlemail.com}
12
+ s.extra_rdoc_files = ["lib/img_gravatar.rb", "MIT-LICENSE", "README.rdoc", "tasks/img_gravatar_tasks.rake"]
13
+ s.files = ["img_gravatar.gemspec", "init.rb", "install.rb", "lib/img_gravatar.rb", "Manifest", "MIT-LICENSE", "Rakefile", "README.rdoc", "tasks/img_gravatar_tasks.rake", "test/img_gravatar_test.rb", "test/module_gravatar_test.rb", "uninstall.rb"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://github.com/tsalzer/img_gravatar}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Img_gravatar", "--main", "README.rdoc"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{img_gravatar}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{Add a img_gravatar helper to ActiveView.}
21
+ s.test_files = ["test/img_gravatar_test.rb", "test/module_gravatar_test.rb"]
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 2
26
+
27
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ else
29
+ end
30
+ else
31
+ end
32
+ end
data/init.rb ADDED
@@ -0,0 +1,3 @@
1
+ # Include hook code here
2
+
3
+ require 'gravatar'
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,126 @@
1
+ require 'md5'
2
+ require 'uri'
3
+ require 'action_view'
4
+
5
+ # = Gravatar
6
+ #
7
+ # Adds the +gravatar+ method to ActionViews.
8
+ #
9
+ # $Id$
10
+ module ImgGravatar #:nodoc:
11
+ mattr_reader :gravatar_host
12
+ @@gravatar_host = 'www.gravatar.com'
13
+ # gravatar.com base URL.
14
+ # This is +http://www.gravatar.com/avatar/+.
15
+ mattr_reader :gravatar_base_url
16
+ @@gravatar_base_url = "http://#{@@gravatar_host}/avatar"
17
+
18
+ # default image URL. Default is +/img/no_gravatar.png+.
19
+ mattr_accessor :default_img_url
20
+ @@default_img_url = '/img/no_gravatar.png'
21
+
22
+ mattr_reader :minimum_size
23
+ @@minimum_size = 1
24
+ mattr_reader :maximum_size
25
+ @@maximum_size = 512
26
+
27
+ # Default size of the image in pixel. Default is +80+.
28
+ mattr_accessor :default_size
29
+ @@default_size = 80
30
+
31
+ # default rating.
32
+ # Valid values are +g+, +r+, +x+, default is +g+.
33
+ mattr_accessor :default_rating
34
+ @@default_rating = 'g'
35
+
36
+ ############################################################################
37
+ # get the Gravatar image.
38
+ # options:
39
+ # :alt - the alternative text for this image
40
+ # :default_url - the default URL for this gravatar
41
+ # :size - the requested gravatar size
42
+ # :rating - the requested maximum rating
43
+ def self.link_gravatar(email, opts={})
44
+ # the defaults
45
+ alt = nil
46
+ alt = opts[:alt] if opts[:alt]
47
+
48
+ if alt then
49
+ "<img src=\"%s\" alt=\"%s\" />" % [image_url(email, opts), alt]
50
+ else
51
+ "<img src=\"%s\" />" % image_url(email, opts)
52
+ end
53
+ end
54
+
55
+ ############################################################################
56
+ # get the default Gravatar image.
57
+ # options:
58
+ # :default_url - the default URL for this gravatar
59
+ # :size - the requested gravatar size
60
+ # :rating - the requested maximum rating
61
+ def self.image_url(email, opts={})
62
+ appender = '?'
63
+
64
+ # now, load infos from options
65
+ default_img_url = check_default_opt(opts[:default_url])
66
+ size = check_size_opt(opts[:size] )
67
+ rating = check_rating_opt(opts[:rating])
68
+
69
+ query = nil
70
+ query = "s=%s" % size if size
71
+ query = query ? "%s&r=%s" % [query, rating] : "r=%s" % rating if rating
72
+ query = query ? "%s&d=%s" % [query, default_img_url] : "d=%s" % default_img_url if default_img_url
73
+
74
+ query = URI.escape(query) if query
75
+
76
+ #uri = URI::HTTP.new(Gravatar.gravatar_base_url)
77
+ uri = URI::HTTP.build(:host => ImgGravatar.gravatar_host,
78
+ :path => "/avatar/%s" % MD5.md5(email.downcase.strip),
79
+ :query => query)
80
+ end
81
+
82
+ # Methods injected in all ActionView classes.
83
+ module Base #:nodoc:
84
+ def self.included(mod) #:nodoc:
85
+ mod.extend(ClassMethods)
86
+ end
87
+ end
88
+
89
+ # Methods injected in all ActionView classes.
90
+ module ClassMethods #:nodoc:
91
+ def self.extended(mod) #:nodoc#
92
+ class_eval do
93
+ include Gravatar::InstanceMethods
94
+ end
95
+ end
96
+ end
97
+
98
+ module InstanceMethods
99
+ ############################################################################
100
+ # get the Gravatar image.
101
+ # See ImgGravatar.link_gravatar for options.
102
+ def img_gravatar(email, opts={})
103
+ return ::ImgGravatar.link_gravatar(email, opts)
104
+ end
105
+ end
106
+
107
+ private
108
+
109
+ def self.check_size_opt(size)
110
+ return size if size and size >= ImgGravatar.minimum_size and size <= ImgGravatar.maximum_size
111
+ end
112
+
113
+ def self.check_rating_opt(rating)
114
+ return rating if rating and ['g', 'r', 'x'].include?(rating)
115
+ end
116
+
117
+ def self.check_default_opt(dflt)
118
+ return dflt if dflt
119
+ end
120
+
121
+ end
122
+
123
+ # inject into ActionView.
124
+ ActionView::Base.send :include, ImgGravatar::InstanceMethods
125
+
126
+
@@ -0,0 +1,29 @@
1
+ # desc "Explaining what the task does"
2
+ # task :gravatar do
3
+ # # Task goes here
4
+ # end
5
+
6
+ =begin
7
+ require 'rake/testtask'
8
+ require 'rake/rdoctask'
9
+
10
+
11
+ desc 'Default: run unit tests.'
12
+ task :default => :test
13
+
14
+ desc 'Test the gravatar plugin.'
15
+ Rake::TestTask.new(:test) do |t|
16
+ t.libs << 'lib'
17
+ t.pattern = 'test/**/*_test.rb'
18
+ t.verbose = true
19
+ end
20
+
21
+ desc 'Generate documentation for the gravatar plugin.'
22
+ Rake::RDocTask.new(:rdoc) do |rdoc|
23
+ rdoc.rdoc_dir = 'rdoc'
24
+ rdoc.title = 'Image Gravatar'
25
+ rdoc.options << '--line-numbers' << '--inline-source'
26
+ rdoc.rdoc_files.include('README.rdoc')
27
+ rdoc.rdoc_files.include('lib/**/*.rb')
28
+ end
29
+ =end
@@ -0,0 +1,88 @@
1
+ # Unit tests for ImgGravatar
2
+ require 'test/unit'
3
+ require 'img_gravatar'
4
+
5
+ class TestView < ActionView::Base
6
+ end
7
+
8
+ class ImgGravatarTest < Test::Unit::TestCase
9
+ @@gravatar_host = "www.gravatar.com"
10
+ @@base_url = "http://#{@@gravatar_host}/avatar"
11
+ @@ref_mail = "iHaveAn@email.com"
12
+ @@ref_hash = "3b3be63a4c2a439b013787725dfce802"
13
+
14
+
15
+ def test_actionview_integration
16
+ myview = TestView.new
17
+ assert myview.respond_to?('img_gravatar'), "integration into ActionView failed"
18
+ end
19
+
20
+ def test_reference_data
21
+ myview = TestView.new
22
+ # the reference data from http://en.gravatar.com/site/implement/url
23
+ link_url = myview.img_gravatar(@@ref_mail)
24
+ assert_match(/^<img src="#{@@base_url}\/#{@@ref_hash}\" \/>/, link_url)
25
+ #assert_match(/^<img src="http:\/\/www\.gravatar\.com\/avatar\/#{ref_hash}\" \/>/, link_url)
26
+ end
27
+
28
+ def test_actionview_url
29
+ myview = TestView.new
30
+ link_url = myview.img_gravatar(@@ref_mail)
31
+ assert_match(/^<img src="#{@@base_url}\/[a-z0-9]{32}\" \/>/, link_url)
32
+ end
33
+
34
+ def test_defaults
35
+ myview = TestView.new
36
+ link_url = myview.img_gravatar(@@ref_mail)
37
+ assert_match(/^<img src="#{@@base_url}\/[a-z0-9]{32}\" \/>/, link_url)
38
+ end
39
+
40
+ def test_actionview_ratings
41
+ myview = TestView.new
42
+ ['g', 'r', 'x'].each do |rating|
43
+ link_url = myview.img_gravatar(@@ref_mail, {:rating => rating})
44
+ assert_match(/^<img src="#{@@base_url}\/[a-z0-9]{32}\?r=#{rating}\" \/>/, link_url)
45
+ end
46
+ end
47
+
48
+ def test_actionview_size
49
+ myview = TestView.new
50
+ (1..512).each do |size|
51
+ link_url = myview.img_gravatar(@@ref_mail, {:size => size})
52
+ assert_match(/^<img src="#{@@base_url}\/[a-z0-9]{32}\?s=#{size}\" \/>/, link_url)
53
+ end
54
+ end
55
+
56
+ def test_illegal_small_sizes
57
+ myview = TestView.new
58
+ (-10..0).each do |size|
59
+ link_url = myview.img_gravatar(@@ref_mail, {:size => size})
60
+ assert_match(/^<img src="#{@@base_url}\/[a-z0-9]{32}\" \/>/, link_url)
61
+ end
62
+ end
63
+
64
+ def test_illegal_large_sizes
65
+ myview = TestView.new
66
+ (513..10000).each do |size|
67
+ link_url = myview.img_gravatar(@@ref_mail, {:size => size})
68
+ assert_match(/^<img src="#{@@base_url}\/[a-z0-9]{32}\" \/>/, link_url)
69
+ end
70
+ end
71
+
72
+ def test_default_image_encoding
73
+ myview = TestView.new
74
+ unencoded = "http://example.com/images/example.jpg"
75
+ encoded = 'http%3A%2F%2Fexample.com%2Fimages%2Fexample.jpg'
76
+ link_url = myview.img_gravatar(@@ref_mail, {:default_url => unencoded})
77
+ assert_match(/^<img src="#{@@base_url}\/[a-z0-9]{32}\?d=#{encoded}\" \/>/, link_url)
78
+ end
79
+
80
+ def test_default_image_specials
81
+ myview = TestView.new
82
+ ['identicon', 'monsterid', 'wavatar'].each do |dflt|
83
+ link_url = myview.img_gravatar(@@ref_mail, {:default_url => dflt})
84
+ assert_match(/^<img src="#{@@base_url}\/[a-z0-9]{32}\?d=#{dflt}\" \/>/, link_url)
85
+ end
86
+ end
87
+
88
+ end
@@ -0,0 +1,22 @@
1
+ # Unit tests for ImgGravatar
2
+ require 'test/unit'
3
+ require 'img_gravatar'
4
+
5
+ class ModuleGravatarTest < Test::Unit::TestCase
6
+ @@gravatar_host = "www.gravatar.com"
7
+ @@base_url = "http://#{@@gravatar_host}/avatar"
8
+ @@ref_mail = "iHaveAn@email.com"
9
+ @@ref_hash = "3b3be63a4c2a439b013787725dfce802"
10
+
11
+ def test_module_functions
12
+ assert(ImgGravatar.respond_to?('image_url'), 'Module ImgGravatar does not respond to image_url')
13
+ assert(ImgGravatar.respond_to?('link_gravatar'), 'Module ImgGravatar does not respond to link_grevatar')
14
+ end
15
+
16
+ def test_reference_data
17
+ # the reference data from http://en.gravatar.com/site/implement/url
18
+ link_url = ImgGravatar.link_gravatar(@@ref_mail)
19
+ assert_match(/^<img src="#{@@base_url}\/#{@@ref_hash}\" \/>/, link_url)
20
+ #assert_match(/^<img src="http:\/\/www\.gravatar\.com\/avatar\/#{ref_hash}\" \/>/, link_url)
21
+ end
22
+ end
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: img_gravatar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Till Salzer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-18 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Add a img_gravatar helper to ActiveView.
17
+ email: till.salzer@googlemail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - lib/img_gravatar.rb
24
+ - MIT-LICENSE
25
+ - README.rdoc
26
+ - tasks/img_gravatar_tasks.rake
27
+ files:
28
+ - img_gravatar.gemspec
29
+ - init.rb
30
+ - install.rb
31
+ - lib/img_gravatar.rb
32
+ - Manifest
33
+ - MIT-LICENSE
34
+ - Rakefile
35
+ - README.rdoc
36
+ - tasks/img_gravatar_tasks.rake
37
+ - test/img_gravatar_test.rb
38
+ - test/module_gravatar_test.rb
39
+ - uninstall.rb
40
+ has_rdoc: true
41
+ homepage: http://github.com/tsalzer/img_gravatar
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --line-numbers
47
+ - --inline-source
48
+ - --title
49
+ - Img_gravatar
50
+ - --main
51
+ - README.rdoc
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "1.2"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project: img_gravatar
69
+ rubygems_version: 1.3.4
70
+ signing_key:
71
+ specification_version: 2
72
+ summary: Add a img_gravatar helper to ActiveView.
73
+ test_files:
74
+ - test/img_gravatar_test.rb
75
+ - test/module_gravatar_test.rb