schema_dot_org 1.5.0 → 1.7.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/Gemfile +2 -2
- data/Gemfile.lock +35 -26
- data/README.md +11 -9
- data/Rakefile +3 -3
- data/bin/console +3 -3
- data/lib/schema_dot_org.rb +12 -11
- data/lib/schema_dot_org/organization.rb +9 -9
- data/lib/schema_dot_org/person.rb +2 -3
- data/lib/schema_dot_org/place.rb +2 -2
- data/lib/schema_dot_org/search_action.rb +3 -3
- data/lib/schema_dot_org/web_site.rb +6 -5
- data/run-script +2 -0
- data/schema_dot_org.gemspec +22 -15
- data/sorbet/config +2 -0
- data/sorbet/rbi/gems/activemodel.rbi +262 -0
- data/sorbet/rbi/gems/activesupport.rbi +912 -0
- data/sorbet/rbi/gems/concurrent-ruby.rbi +1590 -0
- data/sorbet/rbi/gems/i18n.rbi +133 -0
- data/sorbet/rbi/gems/rake.rbi +644 -0
- data/sorbet/rbi/gems/rspec-core.rbi +1872 -0
- data/sorbet/rbi/gems/rspec-expectations.rbi +1123 -0
- data/sorbet/rbi/gems/rspec-mocks.rbi +1090 -0
- data/sorbet/rbi/gems/rspec-support.rbi +280 -0
- data/sorbet/rbi/gems/rspec.rbi +15 -0
- data/sorbet/rbi/gems/thread_safe.rbi +82 -0
- data/sorbet/rbi/gems/tzinfo.rbi +408 -0
- data/sorbet/rbi/gems/validated_object.rbi +60 -0
- data/sorbet/rbi/sorbet-typed/lib/activemodel/all/activemodel.rbi +597 -0
- data/sorbet/rbi/sorbet-typed/lib/activesupport/>=6/activesupport.rbi +36 -0
- data/sorbet/rbi/sorbet-typed/lib/activesupport/all/activesupport.rbi +1431 -0
- data/sorbet/rbi/sorbet-typed/lib/minitest/all/minitest.rbi +108 -0
- data/test-script.rb +21 -10
- metadata +63 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce7c69a80d31a953b0ee6b786fa61fdf28b639293471e14bf0b75d5b17ab1149
|
4
|
+
data.tar.gz: 502d77fdee47db37eb1de21fd27c432df94b787c21714fdbef0c0cfaab2a47d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df9fef20688ef16fcdcc2131c094d05755b59c913f92a537079a80f8a5d5830b31f49643f6c42304ea9f2dd6dc07f4ad3079f70cd0abff36b531e4a66de76e01
|
7
|
+
data.tar.gz: '03698279a36e56a0c114d8e6fa04b090876d076bce1a1d4e47fcb11ba366803e1fbf065a9879d1413a201096e7dcf71a25485c761cdd402c63333c0e949b5c5f'
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.6.6
|
data/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
3
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in schema_dot_org.gemspec
|
6
6
|
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,52 +1,61 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
schema_dot_org (1.
|
5
|
-
|
4
|
+
schema_dot_org (1.7.0)
|
5
|
+
sorbet-runtime (>= 0.5.5890)
|
6
|
+
validated_object (~> 2.1)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
10
|
-
activemodel (
|
11
|
-
activesupport (=
|
12
|
-
activesupport (
|
11
|
+
activemodel (6.0.3.2)
|
12
|
+
activesupport (= 6.0.3.2)
|
13
|
+
activesupport (6.0.3.2)
|
13
14
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
15
|
i18n (>= 0.7, < 2)
|
15
16
|
minitest (~> 5.1)
|
16
17
|
tzinfo (~> 1.1)
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
19
|
+
concurrent-ruby (1.1.7)
|
20
|
+
diff-lcs (1.4.4)
|
21
|
+
i18n (1.8.5)
|
20
22
|
concurrent-ruby (~> 1.0)
|
21
|
-
minitest (5.
|
22
|
-
rake (
|
23
|
-
rspec (3.
|
24
|
-
rspec-core (~> 3.
|
25
|
-
rspec-expectations (~> 3.
|
26
|
-
rspec-mocks (~> 3.
|
27
|
-
rspec-core (3.
|
28
|
-
rspec-support (~> 3.
|
29
|
-
rspec-expectations (3.
|
23
|
+
minitest (5.14.2)
|
24
|
+
rake (13.0.1)
|
25
|
+
rspec (3.9.0)
|
26
|
+
rspec-core (~> 3.9.0)
|
27
|
+
rspec-expectations (~> 3.9.0)
|
28
|
+
rspec-mocks (~> 3.9.0)
|
29
|
+
rspec-core (3.9.2)
|
30
|
+
rspec-support (~> 3.9.3)
|
31
|
+
rspec-expectations (3.9.2)
|
30
32
|
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
-
rspec-support (~> 3.
|
32
|
-
rspec-mocks (3.
|
33
|
+
rspec-support (~> 3.9.0)
|
34
|
+
rspec-mocks (3.9.1)
|
33
35
|
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
-
rspec-support (~> 3.
|
35
|
-
rspec-support (3.
|
36
|
+
rspec-support (~> 3.9.0)
|
37
|
+
rspec-support (3.9.3)
|
38
|
+
sorbet (0.5.5890)
|
39
|
+
sorbet-static (= 0.5.5890)
|
40
|
+
sorbet-runtime (0.5.5890)
|
41
|
+
sorbet-static (0.5.5890-universal-darwin-14)
|
36
42
|
thread_safe (0.3.6)
|
37
|
-
tzinfo (1.2.
|
43
|
+
tzinfo (1.2.7)
|
38
44
|
thread_safe (~> 0.1)
|
39
|
-
validated_object (2.0
|
45
|
+
validated_object (2.1.0)
|
40
46
|
activemodel (>= 3.2.21)
|
47
|
+
sorbet-runtime (>= 0.5.5890)
|
48
|
+
zeitwerk (2.4.0)
|
41
49
|
|
42
50
|
PLATFORMS
|
43
51
|
ruby
|
44
52
|
|
45
53
|
DEPENDENCIES
|
46
|
-
bundler (~>
|
47
|
-
rake (
|
54
|
+
bundler (~> 2)
|
55
|
+
rake (>= 12.3.3)
|
48
56
|
rspec (~> 3.0)
|
49
57
|
schema_dot_org!
|
58
|
+
sorbet (>= 0.5.5890)
|
50
59
|
|
51
60
|
BUNDLED WITH
|
52
|
-
1.
|
61
|
+
2.1.4
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
[![
|
1
|
+
[![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
|
-
Let's create [Structured Data](https://developers.google.com/search/docs/guides/intro-structured-data)
|
5
|
+
Let's create [Structured Data](https://developers.google.com/search/docs/guides/intro-structured-data) with correct **syntax** and **semantics**,
|
6
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 . . .
|
@@ -33,7 +33,7 @@ Let's say you have a Rails app. If you put this in a controller:
|
|
33
33
|
<%= @public_law %>
|
34
34
|
```
|
35
35
|
|
36
|
-
...you'll get this HTML:
|
36
|
+
...you'll get this in the HTML:
|
37
37
|
|
38
38
|
```html
|
39
39
|
<script type="application/ld+json">
|
@@ -56,18 +56,20 @@ Let's say you have a Rails app. If you put this in a controller:
|
|
56
56
|
"sameAs": [
|
57
57
|
"https://twitter.com/law_is_code",
|
58
58
|
"https://www.facebook.com/PublicDotLaw"
|
59
|
-
]
|
59
|
+
]
|
60
|
+
}
|
60
61
|
</script>
|
61
62
|
```
|
62
63
|
|
63
|
-
Strong typing is at work here. SchemaDotOrg will validate your code, and if correct, will generate Schema.org JSON-LD markup.
|
64
|
+
Strong typing is at work here. `SchemaDotOrg` will validate your code, and if correct, will generate Schema.org JSON-LD markup. If not, you'll get a descriptive error message.
|
65
|
+
|
64
66
|
Notice how the `foundingDate` is in the required ISO-8601 format. [The founding date must be a Ruby
|
65
67
|
Date object](https://github.com/dogweather/schema-dot-org/blob/master/lib/schema_dot_org/organization.rb#L11) and so we can ensure correct formatting. In the same way, the `foundingLocation` is a `Place`
|
66
68
|
which adds the proper `@type` attribute.
|
67
69
|
|
68
|
-
### You
|
70
|
+
### You are prevented from creating invalid markup
|
69
71
|
|
70
|
-
|
72
|
+
If you use the wrong type or try to set an unknown attribute, SchemaDotOrg will
|
71
73
|
refuse to create the incorrect JSON-LD. Instead, you'll get a message explaining
|
72
74
|
the problem:
|
73
75
|
|
@@ -158,8 +160,8 @@ To install this gem onto your local machine, run `bundle exec rake install`.
|
|
158
160
|
|
159
161
|
## Contributing
|
160
162
|
|
161
|
-
Bug reports and pull requests are welcome on GitHub
|
163
|
+
Bug reports and pull requests are welcome on GitHub.
|
162
164
|
|
163
165
|
## License
|
164
166
|
|
165
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
167
|
+
[The](The) gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'schema_dot_org'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "schema_dot_org"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start(__FILE__)
|
data/lib/schema_dot_org.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# typed: ignore
|
1
2
|
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'json'
|
@@ -8,12 +9,11 @@ module SchemaDotOrg
|
|
8
9
|
# Base class for schema types. Refactors out common code.
|
9
10
|
#
|
10
11
|
class SchemaType < ValidatedObject::Base
|
11
|
-
ROOT_ATTR = {
|
12
|
-
UNQUALIFIED_CLASS_NAME_REGEX = /([^:]+)
|
13
|
-
|
12
|
+
ROOT_ATTR = { '@context' => 'http://schema.org' }.freeze
|
13
|
+
UNQUALIFIED_CLASS_NAME_REGEX = /([^:]+)$/.freeze
|
14
14
|
|
15
15
|
def to_s
|
16
|
-
json_string = to_json_ld(pretty:
|
16
|
+
json_string = to_json_ld(pretty: (!rails_production? && !ENV['SCHEMA_DOT_ORG_MINIFIED_JSON']))
|
17
17
|
|
18
18
|
# Mark as safe if we're in Rails
|
19
19
|
if json_string.respond_to?(:html_safe)
|
@@ -23,12 +23,10 @@ module SchemaDotOrg
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
26
|
def to_json_ld(pretty: false)
|
28
27
|
"<script type=\"application/ld+json\">\n" + to_json(pretty: pretty, as_root: true) + "\n</script>"
|
29
28
|
end
|
30
29
|
|
31
|
-
|
32
30
|
def to_json(pretty: false, as_root: false)
|
33
31
|
structure = as_root ? ROOT_ATTR.merge(to_json_struct) : to_json_struct
|
34
32
|
|
@@ -39,23 +37,26 @@ module SchemaDotOrg
|
|
39
37
|
end
|
40
38
|
end
|
41
39
|
|
42
|
-
|
43
40
|
# Use the class name to create the "@type" attribute.
|
44
41
|
# @return a hash structure representing json.
|
45
42
|
def to_json_struct
|
46
|
-
{
|
43
|
+
{ '@type' => un_namespaced_classname }.merge(_to_json_struct.compact)
|
47
44
|
end
|
48
45
|
|
49
|
-
|
50
46
|
def _to_json_struct
|
51
|
-
raise
|
47
|
+
raise 'For subclasses to implement'
|
52
48
|
end
|
53
49
|
|
54
|
-
|
55
50
|
# @return the classname without the module namespace.
|
56
51
|
def un_namespaced_classname
|
57
52
|
self.class.name =~ UNQUALIFIED_CLASS_NAME_REGEX
|
58
53
|
Regexp.last_match(1)
|
59
54
|
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def rails_production?
|
59
|
+
defined?(Rails) && Rails.env.production?
|
60
|
+
end
|
60
61
|
end
|
61
62
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# typed: ignore
|
1
2
|
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'date'
|
@@ -5,7 +6,6 @@ require 'schema_dot_org'
|
|
5
6
|
require 'schema_dot_org/person'
|
6
7
|
require 'schema_dot_org/place'
|
7
8
|
|
8
|
-
|
9
9
|
module SchemaDotOrg
|
10
10
|
class Organization < SchemaType
|
11
11
|
attr_accessor :email,
|
@@ -28,14 +28,14 @@ module SchemaDotOrg
|
|
28
28
|
|
29
29
|
def _to_json_struct
|
30
30
|
{
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
31
|
+
'name' => name,
|
32
|
+
'email' => email,
|
33
|
+
'url' => url,
|
34
|
+
'logo' => logo,
|
35
|
+
'founder' => founder.to_json_struct,
|
36
|
+
'foundingDate' => founding_date.to_s,
|
37
|
+
'foundingLocation' => founding_location.to_json_struct,
|
38
|
+
'sameAs' => same_as
|
39
39
|
}
|
40
40
|
end
|
41
41
|
end
|
@@ -1,18 +1,17 @@
|
|
1
|
+
# typed: ignore
|
1
2
|
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'schema_dot_org'
|
4
5
|
|
5
|
-
|
6
6
|
module SchemaDotOrg
|
7
7
|
# Model the Schema.org `Person`. See http://schema.org/Person
|
8
8
|
class Person < SchemaType
|
9
9
|
attr_accessor :name
|
10
10
|
validates :name, type: String, presence: true
|
11
11
|
|
12
|
-
|
13
12
|
def _to_json_struct
|
14
13
|
{
|
15
|
-
'name' =>
|
14
|
+
'name' => name
|
16
15
|
}
|
17
16
|
end
|
18
17
|
end
|
data/lib/schema_dot_org/place.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
+
# typed: ignore
|
1
2
|
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'schema_dot_org'
|
4
5
|
|
5
|
-
|
6
6
|
module SchemaDotOrg
|
7
7
|
# Model the Schema.org `Thing > Place`. See http://schema.org/Place
|
8
8
|
class Place < SchemaType
|
@@ -11,7 +11,7 @@ module SchemaDotOrg
|
|
11
11
|
|
12
12
|
def _to_json_struct
|
13
13
|
{
|
14
|
-
'address' =>
|
14
|
+
'address' => address
|
15
15
|
}
|
16
16
|
end
|
17
17
|
end
|
@@ -1,8 +1,8 @@
|
|
1
|
+
# typed: ignore
|
1
2
|
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'schema_dot_org'
|
4
5
|
|
5
|
-
|
6
6
|
module SchemaDotOrg
|
7
7
|
# Model the Schema.org `Thing > SearchAction`. See http://schema.org/SearchAction
|
8
8
|
class SearchAction < SchemaType
|
@@ -12,8 +12,8 @@ module SchemaDotOrg
|
|
12
12
|
|
13
13
|
def _to_json_struct
|
14
14
|
{
|
15
|
-
'target' =>
|
16
|
-
'query_input' =>
|
15
|
+
'target' => target,
|
16
|
+
'query_input' => query_input
|
17
17
|
}
|
18
18
|
end
|
19
19
|
end
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# typed: ignore
|
1
2
|
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'schema_dot_org'
|
4
|
-
|
5
|
+
require 'schema_dot_org/search_action'
|
5
6
|
|
6
7
|
module SchemaDotOrg
|
7
8
|
# Model the Schema.org `Thing > CreativeWork > WebSite`.
|
@@ -10,13 +11,13 @@ module SchemaDotOrg
|
|
10
11
|
attr_accessor :name, :url, :potential_action
|
11
12
|
validates :name, type: String, presence: true
|
12
13
|
validates :url, type: String, presence: true
|
13
|
-
validates :potential_action, type: SearchAction, allow_nil: true
|
14
|
+
validates :potential_action, type: SchemaDotOrg::SearchAction, allow_nil: true
|
14
15
|
|
15
16
|
def _to_json_struct
|
16
17
|
{
|
17
|
-
'name' =>
|
18
|
-
'url' =>
|
19
|
-
'potentialAction' =>
|
18
|
+
'name' => name,
|
19
|
+
'url' => url,
|
20
|
+
'potentialAction' => potential_action&.to_json_struct
|
20
21
|
}
|
21
22
|
end
|
22
23
|
end
|
data/run-script
ADDED
data/schema_dot_org.gemspec
CHANGED
@@ -1,28 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
1
4
|
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
3
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
6
|
|
5
7
|
Gem::Specification.new do |spec|
|
6
|
-
spec.
|
7
|
-
spec.
|
8
|
-
spec.
|
9
|
-
spec.
|
8
|
+
spec.required_ruby_version = '>= 2.6'
|
9
|
+
spec.name = 'schema_dot_org'
|
10
|
+
spec.version = '1.7.0'
|
11
|
+
spec.authors = ['Robb Shecter']
|
12
|
+
spec.email = ['robb@public.law']
|
10
13
|
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
13
|
-
|
14
|
-
spec.
|
14
|
+
spec.summary = 'JSON-LD generator for Schema.org vocabulary'
|
15
|
+
spec.description = 'Creates well-formed website metadata with ' \
|
16
|
+
'strongly typed Ruby.'
|
17
|
+
spec.homepage = 'https://github.com/public-law/schema-dot-org'
|
18
|
+
spec.license = 'MIT'
|
15
19
|
|
16
20
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
21
|
f.match(%r{^(test|spec|features)/})
|
18
22
|
end
|
19
|
-
spec.bindir =
|
23
|
+
spec.bindir = 'exe'
|
20
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
-
spec.require_paths = [
|
25
|
+
spec.require_paths = ['lib']
|
26
|
+
|
27
|
+
spec.add_dependency 'validated_object', '~> 2.1'
|
22
28
|
|
23
|
-
spec.
|
29
|
+
spec.add_development_dependency 'bundler', '~> 2'
|
30
|
+
spec.add_development_dependency 'rake', '>= 12.3.3'
|
31
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
32
|
+
spec.add_development_dependency 'sorbet', '>= 0.5.5890'
|
24
33
|
|
25
|
-
spec.
|
26
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
34
|
+
spec.add_runtime_dependency 'sorbet-runtime', '>= 0.5.5890'
|
28
35
|
end
|
data/sorbet/config
ADDED