rails_gravatar 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/rails_gravatar.rb +57 -0
  3. metadata +71 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 733c4feb5eecf01dc5d4f6945c1ff248f030ba3f458ea5aee170a17baf3538cf
4
+ data.tar.gz: 534cc069a665c3981872a8a1c16aa28efda4b7509104220da329d56d346da7c6
5
+ SHA512:
6
+ metadata.gz: db2d472104a7496fb7fca30f28095ef2212ebc6c0e74c9f499696d32ab56e6b4a561184fef04e957a573dc27a32c44033fc2d8eca82bef915633e210e827f276
7
+ data.tar.gz: bdade91dea7fa02f27f0a853dd7df5a0c08e616196544417395a8eabc78d6ad52275deb8c088b1544df9657a8d418f2899ec42859fb49f9bf4403006805fecee
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+ require "digest/md5"
3
+ require "cgi"
4
+ require "action_view"
5
+
6
+ class RailsGravatar
7
+ include ActionView::Helpers::TagHelper
8
+
9
+ DEFAULT_SIZE = 64
10
+
11
+ class << self
12
+ def prefetch_dns_tag
13
+ new.prefetch_dns_tag
14
+ end
15
+
16
+ def src(email_address, size = DEFAULT_SIZE, fallback_image_url = nil)
17
+ new(email_address, size, fallback_image_url).src
18
+ end
19
+
20
+ def tag(email_address, size = DEFAULT_SIZE, fallback_image_url = nil, alt_text = nil)
21
+ new(email_address, size, fallback_image_url, alt_text).tag
22
+ end
23
+ end
24
+
25
+ def initialize(email_address = nil, size = DEFAULT_SIZE, fallback_image_url = nil, alt_text = nil)
26
+ @email_address = email_address
27
+ @size = size
28
+ @fallback_image_url = fallback_image_url
29
+ @alt_text = alt_text
30
+ end
31
+
32
+ def src
33
+ [
34
+ "//www.gravatar.com/avatar/",
35
+ Digest::MD5.hexdigest(email_address.downcase.strip),
36
+ "?s=#{size.clamp(1, 2048)}",
37
+ fallback_image_url ? "&d=#{CGI.escape(fallback_image_url)}" : nil
38
+ ].join
39
+ rescue Exception => e
40
+ nil
41
+ end
42
+
43
+ def tag
44
+ content_tag(:img, nil, src: src, class: "gravatar", alt: alt_text)
45
+ end
46
+
47
+ def prefetch_dns_tag
48
+ content_tag(:link, nil, rel: "dns-prefetch", href: "//gravatar.com")
49
+ end
50
+
51
+ private
52
+
53
+ attr_reader :email_address, :size, :fallback_image_url, :alt_text
54
+ end
55
+
56
+
57
+
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_gravatar
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ricky Chilcott
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-04-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionview
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A simple gem for for generating Gravatar images and tags in a Rails environment.
42
+ email: ricky@missionmet.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - lib/rails_gravatar.rb
48
+ homepage: http://github.com/missionmet/rails-gravatar
49
+ licenses:
50
+ - MIT
51
+ metadata: {}
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubygems_version: 3.0.3
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: rails-gravatar
71
+ test_files: []