schema_dot_org 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +17 -0
- data/README.md +92 -8
- data/lib/schema_dot_org/place.rb +20 -0
- data/lib/schema_dot_org/version.rb +1 -1
- data/lib/schema_dot_org.rb +26 -2
- data/schema_dot_org.gemspec +2 -0
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c235d549a6a316ac26bf5e055b310c947e18382f89294808f8ebc8e5ce35a4cf
|
4
|
+
data.tar.gz: 2751fa4daf7f808cfb51bf384cf6aed926cf0c6565fb5f7457a36f5fed02335a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1986324b423f381779fbb2d0696853aa875ff86eb9252c7127cab49236f50100c2d60ba94f1730c4cb1e4e6811b5614d3cb991f2f6e2da87cd355981d9b2d89e
|
7
|
+
data.tar.gz: c5484937988f31451abac9e3e7b5b73a3843fad82b0a3240d1ba845e40b1abb7512dffd99964d99cf170e2254f134b51190eab2557827a34fb098661374a6716
|
data/Gemfile.lock
CHANGED
@@ -2,11 +2,23 @@ PATH
|
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
4
|
schema_dot_org (0.1.0)
|
5
|
+
validated_object
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
8
9
|
specs:
|
10
|
+
activemodel (5.1.4)
|
11
|
+
activesupport (= 5.1.4)
|
12
|
+
activesupport (5.1.4)
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
+
i18n (~> 0.7)
|
15
|
+
minitest (~> 5.1)
|
16
|
+
tzinfo (~> 1.1)
|
17
|
+
concurrent-ruby (1.0.5)
|
9
18
|
diff-lcs (1.3)
|
19
|
+
i18n (0.9.4)
|
20
|
+
concurrent-ruby (~> 1.0)
|
21
|
+
minitest (5.11.3)
|
10
22
|
rake (10.5.0)
|
11
23
|
rspec (3.7.0)
|
12
24
|
rspec-core (~> 3.7.0)
|
@@ -21,6 +33,11 @@ GEM
|
|
21
33
|
diff-lcs (>= 1.2.0, < 2.0)
|
22
34
|
rspec-support (~> 3.7.0)
|
23
35
|
rspec-support (3.7.1)
|
36
|
+
thread_safe (0.3.6)
|
37
|
+
tzinfo (1.2.5)
|
38
|
+
thread_safe (~> 0.1)
|
39
|
+
validated_object (1.1.0)
|
40
|
+
activemodel (>= 3.2.21)
|
24
41
|
|
25
42
|
PLATFORMS
|
26
43
|
ruby
|
data/README.md
CHANGED
@@ -1,8 +1,96 @@
|
|
1
1
|
# SchemaDotOrg
|
2
2
|
|
3
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/schema_dot_org`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
3
|
|
5
|
-
|
4
|
+
## Usage
|
5
|
+
|
6
|
+
Create the tree of objects, and then call `#to_s` in (e.g.) a Rails template:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
require 'schema_dot_org/place'
|
10
|
+
include SchemaDotOrg
|
11
|
+
|
12
|
+
@founding_location = Place.new { |p| p.address = "Las Vegas, NV" }
|
13
|
+
```
|
14
|
+
|
15
|
+
```html
|
16
|
+
<%= @founding_location %>
|
17
|
+
```
|
18
|
+
|
19
|
+
This results in the generated webpage containing absolutely correct Schema.org JSON-LD markup:
|
20
|
+
|
21
|
+
```html
|
22
|
+
<script type="application/ld+json">
|
23
|
+
{
|
24
|
+
"@type": "Place",
|
25
|
+
"address": "Las Vegas, NV"
|
26
|
+
}
|
27
|
+
</script>
|
28
|
+
```
|
29
|
+
|
30
|
+
You cannot create invalid markup: E.g., If you use the wrong type or try to set an unknown attribute, SchemaDotOrg will
|
31
|
+
refuse to create the incorrect JSON-LD. Instead, you'll get a message explaining
|
32
|
+
the problem:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
Place.new { |p| p.address = 12345 }
|
36
|
+
# => ArgumentError: Address is class Integer, not String
|
37
|
+
|
38
|
+
Place.new do |p|
|
39
|
+
p.address = '12345 Happy Street'
|
40
|
+
p.author = 'Hemmingway'
|
41
|
+
end
|
42
|
+
# => NoMethodError: undefined method `author='
|
43
|
+
```
|
44
|
+
|
45
|
+
This type safety comes from the [ValidatedObject gem](https://github.com/dogweather/validated_object).
|
46
|
+
|
47
|
+
## The Goal: Rich enough vocabulary for Google Schema.org parsing
|
48
|
+
|
49
|
+
The end result is to output website metadata like this (taken from my site [public.law](https://www.public.law)):
|
50
|
+
|
51
|
+
```html
|
52
|
+
<script type="application/ld+json">
|
53
|
+
{
|
54
|
+
"@context": "http://schema.org",
|
55
|
+
"@type": "Organization",
|
56
|
+
"email": "sayhi@public.law",
|
57
|
+
"founder": {
|
58
|
+
"@type": "Person",
|
59
|
+
"name": "Robb Shecter"
|
60
|
+
},
|
61
|
+
"foundingDate": "2009-03-06",
|
62
|
+
"foundingLocation": {
|
63
|
+
"@type": "Place",
|
64
|
+
"address": "Portland, Oregon"
|
65
|
+
},
|
66
|
+
"logo": "https://www.public.law/favicon-196x196.png",
|
67
|
+
"name": "Public.Law",
|
68
|
+
"sameAs": [
|
69
|
+
"https://twitter.com/law_is_code",
|
70
|
+
"https://www.facebook.com/PublicDotLaw",
|
71
|
+
"https://www.linkedin.com/company/9170633/"
|
72
|
+
],
|
73
|
+
"url": "https://www.public.law"
|
74
|
+
}
|
75
|
+
</script>
|
76
|
+
```
|
77
|
+
|
78
|
+
And it should do it in a **typesafe** way. That is, not merely syntactically correct,
|
79
|
+
but also _semantically_ correct. It should, e.g., ensure that only allowed
|
80
|
+
attributes are used.
|
81
|
+
|
82
|
+
## Schema Development Status
|
83
|
+
|
84
|
+
| Type | Planned | Completed |
|
85
|
+
| ---- |:-------:|:---------:|
|
86
|
+
| Place | X | X |
|
87
|
+
| Person | X |
|
88
|
+
| Organization | X |
|
89
|
+
| Date | X |
|
90
|
+
| URL | X |
|
91
|
+
|
92
|
+
The plan is to implement a small subset of types and attributes relevant to the Google web crawler.
|
93
|
+
Add an Issue to propose a new relevant type.
|
6
94
|
|
7
95
|
## Installation
|
8
96
|
|
@@ -20,19 +108,15 @@ Or install it yourself as:
|
|
20
108
|
|
21
109
|
$ gem install schema_dot_org
|
22
110
|
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
26
|
-
|
27
111
|
## Development
|
28
112
|
|
29
113
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
114
|
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
115
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
32
116
|
|
33
117
|
## Contributing
|
34
118
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
119
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dogweather/schema_dot_org.
|
36
120
|
|
37
121
|
## License
|
38
122
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'schema_dot_org'
|
3
|
+
|
4
|
+
|
5
|
+
module SchemaDotOrg
|
6
|
+
# Model the Schema.org `Thing > Place`. See http://schema.org/Place
|
7
|
+
class Place < SchemaType
|
8
|
+
attr_accessor :address
|
9
|
+
|
10
|
+
validates :address, presence: true
|
11
|
+
validates :address, type: String
|
12
|
+
|
13
|
+
def to_json_struct
|
14
|
+
{
|
15
|
+
"@type" => "Place",
|
16
|
+
address: self.address
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/schema_dot_org.rb
CHANGED
@@ -1,5 +1,29 @@
|
|
1
|
-
require
|
1
|
+
require 'validated_object'
|
2
|
+
require 'schema_dot_org/version'
|
2
3
|
|
3
4
|
module SchemaDotOrg
|
4
|
-
#
|
5
|
+
#
|
6
|
+
# Base class for schema types. Refactors out common code.
|
7
|
+
#
|
8
|
+
class SchemaType < ValidatedObject::Base
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
to_json_ld(pretty: true)
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def to_json_ld(pretty: false)
|
16
|
+
"<script type=\"application/ld+json\">\n" + to_json(pretty: pretty) + "\n</script>"
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def to_json(pretty: false)
|
21
|
+
if pretty
|
22
|
+
JSON.pretty_generate(to_json_struct)
|
23
|
+
else
|
24
|
+
to_json_struct.to_json
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
5
29
|
end
|
data/schema_dot_org.gemspec
CHANGED
@@ -21,6 +21,8 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
+
spec.add_dependency "validated_object"
|
25
|
+
|
24
26
|
spec.add_development_dependency "bundler", "~> 1.16"
|
25
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|
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.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robb Shecter
|
@@ -10,6 +10,20 @@ bindir: exe
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2018-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: validated_object
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -71,6 +85,7 @@ files:
|
|
71
85
|
- bin/console
|
72
86
|
- bin/setup
|
73
87
|
- lib/schema_dot_org.rb
|
88
|
+
- lib/schema_dot_org/place.rb
|
74
89
|
- lib/schema_dot_org/version.rb
|
75
90
|
- schema_dot_org.gemspec
|
76
91
|
homepage: https://github.com/dogweather/schema-dot-org
|