schema_dot_org 2.2.2 → 2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 146e2c23c546ada2f45452f78d5e609e0730256b24b72811c834306ef69b5409
4
- data.tar.gz: c1dbd6ee1c3af15b07b3188eea8decf036e3bc52c97379d78bea1f7ca16a25ea
3
+ metadata.gz: 6b0120204cb5305a8efc64697f917b6e3ada14584f172f61cf16537f71a7a7d9
4
+ data.tar.gz: 496bde815fba8a32a86f9c1c6bf6ff810bd49b8c6f6d05a73682d2fb49ce68c8
5
5
  SHA512:
6
- metadata.gz: ea5016b6e3075a5aa21d82faf8a7e00b42f920637b6e8dd97c7a54998eae6fcfb8ae4f98a15a6e45cd471b1614598d0f007f54f67545043b63af89ff1ec85fff
7
- data.tar.gz: ae7aaf1fbcea2b10918d224c89c26fa71725cf6dac52d27f5960a7096726ca7d3b9c1866477651084d20e71fe118049de3fa4b646fbc26c0da671db2d064b168
6
+ metadata.gz: 914246c1e12f48142d896d357f22607e383402e3ee5dc3bcf4087ecdbe9db93b8dbd37ce95d0b3622719de8990934aec37b4b05dd35deb916d6089b12dda28c4
7
+ data.tar.gz: 4d9a8f13cbbe2a9519f47e2bb2dd09ffb69874dc403512a3f0cf3269efff6c9904fe05a19b571d039fbb6cdbdd12425c3c56c1ed8b1a4a76e430416ffa903e5b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- schema_dot_org (2.2.2)
4
+ schema_dot_org (2.3.0)
5
5
  validated_object (~> 2.3)
6
6
 
7
7
  GEM
@@ -53,7 +53,7 @@ GEM
53
53
  sorbet-runtime (>= 0.5.5890)
54
54
 
55
55
  PLATFORMS
56
- arm64-darwin-22
56
+ arm64-darwin-24
57
57
 
58
58
  DEPENDENCIES
59
59
  bundler (~> 2.4)
data/README.md CHANGED
@@ -2,22 +2,23 @@
2
2
 
3
3
  # SchemaDotOrg
4
4
 
