schema_dot_org 2.2.2 → 2.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 146e2c23c546ada2f45452f78d5e609e0730256b24b72811c834306ef69b5409
4
- data.tar.gz: c1dbd6ee1c3af15b07b3188eea8decf036e3bc52c97379d78bea1f7ca16a25ea
3
+ metadata.gz: 5e190c183425efbb7808c9e18f253cd377b91a4ce927d8f401f02158d6d704cf
4
+ data.tar.gz: 5e01217b962ed0ec450bda73923e2fbdff9ec4baeee2433c96cdc27c53e08bbf
5
5
  SHA512:
6
- metadata.gz: ea5016b6e3075a5aa21d82faf8a7e00b42f920637b6e8dd97c7a54998eae6fcfb8ae4f98a15a6e45cd471b1614598d0f007f54f67545043b63af89ff1ec85fff
7
- data.tar.gz: ae7aaf1fbcea2b10918d224c89c26fa71725cf6dac52d27f5960a7096726ca7d3b9c1866477651084d20e71fe118049de3fa4b646fbc26c0da671db2d064b168
6
+ metadata.gz: 36a893438da0d2731fba7a14a5d2a04b4a406688b5be906c6080ad30b2bb42865553943451fcb25e22a737e2e5478ac95a72f8fadf6447f28791c8e0ff89d2d9
7
+ data.tar.gz: 2b1feab097655a4efd511838774f1f4c5224c0767cf78aa970f7feb7b57bd6e7a74bf7327aee2eecd2578d38aee68eb494c5ea5b6ff6131651c82c429f27cb70
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.2.3)
5
5
  validated_object (~> 2.3)
6
6
 
7
7
  GEM
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
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
@@ -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,6 +115,7 @@ end
115
115
 
116
116
 
117
117
  require 'schema_dot_org/aggregate_offer'
118
+ require 'schema_dot_org/college_or_university'
118
119
  require 'schema_dot_org/contact_point'
119
120
  require 'schema_dot_org/item_list'
120
121
  require 'schema_dot_org/list_item'
@@ -7,7 +7,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
7
7
  Gem::Specification.new do |spec|
8
8
  spec.required_ruby_version = '>= 2.6'
9
9
  spec.name = 'schema_dot_org'
10
- spec.version = '2.2.2'
10
+ spec.version = '2.2.3'
11
11
  spec.authors = ['Robb Shecter']
12
12
  spec.email = ['robb@public.law']
13
13
 
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: 2.2.2
4
+ version: 2.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-12 00:00:00.000000000 Z
11
+ date: 2023-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: validated_object
@@ -87,6 +87,7 @@ files:
87
87
  - bin/tapioca
88
88
  - lib/schema_dot_org.rb
89
89
  - lib/schema_dot_org/aggregate_offer.rb
90
+ - lib/schema_dot_org/college_or_university.rb
90
91
  - lib/schema_dot_org/contact_point.rb
91
92
  - lib/schema_dot_org/item_list.rb
92
93
  - lib/schema_dot_org/list_item.rb