gravtastic 2.2.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,9 +12,9 @@ The best way to learn more about Gravtastic is to [look at the source](http://gi
12
12
 
13
13
  ## Usage
14
14
 
15
- Add this to your `environment.rb`:
15
+ Add this to your `Gemfile`:
16
16
 
17
- config.gem 'gravtastic', :version => '>= 2.1.0'
17
+ gem 'gravtastic'
18
18
 
19
19
  Next, say that you want a Gravatar for your model:
20
20
 
@@ -40,20 +40,6 @@ Now all your Gravatars will come from a secure connection, be a GIF and be 120x1
40
40
 
41
41
  _Note: You can use either `is_gravtastic!` or `is_gravtastic`, they both do the same thing._
42
42
 
43
- ### Plain Ruby
44
-
45
- So you just have a regular ol' Ruby app? No Rails and ActiveRecord?
46
-
47
- require 'gravtastic'
48
- class BoringUser
49
- include Gravtastic
50
- is_gravtastic!
51
- end
52
-
53
- And wallah! That works exactly the same as in Rails! Now all instances of the BoringUser class will have `#gravatar_url` methods.
54
-
55
- _Note: the `#gravatar_url` methods don't get included until you specify the class `is_gravtastic!`_
56
-
57
43
  ### Complete List of Options
58
44
 
59
45
  <table>
@@ -95,6 +81,58 @@ _Note: the `#gravatar_url` methods don't get included until you specify the clas
95
81
  </tr>
96
82
  </table>
97
83
 
84
+ ## Other ORM
85
+
86
+ ### Plain Ruby
87
+
88
+ So you just have a regular ol' Ruby app? No Rails and ActiveRecord?
89
+
90
+ require 'gravtastic'
91
+ class BoringUser
92
+ include Gravtastic
93
+ is_gravtastic!
94
+ end
95
+
96
+ And wallah! That works exactly the same as in Rails! Now all instances of the BoringUser class will have `#gravatar_url` methods.
97
+
98
+ _Note: the `#gravatar_url` methods don't get included until you specify the class `is_gravtastic!`_
99
+
100
+ ### DataMapper
101
+
102
+ require 'dm-core'
103
+ require 'gravtastic'
104
+ class User
105
+ include DataMapper::Resource
106
+ is :gravtastic
107
+ end
108
+
109
+ ### Sequel
110
+
111
+ require 'sequel'
112
+ require 'gravtastic'
113
+ class User < Sequel::Model
114
+ plugin Gravtastic
115
+ end
116
+
117
+ ### MongoMapper
118
+
119
+ require 'mongo_mapper'
120
+ require 'gravtastic'
121
+ class User
122
+ include MongoMapper::Document
123
+ plugin Gravtastic
124
+ end
125
+
126
+ ### Mongoid
127
+
128
+ require 'mongoid'
129
+ require 'gravtastic'
130
+ class User
131
+ include Mongoid::Document
132
+ is_gravtastic
133
+ end
134
+
135
+
98
136
  ## Making Changes Yourself
99
137
 
100
138
  Fork the project, submit a pull request and I'll get to it straight away. Or you can just view the source like:
@@ -104,10 +142,14 @@ Fork the project, submit a pull request and I'll get to it straight away. Or you
104
142
  ## Thanks
105
143
 
106
144
  * [Xavier Shay](http://rhnh.net) and others for [Enki](http://enkiblog.com) (the reason this was originally written)
107
- * [Matthew Moore](http://www.matthewpaulmoore.com)
108
- * [Vincent Charles](http://vincentcharles.com)
109
- * [Paul Farnell](http://litmusapp.com/blog)
110
- * [Jeff Kreeftmeijer](http://jeffkreeftmeijer.nl/)
145
+ * [Matthew Moore](http://github.com/moorage)
146
+ * [Galen O'Hanlon](http://github.com/gohanlon)
147
+ * [Jason Cheow](http://jasoncheow.com)
148
+ * [Paul Farnell](http://github.com/salted)
149
+ * [Jeff Kreeftmeijer](http://github.com/jeffkreeftmeijer)
150
+ * [Ryan Lewis](http://github.com/c00lryguy)
151
+ * [Arthur Chiu](http://github.com/achiu)
152
+
111
153
 
112
154
  ## License
113
155
 
data/Rakefile CHANGED
@@ -11,7 +11,6 @@ begin
11
11
  end
12
12
  Jeweler::GemcutterTasks.new
13
13
  rescue LoadError
14
- puts "Install jeweler to build gem"
15
14
  end
16
15
 
17
16
  require 'spec/rake/spectask'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.2.0
1
+ 3.0.0
data/lib/gravtastic.rb CHANGED
@@ -4,73 +4,73 @@ require 'uri'
4
4
 
5
5
  module Gravtastic
6
6
 
7
- def self.included(base)
8
- base.extend(SingletonMethods)
9
- end
10
-
11
7
  def self.version
12
8
  File.read(__FILE__.sub('lib/gravtastic.rb','VERSION')).strip
13
9
  end
10
+
11
+ def self.included(model)
12
+ model.extend ManualConfigure
13
+ end
14
+
15
+ def self.apply(model, *args, &blk)
16
+ end
17
+
18
+ def self.configure(model, *args, &blk)
19
+ options = args.last.is_a?(Hash) ? args.pop : {}
20
+
21
+ model.gravatar_defaults = {
22
+ :rating => 'PG',
23
+ :secure => false,
24
+ :filetype => :png
25
+ }.merge(options)
26
+
27
+ model.gravatar_source = args.first || :email
28
+ end
14
29
 
15
- module SingletonMethods
16
-
17
- def is_gravtastic(*args)
30
+ module ManualConfigure
31
+ def is_gravtastic(*args, &blk)
18
32
  extend ClassMethods
19
33
  include InstanceMethods
20
-
21
- options = args.last.is_a?(Hash) ? args.pop : {}
22
- source = args.first || :email
23
-
24
- @gravatar_defaults = {
25
- :rating => 'PG',
26
- :secure => false,
27
- :filetype => :png
28
- }.merge(options)
29
- @gravatar_source = source
34
+ Gravtastic.configure(self, *args, &blk)
35
+ self
30
36
  end
31
37
 
32
38
  alias_method :has_gravatar, :is_gravtastic
33
39
  alias_method :is_gravtastic!, :is_gravtastic
34
-
35
40
  end
36
41
 
37
42
  module ClassMethods
43
+ attr_accessor :gravatar_source, :gravatar_defaults
38
44
 
39
- def gravatar_source
40
- @gravatar_source
41
- end
42
-
43
- def gravatar_defaults
44
- @gravatar_defaults
45
- end
46
-
47
- def gravatar_options
45
+ def gravatar_abbreviations
48
46
  { :size => 's',
49
47
  :default => 'd',
50
48
  :rating => 'r'
51
49
  }
52
50
  end
53
-
54
51
  end
55
52
 
56
53
  module InstanceMethods
57
-
54
+
58
55
  def gravatar_id
59
56
  Digest::MD5.hexdigest(send(self.class.gravatar_source).to_s.downcase)
60
57
  end
61
58
 
62
59
  def gravatar_url(options={})
63
60
  options = self.class.gravatar_defaults.merge(options)
64
- gravatar_hostname(options.delete(:secure)) +
61
+ path = gravatar_hostname(options.delete(:secure)) +
65
62
  gravatar_filename(options.delete(:filetype)) +
66
63
  url_params_from_hash(options)
64
+
65
+ # This would be alot cleaner with .try(:html_safe)
66
+ path.respond_to?(:html_safe) ? path.html_safe : path
67
67
  end
68
68
 
69
69
  private
70
70
 
71
71
  def url_params_from_hash(hash)
72
72
  '?' + hash.map do |key, val|
73
- [self.class.gravatar_options[key.to_sym] || key.to_s, CGI::escape(val.to_s) ].join('=')
73
+ [self.class.gravatar_abbreviations[key.to_sym] || key.to_s, CGI::escape(val.to_s) ].join('=')
74
74
  end.sort.join('&amp;')
75
75
  end
76
76
 
@@ -81,11 +81,15 @@ module Gravtastic
81
81
  def gravatar_filename(filetype)
82
82
  "#{gravatar_id}.#{filetype}"
83
83
  end
84
-
85
84
  end
86
85
 
87
86
  end
88
87
 
88
+ # All these ORMs suck balls. See Sequel or MongoMapper for examples of good
89
+ # plugin systems.
90
+
89
91
  ActiveRecord::Base.send(:include, Gravtastic) if defined?(ActiveRecord) # :nodoc:
90
- DataMapper::Resource.append_inclusions(Gravtastic) if defined?(DataMapper) # :nodoc:
91
- MongoMapper::Document.append_inclusions(Gravtastic) if defined?(MongoMapper) && MongoMapper::Document.respond_to?(:append_inclusions) # :nodoc:
92
+ DataMapper::Model.append_extensions(Gravtastic::ManualConfigure) if defined?(DataMapper) # :nodoc:
93
+ Mongoid::Document.included do
94
+ include Gravtastic
95
+ end if defined?(Mongoid) # :nodoc:
@@ -1,38 +1,52 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
- require 'rubygems'
3
-
4
1
  require 'active_record'
5
- # require 'dm-core'
2
+ require 'dm-core'
3
+ require 'sequel'
4
+ require 'mongo_mapper'
5
+ require 'mongoid'
6
6
  require 'gravtastic'
7
7
 
8
+ describe ActiveRecord do
9
+ it "includes Gravtastic" do
10
+ ActiveRecord::Base.should respond_to(:is_gravtastic)
8
11
 
9
- # class User
10
- # include DataMapper::Resource
11
- # is_gravtastic
12
- # end
13
-
14
- describe ActiveRecord::Base do
12
+ # Class.new(ActiveRecord::Base) do
13
+ # is_gravtastic
14
+ # end.new.should respond_to(:gravatar_url)
15
+ end
16
+ end
15
17
 
18
+ describe DataMapper do
16
19
  it "includes Gravtastic" do
17
- ActiveRecord::Base.included_modules.should include(Gravtastic)
20
+ Class.new do
21
+ include DataMapper::Resource
22
+ is :gravtastic
23
+ end.new.should respond_to(:gravatar_url)
18
24
  end
25
+ end
19
26
 
20
- it "responds to .is_gravtastic" do
21
- ActiveRecord::Base.should respond_to(:is_gravtastic)
27
+ describe Sequel do
28
+ it "includes Gravtastic" do
29
+ Sequel::Model.plugin Gravtastic
30
+ # Class.new(Sequel::Model) do
31
+ # plugin Gravtastic
32
+ # end.new.should respond_to(:gravatar_url)
22
33
  end
23
-
24
34
  end
25
35
 
26
- # describe DataMapper::Resource do
27
- #
28
- # it "includes Gravtastic::Resource" do
29
- # User.included_modules.should include(Gravtastic)
30
- # end
31
- #
32
- # it "responds to .is_gravtastic" do
33
- # User.should respond_to(:is_gravtastic)
34
- # end
35
- #
36
- # end
37
-
36
+ describe MongoMapper do
37
+ it "includes Gravtastic" do
38
+ Class.new do
39
+ include MongoMapper::Document
40
+ plugin Gravtastic
41
+ end.new.should respond_to(:gravatar_url)
42
+ end
43
+ end
38
44
 
45
+ describe Mongoid do
46
+ it "includes Gravtastic" do
47
+ Class.new do
48
+ include Mongoid::Document
49
+ is_gravtastic
50
+ end.new.should respond_to(:gravatar_url)
51
+ end
52
+ end
@@ -1,6 +1,3 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
- require File.dirname(__FILE__) + '/../lib/gravtastic'
3
-
4
1
  describe Gravtastic do
5
2
 
6
3
  before(:each) do
data/spec/helper.rb ADDED
@@ -0,0 +1,5 @@
1
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
2
+
3
+ Spec::Runner.configure do |config|
4
+ config.mock_with :rr
5
+ end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gravtastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ prerelease: false
5
+ segments:
6
+ - 3
7
+ - 0
8
+ - 0
9
+ version: 3.0.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Chris Lloyd
@@ -9,7 +14,7 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-01-03 00:00:00 +11:00
17
+ date: 2010-10-11 00:00:00 +02:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
@@ -29,7 +34,7 @@ files:
29
34
  - lib/gravtastic.rb
30
35
  - spec/gravtastic_integration_spec.rb
31
36
  - spec/gravtastic_spec.rb
32
- - spec/spec_helper.rb
37
+ - spec/helper.rb
33
38
  has_rdoc: true
34
39
  homepage: http://github.com/chrislloyd/gravtastic
35
40
  licenses: []
@@ -40,25 +45,29 @@ rdoc_options:
40
45
  require_paths:
41
46
  - lib
42
47
  required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
43
49
  requirements:
44
50
  - - ">="
45
51
  - !ruby/object:Gem::Version
52
+ segments:
53
+ - 0
46
54
  version: "0"
47
- version:
48
55
  required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
49
57
  requirements:
50
58
  - - ">="
51
59
  - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
52
62
  version: "0"
53
- version:
54
63
  requirements: []
55
64
 
56
65
  rubyforge_project: gravtastic
57
- rubygems_version: 1.3.5
66
+ rubygems_version: 1.3.7
58
67
  signing_key:
59
68
  specification_version: 3
60
69
  summary: Ruby/Gravatar
61
70
  test_files:
62
71
  - spec/gravtastic_integration_spec.rb
63
72
  - spec/gravtastic_spec.rb
64
- - spec/spec_helper.rb
73
+ - spec/helper.rb
data/spec/spec_helper.rb DELETED
@@ -1,15 +0,0 @@
1
- $TESTING=true
2
- $:.push File.join(File.dirname(__FILE__), '..', 'lib')
3
-
4
- def reload_gravtastic!
5
- Object.class_eval { remove_const :Gravtastic } if defined? Gravtastic
6
- require File.join(File.dirname(__FILE__),'../lib/gravtastic')
7
- end
8
-
9
- Spec::Runner.configure do |config|
10
- config.mock_with :rr
11
- end
12
-
13
- class Class
14
- def to_sym; name.to_sym end
15
- end