schema_dot_org 0.2.0 → 0.3.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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +33 -11
- data/lib/schema_dot_org/organization.rb +23 -0
- data/lib/schema_dot_org/place.rb +0 -1
- data/lib/schema_dot_org/version.rb +1 -1
- data/lib/schema_dot_org.rb +9 -4
- data/test-script.rb +15 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bd245f102143fc57e4bf985a21e2ae949b84fb167cd8c4f7493a1b7a51a60a9
|
4
|
+
data.tar.gz: 56f992158f40aa238b21db445f271c2003d2951487dcbf7ae877b7d960bbe234
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bdf3de02430450ea2d6485f70db9d596f7d106bd8a026976381a5807f61209f947e0c5d451acde42fd0bcbbb2852fbad676b8aa7f2a0d9c4f5a5671b59bc8619
|
7
|
+
data.tar.gz: f63ed74bab57639271bcf92f73bd391ba7660a3a59a6d0c55332a72ccbb2b79e406c04d4012a7b547ee3e1a3887bfa9424a44f916360d89d47b88a9219193657
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,33 +1,55 @@
|
|
1
|
+
[](https://circleci.com/gh/dogweather/schema-dot-org) [](https://badge.fury.io/rb/schema_dot_org) [](https://codeclimate.com/github/dogweather/schema-dot-org/maintainability)
|
2
|
+
|
1
3
|
# SchemaDotOrg
|
2
4
|
|
5
|
+
Let's create [Structured Data](https://developers.google.com/search/docs/guides/intro-structured-data) that's correct,
|
6
|
+
every single time.
|
7
|
+
|
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 . . .
|
3
9
|
|
4
10
|
## Usage
|
5
11
|
|
6
|
-
Create the tree of objects, and then call `#to_s` in
|
12
|
+
Create the tree of objects, and then call `#to_s` in e.g., a Rails template:
|
7
13
|
|
8
14
|
```ruby
|
9
15
|
require 'schema_dot_org/place'
|
16
|
+
require 'schema_dot_org/organization'
|
10
17
|
include SchemaDotOrg
|
11
18
|
|
12
|
-
|
19
|
+
|
20
|
+
@public_law = Organization.new do |org|
|
21
|
+
org.name = "Public.Law"
|
22
|
+
org.email = "say_hi@public.law"
|
23
|
+
org.url = "https://www.public.law"
|
24
|
+
org.founding_location = Place.new do |place|
|
25
|
+
place.address = "Portland, OR"
|
26
|
+
end
|
27
|
+
end
|
13
28
|
```
|
14
29
|
|
15
30
|
```html
|
16
|
-
<%= @
|
31
|
+
<%= @public_law %>
|
17
32
|
```
|
18
33
|
|
19
|
-
|
34
|
+
The generated webpage will contain correct Schema.org JSON-LD markup:
|
20
35
|
|
21
36
|
```html
|
22
37
|
<script type="application/ld+json">
|
23
38
|
{
|
24
|
-
"@
|
25
|
-
"
|
26
|
-
|
27
|
-
|
39
|
+
"@context": "http://schema.org",
|
40
|
+
"@type": "Organization",
|
41
|
+
"name": "Public.Law",
|
42
|
+
"email": "say_hi@public.law",
|
43
|
+
"url": "https://www.public.law",
|
44
|
+
"foundingLocation": {
|
45
|
+
"@type": "Place",
|
46
|
+
"address": "Portland, OR"
|
47
|
+
}
|
28
48
|
```
|
29
49
|
|
30
|
-
You cannot create invalid markup
|
50
|
+
### You cannot create invalid markup
|
51
|
+
|
52
|
+
E.g., If you use the wrong type or try to set an unknown attribute, SchemaDotOrg will
|
31
53
|
refuse to create the incorrect JSON-LD. Instead, you'll get a message explaining
|
32
54
|
the problem:
|
33
55
|
|
@@ -79,7 +101,7 @@ And it should do it in a **typesafe** way. That is, not merely syntactically cor
|
|
79
101
|
but also _semantically_ correct. It should, e.g., ensure that only allowed
|
80
102
|
attributes are used.
|
81
103
|
|
82
|
-
## Schema Development
|
104
|
+
## Schema Development Roadmap
|
83
105
|
|
84
106
|
| Type | Planned | Completed |
|
85
107
|
| ---- |:-------:|:---------:|
|
@@ -90,7 +112,7 @@ attributes are used.
|
|
90
112
|
| URL | X |
|
91
113
|
|
92
114
|
The plan is to implement a small subset of types and attributes relevant to the Google web crawler.
|
93
|
-
|
115
|
+
Propose new types and attributes by opening an Issue.
|
94
116
|
|
95
117
|
## Installation
|
96
118
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'schema_dot_org'
|
2
|
+
|
3
|
+
|
4
|
+
module SchemaDotOrg
|
5
|
+
class Organization < SchemaType
|
6
|
+
attr_accessor :founding_location, :email, :name, :url
|
7
|
+
|
8
|
+
validates :email, type: String
|
9
|
+
validates :founding_location, type: Place
|
10
|
+
validates :name, type: String
|
11
|
+
validates :url, type: String
|
12
|
+
|
13
|
+
def to_json_struct
|
14
|
+
{
|
15
|
+
"@type" => "Organization",
|
16
|
+
"name" => name,
|
17
|
+
"email" => email,
|
18
|
+
"url" => url,
|
19
|
+
"foundingLocation" => founding_location.to_json_struct
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/schema_dot_org/place.rb
CHANGED
data/lib/schema_dot_org.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'json'
|
1
2
|
require 'validated_object'
|
2
3
|
require 'schema_dot_org/version'
|
3
4
|
|
@@ -6,6 +7,8 @@ module SchemaDotOrg
|
|
6
7
|
# Base class for schema types. Refactors out common code.
|
7
8
|
#
|
8
9
|
class SchemaType < ValidatedObject::Base
|
10
|
+
ROOT_ATTR = {"@context" => "http://schema.org"}
|
11
|
+
|
9
12
|
|
10
13
|
def to_s
|
11
14
|
to_json_ld(pretty: true)
|
@@ -13,15 +16,17 @@ module SchemaDotOrg
|
|
13
16
|
|
14
17
|
|
15
18
|
def to_json_ld(pretty: false)
|
16
|
-
"<script type=\"application/ld+json\">\n" + to_json(pretty: pretty) + "\n</script>"
|
19
|
+
"<script type=\"application/ld+json\">\n" + to_json(pretty: pretty, as_root: true) + "\n</script>"
|
17
20
|
end
|
18
21
|
|
19
22
|
|
20
|
-
def to_json(pretty: false)
|
23
|
+
def to_json(pretty: false, as_root: false)
|
24
|
+
structure = as_root ? ROOT_ATTR.merge(to_json_struct) : to_json_struct
|
25
|
+
|
21
26
|
if pretty
|
22
|
-
JSON.pretty_generate(
|
27
|
+
JSON.pretty_generate(structure)
|
23
28
|
else
|
24
|
-
|
29
|
+
structure.to_json
|
25
30
|
end
|
26
31
|
end
|
27
32
|
|
data/test-script.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'schema_dot_org/place'
|
2
|
+
require 'schema_dot_org/organization'
|
3
|
+
include SchemaDotOrg
|
4
|
+
|
5
|
+
|
6
|
+
public_law = Organization.new do |org|
|
7
|
+
org.name = "Public.Law"
|
8
|
+
org.email = "say_hi@public.law"
|
9
|
+
org.url = "https://www.public.law"
|
10
|
+
org.founding_location = Place.new do |place|
|
11
|
+
place.address = "Portland, OR"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
puts public_law
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_dot_org
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robb Shecter
|
@@ -85,9 +85,11 @@ files:
|
|
85
85
|
- bin/console
|
86
86
|
- bin/setup
|
87
87
|
- lib/schema_dot_org.rb
|
88
|
+
- lib/schema_dot_org/organization.rb
|
88
89
|
- lib/schema_dot_org/place.rb
|
89
90
|
- lib/schema_dot_org/version.rb
|
90
91
|
- schema_dot_org.gemspec
|
92
|
+
- test-script.rb
|
91
93
|
homepage: https://github.com/dogweather/schema-dot-org
|
92
94
|
licenses:
|
93
95
|
- MIT
|