schema_dot_org 1.3.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +2 -1
- data/Gemfile.lock +8 -8
- data/README.md +61 -9
- data/lib/schema_dot_org.rb +9 -7
- data/lib/schema_dot_org/organization.rb +18 -5
- data/lib/schema_dot_org/person.rb +4 -3
- data/lib/schema_dot_org/place.rb +4 -2
- data/lib/schema_dot_org/search_action.rb +20 -0
- data/lib/schema_dot_org/web_site.rb +10 -9
- data/schema_dot_org.gemspec +2 -3
- metadata +5 -5
- data/lib/schema_dot_org/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce2b289fea268f2a78df900f63d7d36736bcd0b08446eb7c18a21997cfb6ec8c
|
4
|
+
data.tar.gz: e0a512dcf0d386376a5d227312e8fea47f95a014ed34b2b4ac9be8777f5ef1fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05ca9ceb7a3c95478f86c31d11df20f6661f6caee962170615ac35c178e4e2747f031a2675e97ea31881c50931775304caf9e684335633e8fcb5fdb527935243
|
7
|
+
data.tar.gz: 31b3407922f8757746424c39d9571050dc063d24610a98762ee67d424af498314b97dbaf13a5c2f57ea9a23411c8f2509587bbf596fb6d956abce5c31e28b942
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.5.
|
1
|
+
2.5.1
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
schema_dot_org (1.
|
5
|
-
validated_object (~> 2.0.
|
4
|
+
schema_dot_org (1.5.0)
|
5
|
+
validated_object (~> 2.0.2)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (5.1.
|
11
|
-
activesupport (= 5.1.
|
12
|
-
activesupport (5.1.
|
10
|
+
activemodel (5.1.6)
|
11
|
+
activesupport (= 5.1.6)
|
12
|
+
activesupport (5.1.6)
|
13
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
-
i18n (
|
14
|
+
i18n (>= 0.7, < 2)
|
15
15
|
minitest (~> 5.1)
|
16
16
|
tzinfo (~> 1.1)
|
17
17
|
concurrent-ruby (1.0.5)
|
18
18
|
diff-lcs (1.3)
|
19
|
-
i18n (0.
|
19
|
+
i18n (1.0.0)
|
20
20
|
concurrent-ruby (~> 1.0)
|
21
21
|
minitest (5.11.3)
|
22
22
|
rake (10.5.0)
|
@@ -36,7 +36,7 @@ GEM
|
|
36
36
|
thread_safe (0.3.6)
|
37
37
|
tzinfo (1.2.5)
|
38
38
|
thread_safe (~> 0.1)
|
39
|
-
validated_object (2.0.
|
39
|
+
validated_object (2.0.2)
|
40
40
|
activemodel (>= 3.2.21)
|
41
41
|
|
42
42
|
PLATFORMS
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
[![
|
1
|
+
[![Build Status](https://travis-ci.org/dogweather/schema-dot-org.svg?branch=master)](https://travis-ci.org/dogweather/schema-dot-org) [![Gem Version](https://badge.fury.io/rb/schema_dot_org.svg)](https://badge.fury.io/rb/schema_dot_org) [![Maintainability](https://api.codeclimate.com/v1/badges/e0c60b4cbc998563a484/maintainability)](https://codeclimate.com/github/dogweather/schema-dot-org/maintainability)
|
2
2
|
|
3
3
|
# SchemaDotOrg
|
4
4
|
|
5
5
|
Let's create [Structured Data](https://developers.google.com/search/docs/guides/intro-structured-data) that's correct,
|
6
|
-
every single time.
|
6
|
+
every single time. Good structured data [helps enhance a website's search result appearance](https://developers.google.com/search/docs/guides/enhance-site).
|
7
7
|
|
8
8
|
> Google Search works hard to understand the content of a page. You can help us by providing explicit clues about the meaning of a page . . .
|
9
9
|
|
@@ -19,7 +19,11 @@ Let's say you have a Rails app. If you put this in a controller:
|
|
19
19
|
founding_location: Place.new(address: 'Portland, OR'),
|
20
20
|
email: 'say_hi@public.law',
|
21
21
|
url: 'https://www.public.law',
|
22
|
-
logo: 'https://www.public.law/favicon-196x196.png'
|
22
|
+
logo: 'https://www.public.law/favicon-196x196.png',
|
23
|
+
same_as: [
|
24
|
+
'https://twitter.com/law_is_code',
|
25
|
+
'https://www.facebook.com/PublicDotLaw'
|
26
|
+
]
|
23
27
|
)
|
24
28
|
```
|
25
29
|
|
@@ -48,7 +52,11 @@ Let's say you have a Rails app. If you put this in a controller:
|
|
48
52
|
"foundingLocation": {
|
49
53
|
"@type": "Place",
|
50
54
|
"address": "Portland, OR"
|
51
|
-
}
|
55
|
+
},
|
56
|
+
"sameAs": [
|
57
|
+
"https://twitter.com/law_is_code",
|
58
|
+
"https://www.facebook.com/PublicDotLaw"
|
59
|
+
],
|
52
60
|
</script>
|
53
61
|
```
|
54
62
|
|
@@ -71,16 +79,60 @@ Place.new(
|
|
71
79
|
address: '12345 Happy Street',
|
72
80
|
author: 'Hemmingway'
|
73
81
|
)
|
74
|
-
# => NoMethodError: undefined method `author
|
82
|
+
# => NoMethodError: undefined method `author'
|
75
83
|
```
|
76
84
|
|
77
85
|
This type safety comes from the [ValidatedObject gem](https://github.com/dogweather/validated_object).
|
78
86
|
|
79
|
-
##
|
87
|
+
## Supported Schema.org Types
|
88
|
+
|
89
|
+
### WebSite
|
90
|
+
|
91
|
+
Example with only the required attributes:
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
WebSite.new(
|
95
|
+
name: 'Texas Public Law',
|
96
|
+
url: 'https://texas.public.law',
|
97
|
+
)
|
98
|
+
```
|
99
|
+
|
100
|
+
With the optional `SearchAction` to enable a [Sitelinks Searchbox](https://developers.google.com/search/docs/data-types/sitelinks-searchbox):
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
WebSite.new(
|
104
|
+
name: 'Texas Public Law',
|
105
|
+
url: 'https://texas.public.law',
|
106
|
+
potential_action: SearchAction.new(
|
107
|
+
target: 'https://texas.public.law/?search={search_term_string}',
|
108
|
+
query_input: 'required name=search_term_string'
|
109
|
+
)
|
110
|
+
)
|
111
|
+
```
|
112
|
+
|
113
|
+
### Organization
|
114
|
+
|
115
|
+
Example:
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
Organization.new(
|
119
|
+
name: 'Public.Law',
|
120
|
+
founder: Person.new(name: 'Robb Shecter'),
|
121
|
+
founding_date: Date.new(2009, 3, 6),
|
122
|
+
founding_location: Place.new(address: 'Portland, OR'),
|
123
|
+
email: 'say_hi@public.law',
|
124
|
+
url: 'https://www.public.law',
|
125
|
+
logo: 'https://www.public.law/favicon-196x196.png',
|
126
|
+
same_as: [
|
127
|
+
'https://twitter.com/law_is_code',
|
128
|
+
'https://www.facebook.com/PublicDotLaw'
|
129
|
+
]
|
130
|
+
)
|
131
|
+
```
|
132
|
+
|
133
|
+
### Person, Place, and SearchAction
|
80
134
|
|
81
|
-
|
82
|
-
See `test-script.rb` for the supported types. Currently, all the attributes are required.
|
83
|
-
Propose new types and attributes by opening an Issue.
|
135
|
+
These three aren't too useful on their own in web apps. They're used when creating a `WebSite` and `Organization`, as shown above.
|
84
136
|
|
85
137
|
## Installation
|
86
138
|
|
data/lib/schema_dot_org.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'json'
|
2
4
|
require 'validated_object'
|
3
|
-
require 'schema_dot_org/version'
|
4
5
|
|
5
6
|
module SchemaDotOrg
|
6
7
|
#
|
7
8
|
# Base class for schema types. Refactors out common code.
|
8
9
|
#
|
9
10
|
class SchemaType < ValidatedObject::Base
|
10
|
-
ROOT_ATTR = {"@context" => "http://schema.org"}
|
11
|
+
ROOT_ATTR = { "@context" => "http://schema.org" }.freeze
|
12
|
+
UNQUALIFIED_CLASS_NAME_REGEX = /([^:]+)$/
|
13
|
+
|
11
14
|
|
12
|
-
|
13
15
|
def to_s
|
14
16
|
json_string = to_json_ld(pretty: true)
|
15
17
|
|
@@ -26,7 +28,7 @@ module SchemaDotOrg
|
|
26
28
|
"<script type=\"application/ld+json\">\n" + to_json(pretty: pretty, as_root: true) + "\n</script>"
|
27
29
|
end
|
28
30
|
|
29
|
-
|
31
|
+
|
30
32
|
def to_json(pretty: false, as_root: false)
|
31
33
|
structure = as_root ? ROOT_ATTR.merge(to_json_struct) : to_json_struct
|
32
34
|
|
@@ -41,7 +43,7 @@ module SchemaDotOrg
|
|
41
43
|
# Use the class name to create the "@type" attribute.
|
42
44
|
# @return a hash structure representing json.
|
43
45
|
def to_json_struct
|
44
|
-
{ "@type" => un_namespaced_classname }.merge(
|
46
|
+
{ "@type" => un_namespaced_classname }.merge(_to_json_struct.compact)
|
45
47
|
end
|
46
48
|
|
47
49
|
|
@@ -52,8 +54,8 @@ module SchemaDotOrg
|
|
52
54
|
|
53
55
|
# @return the classname without the module namespace.
|
54
56
|
def un_namespaced_classname
|
55
|
-
self.class.name =~
|
56
|
-
|
57
|
+
self.class.name =~ UNQUALIFIED_CLASS_NAME_REGEX
|
58
|
+
Regexp.last_match(1)
|
57
59
|
end
|
58
60
|
end
|
59
61
|
end
|
@@ -1,18 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'date'
|
2
4
|
require 'schema_dot_org'
|
5
|
+
require 'schema_dot_org/person'
|
6
|
+
require 'schema_dot_org/place'
|
3
7
|
|
4
8
|
|
5
9
|
module SchemaDotOrg
|
6
10
|
class Organization < SchemaType
|
7
|
-
attr_accessor :email,
|
11
|
+
attr_accessor :email,
|
12
|
+
:founder,
|
13
|
+
:founding_date,
|
14
|
+
:founding_location,
|
15
|
+
:logo,
|
16
|
+
:name,
|
17
|
+
:url,
|
18
|
+
:same_as
|
8
19
|
|
9
20
|
validates :email, type: String
|
10
|
-
validates :founder, type: Person
|
21
|
+
validates :founder, type: SchemaDotOrg::Person
|
11
22
|
validates :founding_date, type: Date
|
12
|
-
validates :founding_location, type: Place
|
23
|
+
validates :founding_location, type: SchemaDotOrg::Place
|
13
24
|
validates :logo, type: String
|
14
25
|
validates :name, type: String
|
15
26
|
validates :url, type: String
|
27
|
+
validates :same_as, type: Array, allow_nil: true
|
16
28
|
|
17
29
|
def _to_json_struct
|
18
30
|
{
|
@@ -22,8 +34,9 @@ module SchemaDotOrg
|
|
22
34
|
"logo" => logo,
|
23
35
|
"founder" => founder.to_json_struct,
|
24
36
|
"foundingDate" => founding_date.to_s,
|
25
|
-
"foundingLocation" => founding_location.to_json_struct
|
37
|
+
"foundingLocation" => founding_location.to_json_struct,
|
38
|
+
"sameAs" => same_as
|
26
39
|
}
|
27
40
|
end
|
28
41
|
end
|
29
|
-
end
|
42
|
+
end
|
@@ -1,18 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'schema_dot_org'
|
2
4
|
|
3
5
|
|
4
6
|
module SchemaDotOrg
|
5
7
|
# Model the Schema.org `Person`. See http://schema.org/Person
|
6
8
|
class Person < SchemaType
|
7
|
-
|
8
9
|
attr_accessor :name
|
9
10
|
validates :name, type: String, presence: true
|
10
11
|
|
11
12
|
|
12
13
|
def _to_json_struct
|
13
14
|
{
|
14
|
-
name
|
15
|
+
'name' => self.name
|
15
16
|
}
|
16
17
|
end
|
17
18
|
end
|
18
|
-
end
|
19
|
+
end
|
data/lib/schema_dot_org/place.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'schema_dot_org'
|
4
|
+
|
5
|
+
|
6
|
+
module SchemaDotOrg
|
7
|
+
# Model the Schema.org `Thing > SearchAction`. See http://schema.org/SearchAction
|
8
|
+
class SearchAction < SchemaType
|
9
|
+
attr_accessor :target, :query_input
|
10
|
+
validates :target, type: String, presence: true
|
11
|
+
validates :query_input, type: String, presence: true
|
12
|
+
|
13
|
+
def _to_json_struct
|
14
|
+
{
|
15
|
+
'target' => self.target,
|
16
|
+
'query_input' => self.query_input
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,22 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'schema_dot_org'
|
2
4
|
|
3
5
|
|
4
6
|
module SchemaDotOrg
|
5
|
-
# Model the Schema.org `Thing > CreativeWork > WebSite`.
|
7
|
+
# Model the Schema.org `Thing > CreativeWork > WebSite`.
|
6
8
|
# @See http://schema.org/WebSite
|
7
9
|
class WebSite < SchemaType
|
8
|
-
attr_accessor :name
|
9
|
-
validates :name,
|
10
|
-
|
11
|
-
|
12
|
-
validates :url, type: String, presence: true
|
10
|
+
attr_accessor :name, :url, :potential_action
|
11
|
+
validates :name, type: String, presence: true
|
12
|
+
validates :url, type: String, presence: true
|
13
|
+
validates :potential_action, type: SearchAction, allow_nil: true
|
13
14
|
|
14
15
|
def _to_json_struct
|
15
16
|
{
|
16
|
-
name
|
17
|
-
url
|
17
|
+
'name' => self.name,
|
18
|
+
'url' => self.url,
|
19
|
+
'potentialAction' => self.potential_action&.to_json_struct
|
18
20
|
}
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
22
|
-
|
data/schema_dot_org.gemspec
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
|
2
2
|
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "schema_dot_org/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
6
|
spec.name = "schema_dot_org"
|
8
|
-
spec.version =
|
7
|
+
spec.version = '1.5.0'
|
9
8
|
spec.authors = ["Robb Shecter"]
|
10
9
|
spec.email = ["robb@public.law"]
|
11
10
|
|
@@ -21,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
21
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
21
|
spec.require_paths = ["lib"]
|
23
22
|
|
24
|
-
spec.add_dependency "validated_object", "~> 2.0.
|
23
|
+
spec.add_dependency "validated_object", "~> 2.0.2"
|
25
24
|
|
26
25
|
spec.add_development_dependency "bundler", "~> 1.16"
|
27
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_dot_org
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robb Shecter
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: validated_object
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.0.
|
19
|
+
version: 2.0.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.0.
|
26
|
+
version: 2.0.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,7 +88,7 @@ files:
|
|
88
88
|
- lib/schema_dot_org/organization.rb
|
89
89
|
- lib/schema_dot_org/person.rb
|
90
90
|
- lib/schema_dot_org/place.rb
|
91
|
-
- lib/schema_dot_org/
|
91
|
+
- lib/schema_dot_org/search_action.rb
|
92
92
|
- lib/schema_dot_org/web_site.rb
|
93
93
|
- schema_dot_org.gemspec
|
94
94
|
- test-script.rb
|