imageomatic 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 06c6119133165811c725fd96bafc43649fb538b7bc2968a9532b031c106e7298
4
- data.tar.gz: faf5699c37dc7666d504ab8a0bd245ef0242867ff45ba4e84d4a15b2ad96871d
3
+ metadata.gz: 533fb806d3a3ce5ac58f2f79fedb695504ce8e5a2ec2a81772004a27f12c733f
4
+ data.tar.gz: c5bda15752799f09a89b87ae1dd48a4b2ceb0cb87f8a3c315451a0328d80dacb
5
5
  SHA512:
6
- metadata.gz: a5766340cae879938c1faa44a7850ff7a3b173ca94dca76497336b45b1a9012472bb40142044ba1ddc27f561fa85be4b225c68dcf0e2cf27a150f5f884730f5f
7
- data.tar.gz: 2f3f7cc2b4fb13e67417f4aa3d10a28e49fdda77e0dc3e8ae5895e55c20b3302afbdc46c70fb0c645845c7251a402d42434e61d15d0ad6ebbc7bafaf15d3afe7
6
+ metadata.gz: 63106766ef8c74a8705f62204a246f0d47e446ee4fedcd35d4314ef04b5bb6cce1a6bb564ef2ed919f1d955aba22e58e6d291e61328f7c26adc42913ab1f8abd
7
+ data.tar.gz: 29591c03426214e136d0f58eb9d9e0e869714cdf2452e55b2cbf115e6cf0cbeef348dd1d1637750ce74287285091d52b6c3937f42cbb93a09998c2293ea21c73
@@ -24,7 +24,11 @@ module Imageomatic
24
24
  end
25
25
 
26
26
  def url_for_opengraph_image
27
- Imageomatic.client.url_signature.url_for "opengraph", url: url_for(format: :opengraph)
27
+ imageomatic_opengraph_url url: url_for(format: :opengraph)
28
+ end
29
+
30
+ def imageomatic_opengraph_url(*args, **kwargs)
31
+ Imageomatic.client.url_signature.url_for "opengraph", *args, **kwargs
28
32
  end
29
33
 
30
34
  def opengraph
@@ -0,0 +1,51 @@
1
+ module Imageomatic
2
+ module Opengraph
3
+ # Provides a way to specify OpenGraph keys for an OpengraphModel, which can later
4
+ # be iterated upon to generate OpenGraph meta tags.
5
+ class Base
6
+ # Encapsulates OpenGraph properties and provides helpers that are
7
+ # useful for documentation purposes or for reflecting on Ruby objects.
8
+ class Property
9
+ attr_accessor :key, :name, :description, :default
10
+
11
+ def initialize(key, description = nil, default: nil)
12
+ @key = key
13
+ @description = description
14
+ # If we get a string like `og:image:url`, this would give us `url`
15
+ *_, @name = key.rpartition(":")
16
+ @default = default
17
+ end
18
+ end
19
+
20
+ # Allows for the object to be initialized with args like `Image.new(url: "https://example.com/logo.png", alt: "Logo image")`.
21
+ def initialize(**kwargs)
22
+ kwargs.each do |kwarg, value|
23
+ self.send("#{kwarg}=", value)
24
+ rescue NoMethodError
25
+ raise NoMethodError, "#{kwarg.inspect} is not a property of #{self.inspect}"
26
+ end
27
+ end
28
+
29
+ # DSL for creating properties when defining a model.
30
+ def self.property(*args, **kwargs)
31
+ property = Property.new *args, **kwargs
32
+ attr_accessor property.name
33
+ self.properties.append property
34
+ end
35
+
36
+ # Array where properties are registered.
37
+ def self.properties
38
+ @properties ||= []
39
+ end
40
+
41
+ # Iterates through the properties and also gets their value.
42
+ def properties
43
+ Enumerator.new do |y|
44
+ self.class.properties.each do |property|
45
+ y << [ property, (self.send(property.name) || property.default) ]
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,12 @@
1
+ module Imageomatic
2
+ module Opengraph
3
+ class Image < Base
4
+ property "og:image:url", "Identical to og:image."
5
+ property "og:image:secure_url", "An alternate url to use if the webpage requires HTTPS."
6
+ property "og:image:type", "A MIME type for this image."
7
+ property "og:image:width", "The number of pixels wide."
8
+ property "og:image:height", "The number of pixels high."
9
+ property "og:image:alt", "A description of what is in the image (not a caption). If the page specifies an og:image it should specify og:image:alt."
10
+ end
11
+ end
12
+ end
@@ -4,7 +4,7 @@ module Imageomatic
4
4
  include ActionView::Helpers::TagHelper
