tsalzer-img_gravatar 0.0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
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/README.rdoc CHANGED
@@ -47,3 +47,29 @@ You can modify the following aspects of the displayed gravatar image:
47
47
  * :default_url - the default URL for this gravatar
48
48
  * :size - the requested gravatar size
49
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 CHANGED
@@ -3,13 +3,14 @@ require 'rubygems'
3
3
  require 'rake'
4
4
  require 'echoe'
5
5
 
6
- Echoe.new('img_gravatar', '0.0.1') do |p|
6
+ Echoe.new('img_gravatar', '0.1.1') do |p|
7
7
  p.description = "Add a img_gravatar helper to ActiveView."
8
8
  p.url = "http://github.com/tsalzer/img_gravatar"
9
9
  p.author = "Till Salzer"
10
10
  p.email = "till.salzer@googlemail.com"
11
11
  p.ignore_pattern = ["tmp/*", "script/*", "rdoc/*", "pkg/*", "gravatar.tmproj"]
12
12
  p.development_dependencies = []
13
+ p.rdoc_pattern = /^(lib|bin|tasks|ext)|^README.rdoc|^CHANGELOG|^TODO|^MIT-LICENSE|^COPYING$/
13
14
  end
14
15
 
15
16
  Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
data/img_gravatar.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{img_gravatar}
5
- s.version = "0.0.1"
5
+ s.version = "0.1.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Till Salzer"]
9
- s.date = %q{2009-01-20}
9
+ s.date = %q{2009-02-18}
10
10
  s.description = %q{Add a img_gravatar helper to ActiveView.}
11
11
  s.email = %q{till.salzer@googlemail.com}
12
- s.extra_rdoc_files = ["lib/img_gravatar.rb", "README.rdoc", "tasks/img_gravatar_tasks.rake"]
13
- s.files = ["img_gravatar.gemspec", "init.rb", "install.rb", "lib/img_gravatar.rb", "Manifest", "Rakefile", "README.rdoc", "tasks/img_gravatar_tasks.rake", "test/img_gravatar_test.rb", "uninstall.rb"]
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
14
  s.has_rdoc = true
15
15
  s.homepage = %q{http://github.com/tsalzer/img_gravatar}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Img_gravatar", "--main", "README.rdoc"]
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.rubyforge_project = %q{img_gravatar}
19
19
  s.rubygems_version = %q{1.3.1}
20
20
  s.summary = %q{Add a img_gravatar helper to ActiveView.}
21
- s.test_files = ["test/img_gravatar_test.rb"]
21
+ s.test_files = ["test/img_gravatar_test.rb", "test/module_gravatar_test.rb"]
22
22
 
23
23
  if s.respond_to? :specification_version then
24
24
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
data/lib/img_gravatar.rb CHANGED
@@ -33,6 +33,52 @@ module ImgGravatar #:nodoc:
33
33
  mattr_accessor :default_rating
34
34
  @@default_rating = 'g'
35
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
+
36
82
  # Methods injected in all ActionView classes.
37
83
  module Base #:nodoc:
38
84
  def self.included(mod) #:nodoc:
@@ -51,70 +97,30 @@ module ImgGravatar #:nodoc:
51
97
 
52
98
  module InstanceMethods
53
99
  ############################################################################
54
- # get the default Gravatar image.
55
- # options:
56
- # :alt - the alternative text for this image
57
- # :default_url - the default URL for this gravatar
58
- # :size - the requested gravatar size
59
- # :rating - the requested maximum rating
100
+ # get the Gravatar image.
101
+ # See ImgGravatar.link_gravatar for options.
60
102
  def img_gravatar(email, opts={})
61
- # the defaults
62
- alt = nil
63
- appender = '?'
64
-
65
- # now, load infos from options
66
- alt = opts[:alt] if opts[:alt]
67
- default_img_url = check_default_opt(opts[:default_url])
68
- size = check_size_opt(opts[:size] )
69
- rating = check_rating_opt(opts[:rating])
70
-
71
- query = nil
72
- query = "s=%s" % size if size
73
- query = query ? "%s&r=%s" % [query, rating] : "r=%s" % rating if rating
74
- query = query ? "%s&d=%s" % [query, default_img_url] : "d=%s" % default_img_url if default_img_url
75
-
76
- query = URI.escape(query) if query
77
-
78
- #uri = URI::HTTP.new(Gravatar.gravatar_base_url)
79
- uri = URI::HTTP.build(:host => ImgGravatar.gravatar_host,
80
- :path => "/avatar/%s" % MD5.md5(email.downcase.strip),
81
- :query => query)
82
-
83
- if alt then
84
- "<img src=\"%s\" alt=\"%s\" />" % [uri, alt]
85
- else
86
- "<img src=\"%s\" />" % uri
87
- end
88
-
103
+ return ::ImgGravatar.link_gravatar(email, opts)
89
104
  end
105
+ end
90
106
 
91
-
92
- private
93
-
94
- def check_size_opt(size)
95
- if size and size >= ImgGravatar.minimum_size and size <= ImgGravatar.maximum_size
96
- return size
97
- end
98
- end
99
-
100
- def check_rating_opt(rating)
101
- if rating and ['g', 'r', 'x'].include?(rating)
102
- return rating
103
- end
104
- end
105
-
106
- def check_default_opt(dflt)
107
- if dflt
108
- return dflt
109
- end
110
- end
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)
111
115
  end
116
+
117
+ def self.check_default_opt(dflt)
118
+ return dflt if dflt
119
+ end
120
+
112
121
  end
113
122
 
114
123
  # inject into ActionView.
115
- #ActionView::Base.class_eval do
116
- # include Gravatar::Base
117
- #end
118
124
  ActionView::Base.send :include, ImgGravatar::InstanceMethods
119
125
 
120
126
 
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tsalzer-img_gravatar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Till Salzer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-20 00:00:00 -08:00
12
+ date: 2009-02-18 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -21,6 +21,7 @@ extensions: []
21
21
 
22
22
  extra_rdoc_files:
23
23
  - lib/img_gravatar.rb
24
+ - MIT-LICENSE
24
25
  - README.rdoc
25
26
  - tasks/img_gravatar_tasks.rake
26
27
  files:
@@ -29,10 +30,12 @@ files:
29
30
  - install.rb
30
31
  - lib/img_gravatar.rb
31
32
  - Manifest
33
+ - MIT-LICENSE
32
34
  - Rakefile
33
35
  - README.rdoc
34
36
  - tasks/img_gravatar_tasks.rake
35
37
  - test/img_gravatar_test.rb
38
+ - test/module_gravatar_test.rb
36
39
  - uninstall.rb
37
40
  has_rdoc: true
38
41
  homepage: http://github.com/tsalzer/img_gravatar
@@ -67,3 +70,4 @@ specification_version: 2
67
70
  summary: Add a img_gravatar helper to ActiveView.
68
71
  test_files:
69
72
  - test/img_gravatar_test.rb
73
+ - test/module_gravatar_test.rb