opengraphplus 0.1.2 → 0.1.4
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.
- checksums.yaml +4 -4
- data/lib/opengraphplus/namespace.rb +154 -0
- data/lib/opengraphplus/rails/helper.rb +6 -8
- data/lib/opengraphplus/tag.rb +2 -9
- data/lib/opengraphplus/tags.rb +92 -27
- data/lib/opengraphplus/version.rb +1 -1
- data/lib/opengraphplus.rb +1 -2
- metadata +2 -2
- data/lib/opengraphplus/tags/renderer.rb +0 -78
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 48292c717ae45fcea5cd4273eba0baf9b1d9ebeb646ddc2d9c2cf666894c1f74
|
|
4
|
+
data.tar.gz: 293b987be6c9eee0193d12e601df3e542713e53f631720ddab150b1374a4055b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8e4a720f1974d2177dc7221cbe073dd3d68d57393c6b85d387d602d40bb2cf479c4118f4383ef40973d29c1eeb3fc60323500d29846d296acf64e15c35ff5c58
|
|
7
|
+
data.tar.gz: 8655b837fa39a53ba16b9fd2ca1112f99c04fa4b5472b54f8bc35f74915e23b4dd5b4e4fba0b26dba08b2a8d9fbed7f573ad63927d3e5a12c1c3ff475f19dcd2
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "forwardable"
|
|
4
|
+
|
|
5
|
+
module OpenGraphPlus
|
|
6
|
+
module Namespace
|
|
7
|
+
class Base
|
|
8
|
+
include Enumerable
|
|
9
|
+
|
|
10
|
+
def each(&)
|
|
11
|
+
tags.each do |t|
|
|
12
|
+
case t
|
|
13
|
+
when Base
|
|
14
|
+
t.each(&)
|
|
15
|
+
when Tag
|
|
16
|
+
yield t if t.content
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def tags = []
|
|
22
|
+
|
|
23
|
+
def render_in(rails_view_context)
|
|
24
|
+
rails_view_context.safe_join(map { |tag| tag.render_in(rails_view_context) }, "\n")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def update(**kwargs)
|
|
28
|
+
kwargs.each { |key, value| public_send(:"#{key}=", value) }
|
|
29
|
+
self
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
class Image < Base
|
|
34
|
+
attr_accessor :url, :width, :height, :type, :alt, :secure_url
|
|
35
|
+
|
|
36
|
+
def tags
|
|
37
|
+
[
|
|
38
|
+
Tag.new("og:image", url),
|
|
39
|
+
Tag.new("og:image:secure_url", secure_url),
|
|
40
|
+
Tag.new("og:image:type", type),
|
|
41
|
+
Tag.new("og:image:width", width),
|
|
42
|
+
Tag.new("og:image:height", height),
|
|
43
|
+
Tag.new("og:image:alt", alt),
|
|
44
|
+
]
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
class Plus < Base
|
|
49
|
+
attr_accessor :selector
|
|
50
|
+
attr_reader :style
|
|
51
|
+
|
|
52
|
+
def style=(value)
|
|
53
|
+
@style = case value
|
|
54
|
+
when Hash
|
|
55
|
+
hash_to_css(value)
|
|
56
|
+
else
|
|
57
|
+
value
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def tags
|
|
62
|
+
[
|
|
63
|
+
Tag.new("og:plus:selector", selector),
|
|
64
|
+
Tag.new("og:plus:style", style),
|
|
65
|
+
]
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
private
|
|
69
|
+
|
|
70
|
+
def hash_to_css(hash)
|
|
71
|
+
hash.map { |k, v| "#{k.to_s.tr("_", "-")}: #{v}" }.join("; ")
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
class OG < Base
|
|
76
|
+
attr_accessor :title, :description, :url, :type, :site_name, :locale, :determiner, :audio, :video
|
|
77
|
+
|
|
78
|
+
def image = @image ||= Image.new
|
|
79
|
+
def plus = @plus ||= Plus.new
|
|
80
|
+
|
|
81
|
+
def initialize
|
|
82
|
+
@type = "website"
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def image_url=(url)
|
|
86
|
+
image.url = url
|
|
87
|
+
image.secure_url = url
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def tags
|
|
91
|
+
[
|
|
92
|
+
Tag.new("og:title", title),
|
|
93
|
+
Tag.new("og:description", description),
|
|
94
|
+
Tag.new("og:url", url),
|
|
95
|
+
Tag.new("og:type", type),
|
|
96
|
+
Tag.new("og:site_name", site_name),
|
|
97
|
+
Tag.new("og:locale", locale),
|
|
98
|
+
Tag.new("og:determiner", determiner),
|
|
99
|
+
Tag.new("og:audio", audio),
|
|
100
|
+
Tag.new("og:video", video),
|
|
101
|
+
image,
|
|
102
|
+
plus,
|
|
103
|
+
]
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
class Twitter < Base
|
|
108
|
+
attr_accessor :card, :site, :creator, :title, :description, :image, :image_alt
|
|
109
|
+
|
|
110
|
+
def initialize
|
|
111
|
+
@card = "summary_large_image"
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def tags
|
|
115
|
+
[
|
|
116
|
+
Tag.new("twitter:card", card),
|
|
117
|
+
Tag.new("twitter:site", site),
|
|
118
|
+
Tag.new("twitter:creator", creator),
|
|
119
|
+
Tag.new("twitter:title", title),
|
|
120
|
+
Tag.new("twitter:description", description),
|
|
121
|
+
Tag.new("twitter:image", image),
|
|
122
|
+
Tag.new("twitter:image:alt", image_alt),
|
|
123
|
+
]
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
class Root < Base
|
|
128
|
+
extend Forwardable
|
|
129
|
+
|
|
130
|
+
def og = @og ||= OG.new
|
|
131
|
+
def twitter = @twitter ||= Twitter.new
|
|
132
|
+
|
|
133
|
+
def_delegators :og,
|
|
134
|
+
:title, :title=,
|
|
135
|
+
:description, :description=,
|
|
136
|
+
:url, :url=,
|
|
137
|
+
:type, :type=,
|
|
138
|
+
:site_name, :site_name=,
|
|
139
|
+
:locale, :locale=,
|
|
140
|
+
:determiner, :determiner=,
|
|
141
|
+
:audio, :audio=,
|
|
142
|
+
:video, :video=,
|
|
143
|
+
:image, :image_url=,
|
|
144
|
+
:plus
|
|
145
|
+
|
|
146
|
+
def tags
|
|
147
|
+
[og, twitter]
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# Backwards compatibility
|
|
153
|
+
Tags = Namespace
|
|
154
|
+
end
|
|
@@ -3,21 +3,19 @@
|
|
|
3
3
|
module OpenGraphPlus
|
|
4
4
|
module Rails
|
|
5
5
|
module Helper
|
|
6
|
-
def open_graph(**
|
|
7
|
-
@open_graph_root ||=
|
|
8
|
-
@open_graph_root.update(**
|
|
9
|
-
yield
|
|
6
|
+
def open_graph(**)
|
|
7
|
+
@open_graph_root ||= Namespace::Root.new
|
|
8
|
+
@open_graph_root.update(**)
|
|
9
|
+
yield @open_graph_root if block_given?
|
|
10
10
|
@open_graph_root
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def open_graph_tags
|
|
14
|
-
|
|
15
|
-
Tags::Renderer.new(root).tags
|
|
14
|
+
open_graph.to_a
|
|
16
15
|
end
|
|
17
16
|
|
|
18
17
|
def open_graph_meta_tags
|
|
19
|
-
|
|
20
|
-
result.respond_to?(:html_safe) ? result.html_safe : result
|
|
18
|
+
open_graph.render_in(self)
|
|
21
19
|
end
|
|
22
20
|
end
|
|
23
21
|
end
|
data/lib/opengraphplus/tag.rb
CHANGED
|
@@ -15,15 +15,8 @@ module OpenGraphPlus
|
|
|
15
15
|
%(<meta property="#{escape property}" content="#{escape content}">)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
def render_in(
|
|
19
|
-
|
|
20
|
-
if view_context.respond_to?(:raw)
|
|
21
|
-
view_context.raw(result)
|
|
22
|
-
elsif result.respond_to?(:html_safe)
|
|
23
|
-
result.html_safe
|
|
24
|
-
else
|
|
25
|
-
result
|
|
26
|
-
end
|
|
18
|
+
def render_in(rails_view_context)
|
|
19
|
+
rails_view_context.raw(meta)
|
|
27
20
|
end
|
|
28
21
|
|
|
29
22
|
def to_s
|
data/lib/opengraphplus/tags.rb
CHANGED
|
@@ -5,6 +5,25 @@ require "forwardable"
|
|
|
5
5
|
module OpenGraphPlus
|
|
6
6
|
module Tags
|
|
7
7
|
class Base
|
|
8
|
+
include Enumerable
|
|
9
|
+
|
|
10
|
+
def each(&)
|
|
11
|
+
tags.each do |t|
|
|
12
|
+
case t
|
|
13
|
+
when Base
|
|
14
|
+
t.each(&)
|
|
15
|
+
when Tag
|
|
16
|
+
yield t if t.content
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def tags = []
|
|
22
|
+
|
|
23
|
+
def render_in(view_context)
|
|
24
|
+
map { |tag| tag.render_in(view_context) }.join("\n")
|
|
25
|
+
end
|
|
26
|
+
|
|
8
27
|
def update(**kwargs)
|
|
9
28
|
kwargs.each { |key, value| public_send(:"#{key}=", value) }
|
|
10
29
|
self
|
|
@@ -13,29 +32,16 @@ module OpenGraphPlus
|
|
|
13
32
|
|
|
14
33
|
class Image < Base
|
|
15
34
|
attr_accessor :url, :width, :height, :type, :alt, :secure_url
|
|
16
|
-
end
|
|
17
35
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
attr_accessor :title, :description, :url, :type, :site_name, :locale, :determiner, :audio, :video
|
|
28
|
-
attr_reader :image, :plus
|
|
29
|
-
|
|
30
|
-
def initialize
|
|
31
|
-
@type = "website"
|
|
32
|
-
@image = Image.new
|
|
33
|
-
@plus = Plus.new
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def image_url=(url)
|
|
37
|
-
@image.url = url
|
|
38
|
-
@image.secure_url = url
|
|
36
|
+
def tags
|
|
37
|
+
[
|
|
38
|
+
Tag.new("og:image", url),
|
|
39
|
+
Tag.new("og:image:secure_url", secure_url),
|
|
40
|
+
Tag.new("og:image:type", type),
|
|
41
|
+
Tag.new("og:image:width", width),
|
|
42
|
+
Tag.new("og:image:height", height),
|
|
43
|
+
Tag.new("og:image:alt", alt),
|
|
44
|
+
]
|
|
39
45
|
end
|
|
40
46
|
end
|
|
41
47
|
|
|
@@ -52,6 +58,13 @@ module OpenGraphPlus
|
|
|
52
58
|
end
|
|
53
59
|
end
|
|
54
60
|
|
|
61
|
+
def tags
|
|
62
|
+
[
|
|
63
|
+
Tag.new("og:plus:selector", selector),
|
|
64
|
+
Tag.new("og:plus:style", style),
|
|
65
|
+
]
|
|
66
|
+
end
|
|
67
|
+
|
|
55
68
|
private
|
|
56
69
|
|
|
57
70
|
def hash_to_css(hash)
|
|
@@ -59,12 +72,65 @@ module OpenGraphPlus
|
|
|
59
72
|
end
|
|
60
73
|
end
|
|
61
74
|
|
|
75
|
+
class OpenGraph < Base
|
|
76
|
+
attr_accessor :title, :description, :url, :type, :site_name, :locale, :determiner, :audio, :video
|
|
77
|
+
|
|
78
|
+
def image = @image ||= Image.new
|
|
79
|
+
def plus = @plus ||= Plus.new
|
|
80
|
+
|
|
81
|
+
def initialize
|
|
82
|
+
@type = "website"
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def image_url=(url)
|
|
86
|
+
image.url = url
|
|
87
|
+
image.secure_url = url
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def tags
|
|
91
|
+
[
|
|
92
|
+
Tag.new("og:title", title),
|
|
93
|
+
Tag.new("og:description", description),
|
|
94
|
+
Tag.new("og:url", url),
|
|
95
|
+
Tag.new("og:type", type),
|
|
96
|
+
Tag.new("og:site_name", site_name),
|
|
97
|
+
Tag.new("og:locale", locale),
|
|
98
|
+
Tag.new("og:determiner", determiner),
|
|
99
|
+
Tag.new("og:audio", audio),
|
|
100
|
+
Tag.new("og:video", video),
|
|
101
|
+
image,
|
|
102
|
+
plus,
|
|
103
|
+
]
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
class Twitter < Base
|
|
108
|
+
attr_accessor :card, :site, :creator, :title, :description, :image, :image_alt
|
|
109
|
+
|
|
110
|
+
def initialize
|
|
111
|
+
@card = "summary_large_image"
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def tags
|
|
115
|
+
[
|
|
116
|
+
Tag.new("twitter:card", card),
|
|
117
|
+
Tag.new("twitter:site", site),
|
|
118
|
+
Tag.new("twitter:creator", creator),
|
|
119
|
+
Tag.new("twitter:title", title),
|
|
120
|
+
Tag.new("twitter:description", description),
|
|
121
|
+
Tag.new("twitter:image", image),
|
|
122
|
+
Tag.new("twitter:image:alt", image_alt),
|
|
123
|
+
]
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
62
127
|
class Root < Base
|
|
63
128
|
extend Forwardable
|
|
64
129
|
|
|
65
|
-
|
|
130
|
+
def og = @og ||= OpenGraph.new
|
|
131
|
+
def twitter = @twitter ||= Twitter.new
|
|
66
132
|
|
|
67
|
-
def_delegators
|
|
133
|
+
def_delegators :og,
|
|
68
134
|
:title, :title=,
|
|
69
135
|
:description, :description=,
|
|
70
136
|
:url, :url=,
|
|
@@ -77,9 +143,8 @@ module OpenGraphPlus
|
|
|
77
143
|
:image, :image_url=,
|
|
78
144
|
:plus
|
|
79
145
|
|
|
80
|
-
def
|
|
81
|
-
|
|
82
|
-
@twitter = Twitter.new
|
|
146
|
+
def tags
|
|
147
|
+
[og, twitter]
|
|
83
148
|
end
|
|
84
149
|
end
|
|
85
150
|
end
|
data/lib/opengraphplus.rb
CHANGED
|
@@ -5,8 +5,7 @@ require_relative "opengraphplus/api_key"
|
|
|
5
5
|
require_relative "opengraphplus/configuration"
|
|
6
6
|
require_relative "opengraphplus/signature"
|
|
7
7
|
require_relative "opengraphplus/tag"
|
|
8
|
-
require_relative "opengraphplus/
|
|
9
|
-
require_relative "opengraphplus/tags/renderer"
|
|
8
|
+
require_relative "opengraphplus/namespace"
|
|
10
9
|
require_relative "opengraphplus/image_generator"
|
|
11
10
|
|
|
12
11
|
module OpenGraphPlus
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: opengraphplus
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brad Gessler
|
|
@@ -42,6 +42,7 @@ files:
|
|
|
42
42
|
- lib/opengraphplus/api_key.rb
|
|
43
43
|
- lib/opengraphplus/configuration.rb
|
|
44
44
|
- lib/opengraphplus/image_generator.rb
|
|
45
|
+
- lib/opengraphplus/namespace.rb
|
|
45
46
|
- lib/opengraphplus/rails.rb
|
|
46
47
|
- lib/opengraphplus/rails/controller.rb
|
|
47
48
|
- lib/opengraphplus/rails/helper.rb
|
|
@@ -55,7 +56,6 @@ files:
|
|
|
55
56
|
- lib/opengraphplus/signature/verifier.rb
|
|
56
57
|
- lib/opengraphplus/tag.rb
|
|
57
58
|
- lib/opengraphplus/tags.rb
|
|
58
|
-
- lib/opengraphplus/tags/renderer.rb
|
|
59
59
|
- lib/opengraphplus/version.rb
|
|
60
60
|
- sig/open_graph_plus.rbs
|
|
61
61
|
homepage: https://opengraphplus.com/ruby
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module OpenGraphPlus
|
|
4
|
-
module Tags
|
|
5
|
-
class Renderer
|
|
6
|
-
attr_reader :root
|
|
7
|
-
|
|
8
|
-
def initialize(root)
|
|
9
|
-
@root = root
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def tags
|
|
13
|
-
[*og_tags, *twitter_tags].compact
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
def og
|
|
19
|
-
root.og
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def twitter
|
|
23
|
-
root.twitter
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def tag(property, content)
|
|
27
|
-
return nil if content.nil?
|
|
28
|
-
|
|
29
|
-
Tag.new(property, content)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def og_tags
|
|
33
|
-
[
|
|
34
|
-
tag("og:title", og.title),
|
|
35
|
-
tag("og:description", og.description),
|
|
36
|
-
tag("og:url", og.url),
|
|
37
|
-
tag("og:type", og.type),
|
|
38
|
-
tag("og:site_name", og.site_name),
|
|
39
|
-
tag("og:locale", og.locale),
|
|
40
|
-
tag("og:determiner", og.determiner),
|
|
41
|
-
tag("og:audio", og.audio),
|
|
42
|
-
tag("og:video", og.video),
|
|
43
|
-
*og_image_tags
|
|
44
|
-
]
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def og_image_tags
|
|
48
|
-
return [] unless og.image
|
|
49
|
-
|
|
50
|
-
image = og.image
|
|
51
|
-
[
|
|
52
|
-
tag("og:image", image.url),
|
|
53
|
-
tag("og:image:secure_url", image.secure_url),
|
|
54
|
-
tag("og:image:type", image.type),
|
|
55
|
-
tag("og:image:width", image.width),
|
|
56
|
-
tag("og:image:height", image.height),
|
|
57
|
-
tag("og:image:alt", image.alt)
|
|
58
|
-
]
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def twitter_tags
|
|
62
|
-
[
|
|
63
|
-
tag("twitter:card", twitter.card),
|
|
64
|
-
tag("twitter:site", twitter.site),
|
|
65
|
-
tag("twitter:creator", twitter.creator),
|
|
66
|
-
tag("twitter:title", twitter.title || og.title),
|
|
67
|
-
tag("twitter:description", twitter.description || og.description),
|
|
68
|
-
tag("twitter:image", twitter_image_url),
|
|
69
|
-
tag("twitter:image:alt", twitter.image_alt || og.image&.alt)
|
|
70
|
-
]
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def twitter_image_url
|
|
74
|
-
twitter.image || og.image&.url
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
end
|