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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce2b289fea268f2a78df900f63d7d36736bcd0b08446eb7c18a21997cfb6ec8c
4
- data.tar.gz: e0a512dcf0d386376a5d227312e8fea47f95a014ed34b2b4ac9be8777f5ef1fe
3
+ metadata.gz: ce7c69a80d31a953b0ee6b786fa61fdf28b639293471e14bf0b75d5b17ab1149
4
+ data.tar.gz: 502d77fdee47db37eb1de21fd27c432df94b787c21714fdbef0c0cfaab2a47d5
5
5
  SHA512:
6
- metadata.gz: 05ca9ceb7a3c95478f86c31d11df20f6661f6caee962170615ac35c178e4e2747f031a2675e97ea31881c50931775304caf9e684335633e8fcb5fdb527935243
7
- data.tar.gz: 31b3407922f8757746424c39d9571050dc063d24610a98762ee67d424af498314b97dbaf13a5c2f57ea9a23411c8f2509587bbf596fb6d956abce5c31e28b942
6
+ metadata.gz: df9fef20688ef16fcdcc2131c094d05755b59c913f92a537079a80f8a5d5830b31f49643f6c42304ea9f2dd6dc07f4ad3079f70cd0abff36b531e4a66de76e01
7
+ data.tar.gz: '03698279a36e56a0c114d8e6fa04b090876d076bce1a1d4e47fcb11ba366803e1fbf065a9879d1413a201096e7dcf71a25485c761cdd402c63333c0e949b5c5f'
@@ -1 +1 @@
1
- 2.5.1
1
+ 2.6.6
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source "https://rubygems.org"
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
@@ -1,52 +1,61 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- schema_dot_org (1.5.0)
5
- validated_object (~> 2.0.2)
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 (5.1.6)
11
- activesupport (= 5.1.6)
12
- activesupport (5.1.6)
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
- concurrent-ruby (1.0.5)
18
- diff-lcs (1.3)
19
- i18n (1.0.0)
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.11.3)
22
- rake (10.5.0)
23
- rspec (3.7.0)
24
- rspec-core (~> 3.7.0)
25
- rspec-expectations (~> 3.7.0)
26
- rspec-mocks (~> 3.7.0)
27
- rspec-core (3.7.1)
28
- rspec-support (~> 3.7.0)
29
- rspec-expectations (3.7.0)
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.7.0)
32
- rspec-mocks (3.7.0)
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.7.0)
35
- rspec-support (3.7.1)
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.5)
43
+ tzinfo (1.2.7)
38
44
  thread_safe (~> 0.1)
39
- validated_object (2.0.2)
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 (~> 1.16)
47
- rake (~> 10.0)
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.16.1
61
+ 2.1.4
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- [![Build Status](https://travis-ci.org/dogweather/schema-dot-org.svg?branch=master)](https://travis-ci.org/dogweather/schema-dot-org) [![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)
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) that's correct,
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 cannot create invalid markup
70
+ ### You are prevented from creating invalid markup
69
71
 
70
- E.g., If you use the wrong type or try to set an unknown attribute, SchemaDotOrg will
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 at https://github.com/dogweather/schema_dot_org.
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
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "schema_dot_org"
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 "irb"
13
+ require 'irb'
14
14
  IRB.start(__FILE__)
@@ -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 = { "@context" => "http://schema.org" }.freeze
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: true)
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
- { "@type" => un_namespaced_classname }.merge(_to_json_struct.compact)
43
+ { '@type' => un_namespaced_classname }.merge(_to_json_struct.compact)
47
44
  end
48
45
 
49
-
50
46
  def _to_json_struct
51
- raise "For subclasses to implement"
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
- "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
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' => self.name
14
+ 'name' => name
16
15
  }
17
16
  end
18
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 > 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' => self.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' => self.target,
16
- 'query_input' => self.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' => self.name,
18
- 'url' => self.url,
19
- 'potentialAction' => self.potential_action&.to_json_struct
18
+ 'name' => name,
19
+ 'url' => url,
20
+ 'potentialAction' => potential_action&.to_json_struct
20
21
  }
21
22
  end
22
23
  end
@@ -0,0 +1,2 @@
1
+ #!/bin/bash
2
+ ruby -I lib ./test-script.rb
@@ -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.name = "schema_dot_org"
7
- spec.version = '1.5.0'
8
- spec.authors = ["Robb Shecter"]
9
- spec.email = ["robb@public.law"]
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 = %q{JSON-LD generator for Schema.org vocabulary}
12
- spec.description = %q{Creates well-formed website metadata with strongly typed Ruby.}
13
- spec.homepage = "https://github.com/dogweather/schema-dot-org"
14
- spec.license = "MIT"
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 = "exe"
23
+ spec.bindir = 'exe'
20
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
- spec.require_paths = ["lib"]
25
+ spec.require_paths = ['lib']
26
+
27
+ spec.add_dependency 'validated_object', '~> 2.1'
22
28
 
23
- spec.add_dependency "validated_object", "~> 2.0.2"
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.add_development_dependency "bundler", "~> 1.16"
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
@@ -0,0 +1,2 @@
1
+ --dir
2
+ .