ogg 0.1.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.
- checksums.yaml +7 -0
- data/.travis.yml +15 -0
- data/Gemfile +2 -0
- data/README.md +119 -0
- data/Rakefile +8 -0
- data/lib/ogg.rb +8 -0
- data/lib/ogg/generator.rb +155 -0
- data/lib/ogg/helpers.rb +8 -0
- data/lib/ogg/version.rb +4 -0
- data/ogg.gemspec +17 -0
- data/spec/generator_spec.rb +181 -0
- data/spec/helpers_spec.rb +21 -0
- data/spec/ogg_spec.rb +33 -0
- data/spec/spec_helper.rb +2 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f829a87c09038ec67106a19cbe6b3b6a190bc33f
|
4
|
+
data.tar.gz: 189c2d057139e496775b40d41849a079f1bcae52
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 72c721ac3427fde300a615e3504f4dba4ea64fdb9df49e3f5d1cbf1714351890e6ce195603cfeb4cc5f91104829e9a44136f38dab41d0240c6937ce22bd9d874
|
7
|
+
data.tar.gz: 173a11c642b39921b454fbc0a7e0d7d396f6a9c5049f932288bb93703085d0746a98fd0a44a1214b06f7356bdcc7cfc80c4f1edb5bf76cea17eba373a6571b09
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
# Ogg
|
2
|
+
|
3
|
+
[](https://travis-ci.org/namusyaka/ogg)
|
4
|
+
|
5
|
+
Ogg is an Open Graph Generator, support *Basic Metadata*, *Optional Metadata*, *Structured Properties* at present.
|
6
|
+
|
7
|
+
[Whats is Open Graph?](http://ogp.me/)
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
add this line to your Gemfile. `gem 'ogg'`
|
12
|
+
|
13
|
+
or
|
14
|
+
|
15
|
+
`$ gem install ogg`
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
### Basic
|
20
|
+
|
21
|
+
Basic style.
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'ogg'
|
25
|
+
|
26
|
+
ogg = Ogg.new
|
27
|
+
ogg.title = 'Site Title'
|
28
|
+
ogg.type = 'Article'
|
29
|
+
ogg.description = 'Description'
|
30
|
+
ogg.url = 'http://example.com/'
|
31
|
+
ogg.image = 'http://example.com/example.png'
|
32
|
+
ogg.site_image = 'http://example.com/site_image.png'
|
33
|
+
ogg.email = 'foo@bar.com'
|
34
|
+
ogg.html
|
35
|
+
```
|
36
|
+
|
37
|
+
Ogg support new method with block.
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
ogg = Ogg.new do |o|
|
41
|
+
o.title = 'Site Title'
|
42
|
+
o.type = 'Article'
|
43
|
+
o.description = 'Description'
|
44
|
+
o.url = 'http://example.com/'
|
45
|
+
o.image = 'http://example.com/example.png'
|
46
|
+
o.site_image = 'http://example.com/site_image.png'
|
47
|
+
o.email = 'foo@bar.com'
|
48
|
+
end
|
49
|
+
ogg.html
|
50
|
+
```
|
51
|
+
|
52
|
+
#### `:raise`
|
53
|
+
|
54
|
+
If you set :raise option and basic properties are inadequacy, occurs `InvalidBasicProperty`.
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
ogg = Ogg.new(:raise => true)
|
58
|
+
begin
|
59
|
+
ogg.html
|
60
|
+
rescue InvalidBasicProperty
|
61
|
+
puts "called"
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
### Structured Properties
|
66
|
+
|
67
|
+
#### like accessor
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
ogg = Ogg.new do |o|
|
71
|
+
o.image.url = "http://example.com/example.png"
|
72
|
+
o.image.secure_url = "https://example.com/example.png"
|
73
|
+
o.image.type = "image/png"
|
74
|
+
o.image.width = "400"
|
75
|
+
o.image.height = "300"
|
76
|
+
|
77
|
+
o.video.secure_url = "https://example.com/example.swf"
|
78
|
+
o.video.type = "application/x-shockwave-flash"
|
79
|
+
o.video.width = "400"
|
80
|
+
o.video.height = "300"
|
81
|
+
|
82
|
+
o.audio.secure_url = "https://example.com/example.mp3"
|
83
|
+
o.audio.type = "audio/mpeg"
|
84
|
+
end
|
85
|
+
ogg.html
|
86
|
+
```
|
87
|
+
|
88
|
+
#### like hash
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
ogg = Ogg.new do |o|
|
92
|
+
o.image[:url] = "http://example.com/example.png"
|
93
|
+
o.image[:secure_url] = "https://example.com/example.png"
|
94
|
+
o.image[:type] = "image/png"
|
95
|
+
o.image[:width] = "400"
|
96
|
+
o.image[:height] = "300"
|
97
|
+
|
98
|
+
o.video[:secure_url] = "https://example.com/example.swf"
|
99
|
+
o.video[:type] = "application/x-shockwave-flash"
|
100
|
+
o.video[:width] = "400"
|
101
|
+
o.video[:height] = "300"
|
102
|
+
|
103
|
+
o.audio[:secure_url] = "https://example.com/example.mp3"
|
104
|
+
o.audio[:type] = "audio/mpeg"
|
105
|
+
end
|
106
|
+
ogg.html
|
107
|
+
```
|
108
|
+
|
109
|
+
## Contributing
|
110
|
+
|
111
|
+
1. fork the project.
|
112
|
+
2. create your feature branch. (`git checkout -b my-feature`)
|
113
|
+
3. commit your changes. (`git commit -am 'commit message'`)
|
114
|
+
4. push to the branch. (`git push origin my-feature`
|
115
|
+
5. send pull request.
|
116
|
+
|
117
|
+
## License
|
118
|
+
|
119
|
+
the MIT License
|
data/Rakefile
ADDED
data/lib/ogg.rb
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
|
2
|
+
module Ogg
|
3
|
+
class Generator
|
4
|
+
class InvalidBasicProperty < ArgumentError
|
5
|
+
end
|
6
|
+
|
7
|
+
class Property
|
8
|
+
attr_accessor :content
|
9
|
+
attr_reader :property
|
10
|
+
|
11
|
+
def initialize(property)
|
12
|
+
@property = property
|
13
|
+
@children = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_child(structured_property)
|
17
|
+
raise ArgumentError unless @children
|
18
|
+
@children << structured_property
|
19
|
+
end
|
20
|
+
|
21
|
+
def [](name)
|
22
|
+
return nil unless @children
|
23
|
+
name = name.to_s
|
24
|
+
@children.find{|child| child.property == name }
|
25
|
+
end
|
26
|
+
|
27
|
+
def []=(name, value)
|
28
|
+
child = __send__(:[], name)
|
29
|
+
raise ArgumentError unless child
|
30
|
+
child.content = value
|
31
|
+
end
|
32
|
+
|
33
|
+
def method_missing(name, *args)
|
34
|
+
name = name.to_s
|
35
|
+
structured_property = @children.find{|child| [child.property, "#{child.property}="].include?(name) }
|
36
|
+
super unless structured_property
|
37
|
+
if name[-1] == "="
|
38
|
+
structured_property.content = args.shift
|
39
|
+
else
|
40
|
+
structured_property
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def changed?
|
45
|
+
content
|
46
|
+
end
|
47
|
+
|
48
|
+
def meta_tag
|
49
|
+
tags = []
|
50
|
+
tags << "<meta property=\"og:#{@property}\" content=\"#{content}\">" if changed?
|
51
|
+
@children.each do |child|
|
52
|
+
next unless child.changed?
|
53
|
+
if child.alternative?
|
54
|
+
tags << "<meta property=\"og:#{@property}\" content=\"#{child.content}\"><a></a>" unless changed?
|
55
|
+
else
|
56
|
+
tags << child.meta_tag
|
57
|
+
end
|
58
|
+
end
|
59
|
+
tags.compact.join("\n")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class StructuredProperty < Property
|
64
|
+
def initialize(property, options = {})
|
65
|
+
@property = property
|
66
|
+
@parent = options[:parent]
|
67
|
+
@alternative = options[:alternative]
|
68
|
+
end
|
69
|
+
|
70
|
+
def alternative?
|
71
|
+
@alternative
|
72
|
+
end
|
73
|
+
|
74
|
+
def meta_tag
|
75
|
+
"<meta property=\"og:#{@parent}:#{@property}\" content=\"#{content}\">"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class << self
|
80
|
+
def define_property(name, options = {})
|
81
|
+
define_method(name) do
|
82
|
+
properties = instance_variable_get(:@properties)
|
83
|
+
return properties[name] if properties.is_a?(Hash) and properties[name]
|
84
|
+
properties = instance_variable_set(:@properties, {}) unless properties.is_a?(Hash)
|
85
|
+
property = properties[name] = Property.new(name)
|
86
|
+
options[:children].each do |child|
|
87
|
+
options_for_child = {:parent => name, :alternative => child == "url"}
|
88
|
+
property.add_child(StructuredProperty.new(child, options_for_child))
|
89
|
+
end if options[:children]
|
90
|
+
property
|
91
|
+
end
|
92
|
+
define_method("#{name}=") do |value|
|
93
|
+
property = __send__(name)
|
94
|
+
property.content = value
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def define_properties(names, options = {})
|
99
|
+
names.each{|name| define_property(name, options) }
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
BASIC_PROPERTIES = %w[title type url image]
|
104
|
+
OPTIONAL_PROPERTIES = %w[
|
105
|
+
audio description determiner locale
|
106
|
+
site_name video
|
107
|
+
]
|
108
|
+
STRUCTURED_PROPERTIES = {
|
109
|
+
:image => %w[url secure_url type width height],
|
110
|
+
:video => %w[secure_url type width height],
|
111
|
+
:audio => %w[secure_url type],
|
112
|
+
:locale => %w[alternate]
|
113
|
+
}
|
114
|
+
|
115
|
+
(BASIC_PROPERTIES + OPTIONAL_PROPERTIES).each do |property|
|
116
|
+
options = {}
|
117
|
+
properties = STRUCTURED_PROPERTIES[property.to_sym]
|
118
|
+
options[:children] = properties if properties
|
119
|
+
define_property(property, options)
|
120
|
+
end
|
121
|
+
|
122
|
+
def initialize(options = {}, &block)
|
123
|
+
@raise = options[:raise]
|
124
|
+
instance_eval(&block) if block_given?
|
125
|
+
end
|
126
|
+
|
127
|
+
def basic_properties
|
128
|
+
BASIC_PROPERTIES.map{|name|
|
129
|
+
property_instance = __send__(name)
|
130
|
+
raise_invalid_basic_property(name) if @raise and !property_instance.content
|
131
|
+
property_instance.meta_tag
|
132
|
+
}.delete_if(&:empty?).join("\n")
|
133
|
+
end
|
134
|
+
|
135
|
+
def optional_properties
|
136
|
+
OPTIONAL_PROPERTIES.map{|name|
|
137
|
+
property_instance = __send__(name)
|
138
|
+
property_instance.meta_tag
|
139
|
+
}.delete_if(&:empty?).join("\n")
|
140
|
+
end
|
141
|
+
|
142
|
+
def html
|
143
|
+
@properties ||= {}
|
144
|
+
if @raise
|
145
|
+
diff = BASIC_PROPERTIES - @properties.keys
|
146
|
+
raise_invalid_basic_property(diff * ", ") unless diff.empty?
|
147
|
+
end
|
148
|
+
@properties.values.map(&:meta_tag).delete_if(&:empty?).join("\n")
|
149
|
+
end
|
150
|
+
|
151
|
+
def raise_invalid_basic_property(name)
|
152
|
+
raise InvalidBasicProperty, "`#{name}` should be set."
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
data/lib/ogg/helpers.rb
ADDED
data/lib/ogg/version.rb
ADDED
data/ogg.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path("../lib/ogg/version", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new "ogg", Ogg::VERSION do |s|
|
4
|
+
s.description = "Ogg is an Open Graph Generator."
|
5
|
+
s.summary = s.description
|
6
|
+
s.author = "namusyaka"
|
7
|
+
s.email = "namusyaka@gmail.com"
|
8
|
+
s.homepage = "https://github.com/namusyaka/ogg"
|
9
|
+
s.files = `git ls-files`.split("\n") - %w(.gitignore)
|
10
|
+
s.test_files = s.files.select { |path| path =~ /^spec\/.*_spec\.rb/ }
|
11
|
+
s.license = "MIT"
|
12
|
+
|
13
|
+
s.add_development_dependency "rake"
|
14
|
+
s.add_development_dependency "rspec"
|
15
|
+
s.add_development_dependency "rspec-html-matchers"
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,181 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__))
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
module Ogg
|
5
|
+
describe Generator do
|
6
|
+
it "support basic properties" do
|
7
|
+
ogg = Ogg::Generator.new
|
8
|
+
ogg.title = "Site Title"
|
9
|
+
ogg.type = "Article"
|
10
|
+
ogg.image = "http://example.com/example.png"
|
11
|
+
ogg.url = "http://example.com/"
|
12
|
+
actual_html = ogg.html
|
13
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:title", :content => "Site Title"})
|
14
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:type", :content => "Article"})
|
15
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:image", :content => "http://example.com/example.png"})
|
16
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:url", :content => "http://example.com/"})
|
17
|
+
end
|
18
|
+
|
19
|
+
it "support basic properties with block" do
|
20
|
+
ogg = Ogg::Generator.new do |o|
|
21
|
+
o.title = "Site Title"
|
22
|
+
o.type = "Article"
|
23
|
+
o.image = "http://example.com/example.png"
|
24
|
+
o.url = "http://example.com/"
|
25
|
+
end
|
26
|
+
actual_html = ogg.html
|
27
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:title", :content => "Site Title"})
|
28
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:type", :content => "Article"})
|
29
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:image", :content => "http://example.com/example.png"})
|
30
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:url", :content => "http://example.com/"})
|
31
|
+
end
|
32
|
+
|
33
|
+
it "support optional properties" do
|
34
|
+
ogg = Ogg::Generator.new do |o|
|
35
|
+
o.audio = "Audio"
|
36
|
+
o.description = "Description"
|
37
|
+
o.determiner = "Determiner"
|
38
|
+
o.locale = "en_US"
|
39
|
+
o.site_name = "Example Site"
|
40
|
+
o.video = "Video"
|
41
|
+
end
|
42
|
+
actual_html = ogg.html
|
43
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:audio", :content => "Audio"})
|
44
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:description", :content => "Description"})
|
45
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:determiner", :content => "Determiner"})
|
46
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:locale", :content => "en_US"})
|
47
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:site_name", :content => "Example Site"})
|
48
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:video", :content => "Video"})
|
49
|
+
end
|
50
|
+
|
51
|
+
it "support structured properties as accessor" do
|
52
|
+
ogg = Ogg::Generator.new do |o|
|
53
|
+
o.image.url = "http://example.com/example.png"
|
54
|
+
o.image.secure_url = "https://example.com/example.png"
|
55
|
+
o.image.type = "image/png"
|
56
|
+
o.image.width = "400"
|
57
|
+
o.image.height = "300"
|
58
|
+
|
59
|
+
o.video.secure_url = "https://example.com/example.swf"
|
60
|
+
o.video.type = "application/x-shockwave-flash"
|
61
|
+
o.video.width = "400"
|
62
|
+
o.video.height = "300"
|
63
|
+
|
64
|
+
o.audio.secure_url = "https://example.com/example.mp3"
|
65
|
+
o.audio.type = "audio/mpeg"
|
66
|
+
end
|
67
|
+
actual_html = ogg.html
|
68
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:image", :content => "http://example.com/example.png"})
|
69
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:image:secure_url", :content => "https://example.com/example.png"})
|
70
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:image:type", :content => "image/png"})
|
71
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:image:width", :content => "400"})
|
72
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:image:height", :content => "300"})
|
73
|
+
|
74
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:video:secure_url", :content => "https://example.com/example.swf"})
|
75
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:video:type", :content => "application/x-shockwave-flash"})
|
76
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:video:width", :content => "400"})
|
77
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:video:height", :content => "300"})
|
78
|
+
|
79
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:audio:secure_url", :content => "https://example.com/example.mp3"})
|
80
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:audio:type", :content => "audio/mpeg"})
|
81
|
+
end
|
82
|
+
|
83
|
+
it "support structured properties like hash" do
|
84
|
+
ogg = Ogg::Generator.new do |o|
|
85
|
+
o.image[:url] = "http://example.com/example.png"
|
86
|
+
o.image[:secure_url] = "https://example.com/example.png"
|
87
|
+
o.image[:type] = "image/png"
|
88
|
+
o.image[:width] = "400"
|
89
|
+
o.image[:height] = "300"
|
90
|
+
|
91
|
+
o.video[:secure_url] = "https://example.com/example.swf"
|
92
|
+
o.video[:type] = "application/x-shockwave-flash"
|
93
|
+
o.video[:width] = "400"
|
94
|
+
o.video[:height] = "300"
|
95
|
+
|
96
|
+
o.audio[:secure_url] = "https://example.com/example.mp3"
|
97
|
+
o.audio[:type] = "audio/mpeg"
|
98
|
+
end
|
99
|
+
actual_html = ogg.html
|
100
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:image", :content => "http://example.com/example.png"})
|
101
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:image:secure_url", :content => "https://example.com/example.png"})
|
102
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:image:type", :content => "image/png"})
|
103
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:image:width", :content => "400"})
|
104
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:image:height", :content => "300"})
|
105
|
+
|
106
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:video:secure_url", :content => "https://example.com/example.swf"})
|
107
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:video:type", :content => "application/x-shockwave-flash"})
|
108
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:video:width", :content => "400"})
|
109
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:video:height", :content => "300"})
|
110
|
+
|
111
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:audio:secure_url", :content => "https://example.com/example.mp3"})
|
112
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:audio:type", :content => "audio/mpeg"})
|
113
|
+
end
|
114
|
+
|
115
|
+
it "prioritizes parent property if duplicates parent property and alternative property" do
|
116
|
+
ogg = Ogg::Generator.new do |o|
|
117
|
+
o.image = "http://example.com/example.jpg"
|
118
|
+
o.image.url = "http://example.com/example.png"
|
119
|
+
end
|
120
|
+
expect(ogg.html).to have_tag("meta", :with => {:property => "og:image", :content => "http://example.com/example.jpg"})
|
121
|
+
end
|
122
|
+
|
123
|
+
it "returns empty string if property is not set" do
|
124
|
+
ogg = Ogg::Generator.new
|
125
|
+
actual_html = ogg.html
|
126
|
+
expect(actual_html).to eq("")
|
127
|
+
end
|
128
|
+
|
129
|
+
it "occurs InvalidBasicProperty if :raise is set and basic properties are inadequacy" do
|
130
|
+
ogg = Ogg::Generator.new(:raise => true)
|
131
|
+
expect{ ogg.html }.to raise_error(Ogg::Generator::InvalidBasicProperty)
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "#basic_properties" do
|
135
|
+
it "occurs InvalidBasicProperty if :raise is set and basic properties are inadequacy" do
|
136
|
+
ogg = Ogg::Generator.new(:raise => true) do |o|
|
137
|
+
o.image = "http://example.com/example.jpg"
|
138
|
+
end
|
139
|
+
expect{ ogg.basic_properties }.to raise_error(Ogg::Generator::InvalidBasicProperty)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "support only basic properties" do
|
143
|
+
ogg = Ogg::Generator.new do |o|
|
144
|
+
o.title = "Site Title"
|
145
|
+
o.type = "Article"
|
146
|
+
o.image = "http://example.com/example.png"
|
147
|
+
o.url = "http://example.com/"
|
148
|
+
o.description = "Description"
|
149
|
+
end
|
150
|
+
actual_html = ogg.basic_properties
|
151
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:title", :content => "Site Title"})
|
152
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:type", :content => "Article"})
|
153
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:image", :content => "http://example.com/example.png"})
|
154
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:url", :content => "http://example.com/"})
|
155
|
+
expect(actual_html).to have_tag("meta", :without => {:property => "og:description"})
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "#optional_properties" do
|
160
|
+
it "support only optional properties" do
|
161
|
+
ogg = Ogg::Generator.new do |o|
|
162
|
+
o.audio = "Audio"
|
163
|
+
o.description = "Description"
|
164
|
+
o.determiner = "Determiner"
|
165
|
+
o.locale = "en_US"
|
166
|
+
o.site_name = "Example Site"
|
167
|
+
o.video = "Video"
|
168
|
+
o.title = "Site Title"
|
169
|
+
end
|
170
|
+
actual_html = ogg.optional_properties
|
171
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:audio", :content => "Audio"})
|
172
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:description", :content => "Description"})
|
173
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:determiner", :content => "Determiner"})
|
174
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:locale", :content => "en_US"})
|
175
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:site_name", :content => "Example Site"})
|
176
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:video", :content => "Video"})
|
177
|
+
expect(actual_html).to have_tag("meta", :without => {:property => "og:title"})
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__))
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
module Ogg
|
5
|
+
describe Helpers do
|
6
|
+
include Ogg::Helpers
|
7
|
+
|
8
|
+
it "og_tag" do
|
9
|
+
actual_html = og_tag do |ogg|
|
10
|
+
ogg.title = "Site Title"
|
11
|
+
ogg.type = "Article"
|
12
|
+
ogg.image = "http://example.com/example.png"
|
13
|
+
ogg.url = "http://example.com/"
|
14
|
+
end
|
15
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:title", :content => "Site Title"})
|
16
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:type", :content => "Article"})
|
17
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:image", :content => "http://example.com/example.png"})
|
18
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:url", :content => "http://example.com/"})
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/ogg_spec.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__))
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
module Ogg
|
5
|
+
describe do
|
6
|
+
it "new method" do
|
7
|
+
ogg = Ogg.new
|
8
|
+
ogg.title = "Site Title"
|
9
|
+
ogg.type = "Article"
|
10
|
+
ogg.image = "http://example.com/example.png"
|
11
|
+
ogg.url = "http://example.com/"
|
12
|
+
actual_html = ogg.html
|
13
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:title", :content => "Site Title"})
|
14
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:type", :content => "Article"})
|
15
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:image", :content => "http://example.com/example.png"})
|
16
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:url", :content => "http://example.com/"})
|
17
|
+
end
|
18
|
+
|
19
|
+
it "new method with block" do
|
20
|
+
ogg = Ogg.new do |o|
|
21
|
+
o.title = "Site Title"
|
22
|
+
o.type = "Article"
|
23
|
+
o.image = "http://example.com/example.png"
|
24
|
+
o.url = "http://example.com/"
|
25
|
+
end
|
26
|
+
actual_html = ogg.html
|
27
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:title", :content => "Site Title"})
|
28
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:type", :content => "Article"})
|
29
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:image", :content => "http://example.com/example.png"})
|
30
|
+
expect(actual_html).to have_tag("meta", :with => {:property => "og:url", :content => "http://example.com/"})
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ogg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- namusyaka
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-html-matchers
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Ogg is an Open Graph Generator.
|
56
|
+
email: namusyaka@gmail.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- .travis.yml
|
62
|
+
- Gemfile
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- lib/ogg.rb
|
66
|
+
- lib/ogg/generator.rb
|
67
|
+
- lib/ogg/helpers.rb
|
68
|
+
- lib/ogg/version.rb
|
69
|
+
- ogg.gemspec
|
70
|
+
- spec/generator_spec.rb
|
71
|
+
- spec/helpers_spec.rb
|
72
|
+
- spec/ogg_spec.rb
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
homepage: https://github.com/namusyaka/ogg
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.0.2
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Ogg is an Open Graph Generator.
|
98
|
+
test_files:
|
99
|
+
- spec/generator_spec.rb
|
100
|
+
- spec/helpers_spec.rb
|
101
|
+
- spec/ogg_spec.rb
|
102
|
+
has_rdoc:
|