to_gravatar 1.0.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/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 James Martin
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,34 @@
1
+ to_gravatar
2
+
3
+ To install… add the following to your Gemfile:
4
+
5
+ gem ‘to_gravatar’, :git => ‘git@github.com:jmartin2683/to_gravatar.git’
6
+
7
+ …and run ‘bundle install’.
8
+
9
+ Then, simply add “has_gravatar” to any model with an :email property. Optionally, you may pass in some other property name which includes the email address… something like:
10
+
11
+ class User < ActiveRecord::Base
12
+
13
+ attr_accessible :some_other_field, :password, :password_confirmation, :remember_me
14
+
15
+ has_gravatar :field => "some_other_field"
16
+
17
+ end
18
+
19
+ In your views… @user.to_gravatar will return the url to the user’s Gravatar. So you can do something like:
20
+
21
+ image_tag @user.to_gravatar
22
+
23
+ You can also add options for the size, default image, rating restriction, ssl. Example:
24
+
25
+ class User < ActiveRecord::Base
26
+
27
+ attr_accessible :some_other_field, :password, :password_confirmation, :remember_me
28
+
29
+ has_gravatar :field => "some_other_field", ### field containing email address. default to :email.
30
+ :default => "http://example.com/example_image.jpg", ### url of default image
31
+ :rating => "g", ### options are "g", "pg", "r", and "x". default to "r".
32
+ :size => 100, ### pixels square. default to 80px.
33
+ :ssl => true ### use https, avoid popups. defaults false.
34
+ end
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'ToGravatar'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rake/testtask'
29
+
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib'
32
+ t.libs << 'test'
33
+ t.pattern = 'test/**/*_test.rb'
34
+ t.verbose = false
35
+ end
36
+
37
+
38
+ task :default => :test
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :to_gravatar do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,35 @@
1
+ module ToGravatar
2
+ module HasGravatar
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ end
7
+
8
+ module ClassMethods
9
+ def has_gravatar(options = {})
10
+ cattr_accessor :gr_field, :gr_size, :gr_default, :gr_rating, :gr_ssl
11
+ self.gr_field = (options[:field] || :email)
12
+ self.gr_size = (options[:size] ||= 80)
13
+ self.gr_default = (options[:default])
14
+ self.gr_rating = (options[:rating] ||= "r")
15
+ self.gr_ssl = (options[:ssl] ||= false)
16
+ end
17
+ end
18
+
19
+
20
+ def to_gravatar
21
+ gr_id = Digest::MD5.hexdigest(self.read_attribute(self.gr_field).downcase)
22
+ if self.gr_ssl == true
23
+ gravatar_url= "https://secure.gravatar.com/avatar/#{gr_id}.png?s=#{self.gr_size}?r=#{self.gr_rating}"
24
+ gravatar_url += "?d=#{self.gr_default}" if self.gr_default
25
+ return gravatar_url
26
+ else
27
+ gravatar_url = "http://gravatar.com/avatar/#{gr_id}.png?s=#{self.gr_size}?r=#{self.gr_rating}"
28
+ gravatar_url += "?d=#{self.gr_default}" if self.gr_default
29
+ return gravatar_url
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ ActiveRecord::Base.send :include, ToGravatar::HasGravatar
@@ -0,0 +1,3 @@
1
+ module ToGravatar
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,4 @@
1
+ require 'to_gravatar/has_gravatar'
2
+
3
+ module ToGravatar
4
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: to_gravatar
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - James Martin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.3
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.3
30
+ - !ruby/object:Gem::Dependency
31
+ name: sqlite3
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: A simple gem to generate Gravatars from email properties.
47
+ email:
48
+ - james@equipteccorp.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/tasks/to_gravatar_tasks.rake
54
+ - lib/to_gravatar/has_gravatar.rb
55
+ - lib/to_gravatar/version.rb
56
+ - lib/to_gravatar.rb
57
+ - MIT-LICENSE
58
+ - Rakefile
59
+ - README.rdoc
60
+ homepage: http://www.equipteccorp.com
61
+ licenses: []
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 1.8.21
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: A simple gem to generate Gravatars from email properties.
84
+ test_files: []