5
- Create [Structured Data](https://developers.google.com/search/docs/guides/intro-structured-data) with correct **syntax** and **semantics**,
6
- every single time. Good structured data [helps enhance a website's search result appearance](https://developers.google.com/search/docs/guides/enhance-site).
5
+ Easily create [Structured Data](https://developers.google.com/search/docs/guides/intro-structured-data) with **correct syntax and semantics**.
6
+ Good structured data [helps enhance a website's search result appearance](https://developers.google.com/search/docs/guides/enhance-site):
7
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 . . .
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
 
10
10
  ## Usage
11
11
 
12
- Let's say you have a Rails app. If you put this in a controller:
12
+ Let's say you have a Rails app. First write plain-ruby code in a controller. Just instantiate
13
+ the structured data object you want in your web page:
13
14
 
14
15
  ```ruby
15
- @public_law = Organization.new(
16
+ @my_org = Organization.new(
16
17
  name: 'Public.Law',
17
18
  founder: Person.new(name: 'Robb Shecter'),
18
19
  founding_date: Date.new(2009, 3, 6),
19
20
  founding_location: Place.new(address: 'Portland, OR'),
20
- email: 'say_hi@public.law',
21
+ email: 'support@public.law',
21
22
  telephone: '+1 123 456 7890',
22
23
  url: 'https://www.public.law',
23
24
  logo: 'https://www.public.law/favicon-196x196.png',
@@ -28,13 +29,13 @@ Let's say you have a Rails app. If you put this in a controller:
28
29
  )
29
30
  ```
30
31
 
31
- ...and this in a template:
32
+ ...and then output it in a template:
32
33
 
33
34
  ```html
34
- <%= @public_law %>
35
+ <%= @my_org %>
35
36
  ```
36
37
 
37
- ...you'll get this in the HTML:
38
+ ...you'll get this perfectly formatted structured data in your HTML:
38
39
 
39
40
  ```html
40
41
  <script type="application/ld+json">
@@ -42,7 +43,7 @@ Let's say you have a Rails app. If you put this in a controller:
42
43
  "@context": "http://schema.org",
43
44
  "@type": "Organization",
44
45
  "name": "Public.Law",
45
- "email": "say_hi@public.law",
46
+ "email": "support@public.law",
46
47
  "telephone": "+1 123 456 7890",
47
48
  "url": "https://www.public.law",
48
49
  "logo": "https://www.public.law/favicon-196x196.png",
@@ -63,14 +64,25 @@ Let's say you have a Rails app. If you put this in a controller:
63
64
  </script>
64
65
  ```
65
66
 
66
- 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.
67
+ ### Principle: No silent failures
68
+
69
+ We coded the library this way because the data is embedded in the HTML - and it's a
70
+ pain in the butt to manually check for errors. In my case, I manage 500,000 unique
71
+ pages in my Rails app. There's _no way_ I could place error-free structured data in
72
+ them without automatic validation.
73
+
74
+ `SchemaDotOrg` will validate your Ruby code, and if it's correct, will generate Schema.org JSON-LD markup when `#to_s`
75
+ is called. If you, e.g., didn't add the correct attributes, you'll get a descriptive error message pointing
76
+ you to the problem.
67
77
 
68
- Notice how the `foundingDate` is in the required ISO-8601 format. [The founding date must be a Ruby
69
- 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`
70
- which adds the proper `@type` attribute.
78
+ Notice how the `foundingDate` is in the required ISO-8601 format. In the same way, the `foundingLocation` is a `Place`
79
+ which adds the proper `@type` attribute. All Ruby snake-case names have been converted to the Schema.org standard camel-case.
80
+ Etc., etc.
71
81
 
72
82
  ### You are prevented from creating invalid markup
73
83
 
84
+ If your page loads, you know your markup is good.
85
+
74
86
  If you use the wrong type or try to set an unknown attribute, SchemaDotOrg will
75
87
  refuse to create the incorrect JSON-LD. Instead, you'll get a message explaining
76
88
  the problem:
@@ -86,15 +98,18 @@ Place.new(
86
98
  # => NoMethodError: undefined method `author'
87
99
  ```
88
100
 
89
- This type safety comes from the [ValidatedObject gem](https://github.com/dogweather/validated_object).
101
+ In my experience, I never get errors from the lib. I code it once, it works, and then
102
+ I move on to other things.
103
+
104
+ > This automatic validation comes from my [ValidatedObject gem](https://github.com/dogweather/validated_object), which in turn,
105
+ > is a thin wrapper around ActiveRecord::Validations. So there's nothing magical going on here.
90
106
 
91
107
  ## Supported Schema.org Types
92
108
 
93
109
  AggregateOffer, ContactPoint, ItemList, ListItem, Offer, Organization, Person, Place,
94
110
  Product, SearchAction, and WebSite.
95
111
 
96
- Here are a few examples. The [source code](https://github.com/dogweather/schema-dot-org/tree/master/lib/schema_dot_org) for these is **extremely easy** to read. Check them out to see
97
- all the available attributes.
112
+ Here are a few examples. [The source code for these is extremely easy to read.](https://github.com/dogweather/schema-dot-org/tree/master/lib/schema_dot_org) Check them out to see all the available attributes.
98
113
 
99
114
  ### WebSite
100
115
 
@@ -140,9 +155,6 @@ Organization.new(
140
155
  )
141
156
  ```
142
157
 
143
- ### Person, Place, and SearchAction
144
-
145
- These three aren't too useful on their own in web apps. They're used when creating a `WebSite` and `Organization`, as shown above.
146
158
 
147
159
  ## Installation
148
160
 
@@ -154,8 +166,8 @@ gem 'schema_dot_org'
154
166
 
155
167
  ## Development
156
168
 
157
- The Schema.org classes are as DRY as I could possibly make them. They're really
158
- easy to create and add to. For example, `Product`:
169
+ The coding is as DRY as I could possibly make it. I think it's really
170
+ easy to create and add to. For example, here's `Product`:
159
171
 
160
172
  ```ruby
161
173
  class Product < SchemaType
@@ -179,4 +191,4 @@ Bug reports and pull requests are welcome on GitHub.
179
191
 
180
192
  ## License
181
193
 
182
- [The](The) gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
194
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #
4
- # Model the Schema.org `Thing > Place`. See https://schema.org/Offer
4
+ # Model the Schema.org `Thing > Intangible > Offer > AggregateOffer`. See https://schema.org/Offer
5
5
  #
6
6
  module SchemaDotOrg
7
7
  class AggregateOffer < SchemaType
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+
4
+ #
5
+ # https://schema.org/CollegeOrUniversity
6
+ #
7
+ module SchemaDotOrg
8
+ class CollegeOrUniversity < SchemaType
9
+ validated_attr :name, type: String, presence: true
10
+ validated_attr :url, type: String, allow_nil: true
11
+ end
12
+ end
@@ -0,0 +1,24 @@
1
+
2
+ # frozen_string_literal: true
3
+
4
+ require 'date'
5
+ require_relative 'person'
6
+
7
+ #
8
+ # Model the Schema.org `Thing > CreativeWork > Comment`.
9
+ # See https://schema.org/Comment
10
+ #
11
+ module SchemaDotOrg
12
+ class Comment < SchemaType
13
+ validated_attr :author, type: Person, presence: true
14
+ validated_attr :datePublished, type: Date, presence: true
15
+
16
+ validated_attr :comment, type: Array, allow_nil: true
17
+ validated_attr :creativeWorkStatus, type: String, allow_nil: true
18
+ validated_attr :image, type: Array, allow_nil: true
19
+ validated_attr :inLanguage, type: Array, allow_nil: true
20
+ validated_attr :interactionStatistic, type: Array, allow_nil: true
21
+ validated_attr :text, type: String, allow_nil: true
22
+ validated_attr :url, type: String, allow_nil: true
23
+ end
24
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+ require_relative 'person'
5
+
6
+ #
7
+ # Model the Schema.org `Thing > CreativeWork > Article > SocialMediaPosting > DiscussionForumPosting`.
8
+ # See https://schema.org/DiscussionForumPosting
9
+ #
10
+ module SchemaDotOrg
11
+ class DiscussionForumPosting < SchemaType
12
+ # TODO: Allow for type Person or Organization
13
+ validated_attr :author, type: Person, presence: true
14
+ # TODO: Allow for type Date or DateTime
15
+ validated_attr :datePublished, type: Date, presence: true
16
+
17
+ validated_attr :comment, type: Array, allow_nil: true
18
+ validated_attr :commentCount, type: Integer, allow_nil: true
19
+ validated_attr :headline, type: String, allow_nil: true
20
+ validated_attr :image, type: Array, allow_nil: true
21
+ validated_attr :inLanguage, type: Array, allow_nil: true
22
+ validated_attr :interactionStatistic, type: Array, allow_nil: true
23
+ validated_attr :mainEntityOfPage, type: String, allow_nil: true
24
+ validated_attr :text, type: String, allow_nil: true
25
+ validated_attr :url, type: String, allow_nil: true
26
+ end
27
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Model the Schema.org `Thing > Intangible > StructuredValue > InteractionCounter`.
5
+ # See https://schema.org/InteractionCounter
6
+ #
7
+ module SchemaDotOrg
8
+ class InteractionCounter < SchemaType
9
+ validated_attr :userInteractionCount, type: Integer, presence: true
10
+ validated_attr :interactionType, type: String, presence: true
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Model the Schema.org `Thing > Intangible > Language`.
5
+ # See https://schema.org/Language
6
+ #
7
+ module SchemaDotOrg
8
+ class Language < SchemaType
9
+ validated_attr :alternateName, type: String, allow_nil: true
10
+ validated_attr :name, type: String, presence: true
11
+ end
12
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
  #
5
- # Model the Schema.org `Thing > Place`. See https://schema.org/Offer
5
+ # Model the Schema.org `Thing > Intangible > Offer`. See https://schema.org/Offer
6
6
  #
7
7
  module SchemaDotOrg
8
8
  class Offer < SchemaType
@@ -5,6 +5,9 @@ require 'date'
5
5
  require_relative 'person'
6
6
  require_relative 'place'
7
7
 
8
+ # Google allows `url` to be a string:
9
+ # https://developers.google.com/search/docs/appearance/structured-data/logo
10
+
8
11
  module SchemaDotOrg
9
12
  class Organization < SchemaType
10
13
  validated_attr :contact_points, type: Array, allow_nil: true
@@ -12,9 +15,11 @@ module SchemaDotOrg
12
15
  validated_attr :founder, type: SchemaDotOrg::Person, allow_nil: true
13
16
  validated_attr :founding_date, type: Date, allow_nil: true
14
17
  validated_attr :founding_location, type: SchemaDotOrg::Place, allow_nil: true
18
+ validated_attr :legal_name, type: String, allow_nil: true
15
19
  validated_attr :logo, type: String
16
20
  validated_attr :name, type: String
17
21
  validated_attr :same_as, type: Array, allow_nil: true
22
+ validated_attr :slogan, type: String, allow_nil: true
18
23
  validated_attr :telephone, type: String, allow_nil: true
19
24
  validated_attr :url, type: String
20
25
  end
@@ -6,8 +6,11 @@
6
6
  #
7
7
  module SchemaDotOrg
8
8
  class Person < SchemaType
9
- validated_attr :name, type: String, presence: true
10
- validated_attr :same_as, type: Array, allow_nil: true
11
- validated_attr :url, type: String, allow_nil: true
9
+ validated_attr :award, type: String, allow_nil: true
10
+ validated_attr :alumni_of, type: SchemaDotOrg::CollegeOrUniversity, allow_nil: true
11
+ validated_attr :honorific_suffix, type: String, allow_nil: true
12
+ validated_attr :name, type: String, presence: true
13
+ validated_attr :same_as, type: Array, allow_nil: true
14
+ validated_attr :url, type: String, allow_nil: true
12
15
  end
13
16
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
  #
5
- # Model the Schema.org `Thing > Place`. See https://schema.org/Product
5
+ # Model the Schema.org `Thing > Product`. See https://schema.org/Product
6
6
  #
7
7
  module SchemaDotOrg
8
8
  class Product < SchemaType
@@ -115,8 +115,13 @@ end
115
115
 
116
116
 
117
117
  require 'schema_dot_org/aggregate_offer'
118
+ require 'schema_dot_org/college_or_university'
119
+ require 'schema_dot_org/comment'
118
120
  require 'schema_dot_org/contact_point'
121
+ require 'schema_dot_org/discussion_forum_posting'
122
+ require 'schema_dot_org/interaction_counter'
119
123
  require 'schema_dot_org/item_list'
124
+ require 'schema_dot_org/language'
120
125
  require 'schema_dot_org/list_item'
121
126
  require 'schema_dot_org/organization'
122
127
  require 'schema_dot_org/person'
@@ -5,9 +5,9 @@ lib = File.expand_path('lib', __dir__)
5
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
6
 
7
7
  Gem::Specification.new do |spec|
8
- spec.required_ruby_version = '>= 2.6'
8
+ spec.required_ruby_version = '>= 3.0'
9
9
  spec.name = 'schema_dot_org'
10
- spec.version = '2.2.2'
10
+ spec.version = '2.3.0'
11
11
  spec.authors = ['Robb Shecter']
12
12
  spec.email = ['robb@public.law']
13
13
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema_dot_org
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2023-10-12 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: validated_object
@@ -75,7 +74,6 @@ extra_rdoc_files: []
75
74
  files:
76
75
  - ".gitignore"
77
76
  - ".rspec"
78
- - ".ruby-version"
79
77
  - ".travis.yml"
80
78
  - Gemfile
81
79
  - Gemfile.lock
@@ -87,8 +85,13 @@ files:
87
85
  - bin/tapioca
88
86
  - lib/schema_dot_org.rb
89
87
  - lib/schema_dot_org/aggregate_offer.rb
88
+ - lib/schema_dot_org/college_or_university.rb
89
+ - lib/schema_dot_org/comment.rb
90
90
  - lib/schema_dot_org/contact_point.rb
91
+ - lib/schema_dot_org/discussion_forum_posting.rb
92
+ - lib/schema_dot_org/interaction_counter.rb
91
93
  - lib/schema_dot_org/item_list.rb
94
+ - lib/schema_dot_org/language.rb
92
95
  - lib/schema_dot_org/list_item.rb
93
96
  - lib/schema_dot_org/offer.rb
94
97
  - lib/schema_dot_org/organization.rb
@@ -103,7 +106,6 @@ homepage: https://github.com/public-law/schema-dot-org
103
106
  licenses:
104
107
  - MIT
105
108
  metadata: {}
106
- post_install_message:
107
109
  rdoc_options: []
108
110
  require_paths:
109
111
  - lib
@@ -111,15 +113,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
113
  requirements:
112
114
  - - ">="
113
115
  - !ruby/object:Gem::Version
114
- version: '2.6'
116
+ version: '3.0'
115
117
  required_rubygems_version: !ruby/object:Gem::Requirement
116
118
  requirements:
117
119
  - - ">="
118
120
  - !ruby/object:Gem::Version
119
121
  version: '0'
120
122
  requirements: []
121
- rubygems_version: 3.4.20
122
- signing_key:
123
+ rubygems_version: 3.6.9
123
124
  specification_version: 4
124
125
  summary: JSON-LD generator for Schema.org vocabulary
125
126
  test_files: []
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.6.6