5
5
 
6
6
  def to_html
7
- tag :meta, property: "og:#{property}", content: content
7
+ tag :meta, property: property, content: content
8
8
  end
9
9
  end
10
10
  end
@@ -0,0 +1,35 @@
1
+ module Imageomatic
2
+ module Opengraph
3
+ # Iterates recursively through an OpenGraph object and gets a bunch of
4
+ # metatags and keys.
5
+ class MetatagMapper
6
+ include ActionView::Helpers::OutputSafetyHelper
7
+
8
+ attr_reader :model
9
+ delegate :context,
10
+ to: :model
11
+
12
+ def initialize(model)
13
+ @model = model
14
+ end
15
+
16
+ def metatags
17
+ Enumerator.new do |y|
18
+ model.properties.each do |property, content|
19
+ if content.respond_to? :properties
20
+ MetatagMapper.new(content).metatags.each do |tag|
21
+ y << tag
22
+ end
23
+ else
24
+ y << Metatag.new(property.key, content) if content.present?
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ def to_html
31
+ safe_join metatags.map(&:to_html), "\n"
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,19 +1,35 @@
1
1
  module Imageomatic
2
2
  module Opengraph
3
- class Model < Struct.new(:title, :image, :description, :type)
4
- include ActionView::Helpers::OutputSafetyHelper
3
+ class Model < Base
4
+ property "og:title", %[The title of your object as it should appear within the graph, e.g., "The Rock".]
5
+ property "og:type", %[The type of your object, e.g., "video.movie". Depending on the type you specify, other properties may also be required.]
6
+ property "og:image", %[An image URL which should represent your object within the graph.]
7
+ property "og:url", %[The canonical URL of your object that will be used as its permanent ID in the graph, e.g., "https://www.imdb.com/title/tt0117500/".]
8
+ property "og:description", %[A one to two sentence description of your object.]
9
+ property "twitter", %[A one to two sentence description of your object.]
5
10
 
6
- def metatags
7
- Enumerator.new do |y|
8
- each_pair do |property, content|
9
- y << Metatag.new(property, content) if content.present?
10
- end
11
- end
11
+ delegate :to_html, to: :metatag_mapper
12
+
13
+ def image
14
+ @image ||= Image.new
12
15
  end
13
16
 
14
- def to_html
15
- safe_join metatags.map(&:to_html), "\n"
17
+ def image=(url)
18
+ image.url = url
16
19
  end
20
+
21
+ def twitter
22
+ @twitter ||= Twitter.new.tap do |twitter|
23
+ twitter.title = title
24
+ twitter.description = description
25
+ twitter.image = image.url
26
+ end
27
+ end
28
+
29
+ private
30
+ def metatag_mapper
31
+ MetatagMapper.new(self)
32
+ end
17
33
  end
18
34
  end
19
35
  end
@@ -0,0 +1,11 @@
1
+ module Imageomatic
2
+ module Opengraph
3
+ class Twitter < Base
4
+ property "twitter:card", "Type of card, which is 'summary_large_image'", default: "summary_large_image"
5
+ property "twitter:site", "Twitter @handle of the account"
6
+ property "twitter:title", "Title of the card, similar to og:title"
7
+ property "twitter:description", "Description of the card, similar to og:description"
8
+ property "twitter:image", "Image URL of the card, similar to og:image"
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Imageomatic
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imageomatic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Gessler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-24 00:00:00.000000000 Z
11
+ date: 2022-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -58,8 +58,12 @@ files:
58
58
  - app/jobs/imageomatic/application_job.rb
59
59
  - app/mailers/imageomatic/application_mailer.rb
60
60
  - app/models/imageomatic/application_record.rb
61
+ - app/models/imageomatic/opengraph/base.rb
62
+ - app/models/imageomatic/opengraph/image.rb
61
63
  - app/models/imageomatic/opengraph/metatag.rb
64
+ - app/models/imageomatic/opengraph/metatag_mapper.rb
62
65
  - app/models/imageomatic/opengraph/model.rb
66
+ - app/models/imageomatic/opengraph/twitter.rb
63
67
  - app/views/layouts/imageomatic/application.html.erb
64
68
  - config/initializers/mime_types.rb
65
69
  - config/routes.rb
@@ -100,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
104
  - !ruby/object:Gem::Version
101
105
  version: '0'
102
106
  requirements: []
103
- rubygems_version: 3.3.15
107
+ rubygems_version: 3.3.20
104
108
  signing_key:
105
109
  specification_version: 4
106
110
  summary: Easiest way to generate fresh images for Rails applications.