gretel-jsonld 0.2.0 → 1.0.0.rc1

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
- SHA1:
3
- metadata.gz: b148016c75478dd947e087855608b34439be9ba8
4
- data.tar.gz: ab4814c23a2a01042724350f8ea5fae3321dab89
2
+ SHA256:
3
+ metadata.gz: b8ed941958ee879b901c34cc71df02879f48d39da255bf3adb6d41597792833e
4
+ data.tar.gz: bd4529a8789dbc6bffcc1deced291dd59e01a7cd5524a93cfa9a48f87e303e72
5
5
  SHA512:
6
- metadata.gz: ccda8ccceb6689db485af211b7ad4d16fefbb17a98f3fcfa0853b6e6545fd3ed696a98a0f1e058f94bec13e16522e1aee4799a820151a376785fe7821cca3447
7
- data.tar.gz: cce14c004c513533c2c1b8c83772fc941917da428ebbca6d0c16cb844c21401ac429db8f8f39f444326ebe34a6f912ad3ffd20bfe4bf8e915f7b958addad4786
6
+ metadata.gz: 237c2f713dc99b29a7ff3986ef6a34ab9d78eb738020d2325e01f583eab1e8115c7d28160e894249cd06119ffab794fcc7aa4621c77d542618e8b5f61b202c37
7
+ data.tar.gz: 4f85e13c1f0606c0b841309e7591af2b82033e081e5ca8edda74cfab2a6b84aa7f8331aecd35b9365b0ba0458065d30317786c0a96e8c421f062288190013018
data/CHANGELOG.md CHANGED
@@ -1,11 +1,28 @@
1
1
  # CHANGELOG
2
+
3
+ ## [1.0.0.rc1](https://github.com/yasaichi/gretel-jsonld/releases/tag/v1.0.0.rc1) (July 23, 2026)
4
+
5
+ * [Generate valid breadcrumb item URLs](https://github.com/yasaichi/gretel-jsonld/pull/28)
6
+ * [Document effective Gretel options](https://github.com/yasaichi/gretel-jsonld/pull/27)
7
+ * [Load Railtie only when available](https://github.com/yasaichi/gretel-jsonld/pull/24)
8
+ * [Specify minimum Rails dependencies](https://github.com/yasaichi/gretel-jsonld/pull/21)
9
+ * [Support Gretel 4 and 5](https://github.com/yasaichi/gretel-jsonld/pull/19)
10
+
11
+ ## [0.3.0](https://github.com/yasaichi/gretel-jsonld/releases/tag/v0.3.0) (July 22, 2026)
12
+
13
+ * [Test against Rails 6 through 8](https://github.com/yasaichi/gretel-jsonld/pull/18)
14
+ * [Drop support for Ruby 2.4 and earlier](https://github.com/yasaichi/gretel-jsonld/pull/16)
15
+
2
16
  ## [0.2.0](https://github.com/yasaichi/gretel-jsonld/releases/tag/v0.2.0) (November 25, 2017)
17
+
3
18
  * [Write README](https://github.com/yasaichi/gretel-jsonld/pull/7)
4
19
  * [Use `JSONLD` as module name instead of `Jsonld`](https://github.com/yasaichi/gretel-jsonld/pull/6)
5
20
  * [Specify the required Ruby version](https://github.com/yasaichi/gretel-jsonld/pull/5)
6
21
 
7
22
  ## [0.1.1](https://github.com/yasaichi/gretel-jsonld/releases/tag/v0.1.1) (November 25, 2017)
23
+
8
24
  * [Cope with Rails 4.0 or former](https://github.com/yasaichi/gretel-jsonld/pull/4)
9
25
 
10
26
  ## [0.1.0](https://github.com/yasaichi/gretel-jsonld/releases/tag/v0.1.0) (November 23, 2017)
27
+
11
28
  * The initial release to reserve the gem name
data/README.md CHANGED
@@ -1,43 +1,45 @@
1
1
  # gretel-jsonld
2
+
2
3
  [![Gem Version](https://badge.fury.io/rb/gretel-jsonld.svg)](http://badge.fury.io/rb/gretel-jsonld)
3
- [![Build Status](https://travis-ci.org/yasaichi/gretel-jsonld.svg?branch=master)](https://travis-ci.org/yasaichi/gretel-jsonld)
4
- [![Code Climate](https://api.codeclimate.com/v1/badges/fc3fd5037eb200bedbf5/maintainability)](https://codeclimate.com/github/yasaichi/gretel-jsonld/maintainability)
5
- [![Test Coverage](https://codeclimate.com/github/yasaichi/gretel-jsonld/badges/coverage.svg)](https://codeclimate.com/github/yasaichi/gretel-jsonld/coverage)
4
+ [![CI](https://github.com/yasaichi/gretel-jsonld/actions/workflows/ci.yml/badge.svg)](https://github.com/yasaichi/gretel-jsonld/actions/workflows/ci.yml)
5
+ [![Code Coverage](https://qlty.sh/gh/yasaichi/projects/gretel-jsonld/coverage.svg)](https://qlty.sh/gh/yasaichi/projects/gretel-jsonld)
6
6
 
7
- gretel-jsonld enables gretel gem to handle JSON-LD based breadcrumbs.
7
+ gretel-jsonld enables [gretel](https://github.com/kzkn/gretel) to generate
8
+ breadcrumbs using JSON-LD structured data.
8
9
 
9
10
  ## Installation
10
- Add this line to your application's `Gemfile`:
11
+
12
+ In your `Gemfile`:
11
13
 
12
14
  ```ruby
13
- gem 'gretel-jsonld'
15
+ gem "gretel-jsonld"
14
16
  ```
15
17
 
16
- And then execute:
18
+ And run:
19
+
17
20
  ```bash
18
- $ bundle
21
+ $ bundle install
19
22
  ```
20
23
 
21
- ## Usage
22
- First, run the installation generator with:
24
+ ## Example
25
+
26
+ Start by generating the breadcrumbs configuration file:
23
27
 
24
28
  ```sh
25
29
  $ rails generate gretel:install
26
30
  ```
27
31
 
28
- Next, define "crumbs" in `config/breadcrumbs.rb`:
32
+ Then, in `config/breadcrumbs.rb`:
29
33
 
30
34
  ```ruby
31
- # See also: https://github.com/lassebunk/gretel#more-examples
32
-
33
35
  # Root crumb
34
36
  crumb :root do
35
- link 'Home', root_path
37
+ link "Home", root_path
36
38
  end
37
39
 
38
40
  # Issue list
39
41
  crumb :issues do
40
- link 'All issues', issues_path
42
+ link "All issues", issues_path
41
43
  end
42
44
 
43
45
  # Issue
@@ -47,80 +49,116 @@ crumb :issue do |issue|
47
49
  end
48
50
  ```
49
51
 
50
- Then, add this line to your application's layout:
52
+ At the top of `app/views/issues/show.html.erb`, set the current breadcrumb
53
+ (assuming you have loaded `@issue` with an issue):
51
54
 
52
55
  ```erb
53
- <%= jsonld_breadcrumbs %>
56
+ <% breadcrumb :issue, @issue %>
54
57
  ```
55
58
 
56
- Finally, specify a current breadcrumb in each view:
59
+ Then, in `app/views/layouts/application.html.erb`:
57
60
 
58
61
  ```erb
59
- <% breadcrumb :issue, @issue %>
62
+ <%= jsonld_breadcrumbs %>
60
63
  ```
61
64
 
62
- This will generate the following breadcrumbs, marked up with JSON-LD (indented for readability):
65
+ For a request to `https://example.com/issues/46`, this will generate the
66
+ following JSON-LD (indented for readability):
63
67
 
64
68
  ```html
65
69
  <script type="application/ld+json">
66
- {
67
- "@context":"http://schema.org",
68
- "@type":"BreadcrumbList",
69
- "itemListElement":[
70
- {
71
- "@type":"ListItem",
72
- "position":1,
73
- "item":{
74
- "@id":"/",
75
- "name":"Home"
76
- }
77
- },
78
- {
79
- "@type":"ListItem",
80
- "position":2,
81
- "item":{
82
- "@id":"/issues",
83
- "name":"All issues"
84
- }
85
- },
86
- {
87
- "@type":"ListItem",
88
- "position":3,
89
- "item":{
90
- "@id":"/issues/46",
91
- "name":"My Issue"
70
+ {
71
+ "@context": "http://schema.org",
72
+ "@type": "BreadcrumbList",
73
+ "itemListElement": [
74
+ {
75
+ "@type": "ListItem",
76
+ "position": 1,
77
+ "item": {
78
+ "@id": "https://example.com/",
79
+ "name": "Home"
80
+ }
81
+ },
82
+ {
83
+ "@type": "ListItem",
84
+ "position": 2,
85
+ "item": {
86
+ "@id": "https://example.com/issues",
87
+ "name": "All issues"
88
+ }
89
+ },
90
+ {
91
+ "@type": "ListItem",
92
+ "position": 3,
93
+ "item": {
94
+ "@id": "https://example.com/issues/46",
95
+ "name": "My Issue"
96
+ }
92
97
  }
93
- }
94
- ]
95
- }
98
+ ]
99
+ }
96
100
  </script>
97
101
  ```
98
102
 
99
103
  ## Options
100
104
 
101
- You can pass `jsonld_breadcrumbs` the same options as `breadcrumbs`:
105
+ You can pass options to `<%= jsonld_breadcrumbs %>`, e.g.:
102
106
 
103
107
  ```erb
104
- <%= jsonld_breadcrumbs link_current_to_request_path: false %>
108
+ <%= jsonld_breadcrumbs autoroot: false, link_current_to_request_path: false %>
105
109
  ```
106
110
 
107
- For further information, please see [gretel's documentation](https://github.com/lassebunk/gretel/blob/master/README.md#options).
111
+ Options that change the breadcrumb collection also affect the JSON-LD output:
112
+
113
+ Option | Description | Default
114
+ ------------------------ | --------------------------------------------------------------------------------------------------------------------------- | -------
115
+ :autoroot | Whether it should automatically add the `:root` crumb to the `BreadcrumbList` if no parent is given. | True
116
+ :display_single_fragment | Whether it should output the `BreadcrumbList` if it includes only one item. | False
117
+ :link_current_to_request_path | Whether the current crumb's `item.@id` in the `BreadcrumbList` should always use the current request path. | True
118
+
119
+ Options concerned only with HTML presentation do not change the JSON-LD
120
+ output. For example, `link_current` controls whether the current crumb is
121
+ rendered as an HTML link, but the current crumb always includes `item.@id` in
122
+ JSON-LD.
123
+
124
+ For further information, please see
125
+ [Gretel's documentation](https://github.com/kzkn/gretel#options).
126
+
127
+ ## Nice to know
128
+
129
+ ### Breadcrumb URLs
130
+
131
+ Relative breadcrumb paths are resolved against the current request's base URL.
132
+ Absolute breadcrumb URLs are used as-is.
133
+
134
+ Breadcrumbs without link URLs are omitted from the JSON-LD output because each
135
+ breadcrumb item is identified by `@id`, whose value must be an IRI reference
136
+ under the
137
+ [JSON-LD specification](https://www.w3.org/TR/json-ld11/#node-objects).
108
138
 
109
139
  ## Supported versions
110
- Note that gretel-jsonld doesn't support all versions of gretel, Ruby and Rails:
111
140
 
112
- * gretel: gretel-jsonld supports __only 3.x__ for now
113
- * Ruby: gretel 3.x supports __1.9.3 or later__, but gretel-jsonld does __only 2.2.2 or later__
114
- * Rails: gretel 3.x supports __3.1 or later__, but gretel-jsonld does __only 3.2 or later__
141
+ gretel-jsonld supports gretel 3.0 or later without an upper version bound.
142
+ The supported version ranges are:
143
+
144
+ | gretel | Rails | Ruby |
145
+ | --- | --- | --- |
146
+ | 3.x | 5.x | 2.5 or later |
147
+ | 4.x | 5.1 through 7.1 | 2.5 or later |
148
+ | 5.x | 6.1 or later | 3.0 or later |
149
+
150
+ CI covers the lowest and highest supported Rails majors for each gretel major.
115
151
 
116
152
  ## Contributing
117
- You should follow the steps below:
153
+
154
+ To contribute:
118
155
 
119
156
  1. [Fork the repository](https://help.github.com/articles/fork-a-repo/)
120
157
  2. Create a feature branch: `git checkout -b add-new-feature`
121
158
  3. Commit your changes: `git commit -am 'Add new feature'`
122
159
  4. Push the branch: `git push origin add-new-feature`
123
- 4. [Send us a pull request](https://help.github.com/articles/about-pull-requests/)
160
+ 5. [Send us a pull request](https://help.github.com/articles/about-pull-requests/)
124
161
 
125
162
  ## License
163
+
126
164
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -1,41 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "json"
4
- require "active_support"
5
- require "active_support/json/encoding"
6
- require "gretel/jsonld/breadcrumb/list_item"
7
4
 
8
5
  module Gretel
9
6
  module JSONLD
10
7
  module Breadcrumb
11
8
  class List
12
- def initialize(link_collection)
13
- @link_collection = link_collection
9
+ def initialize(items)
10
+ @items = items
14
11
  end
15
12
 
16
- # NOTE: Override #as_json to cope with Rails 4.0 or former
17
- def as_json(options = nil)
13
+ def to_json(*args)
18
14
  {
19
15
  "@context": "http://schema.org",
20
16
  "@type": "BreadcrumbList",
21
- itemListElement: item_list_element,
22
- }.as_json(options)
23
- end
24
-
25
- def to_json(*args)
26
- as_json.to_json(*args)
27
- end
28
-
29
- private
30
-
31
- def item_list_element
32
- @link_collection.map.with_index(1) do |link, index|
33
- ::Gretel::JSONLD::Breadcrumb::ListItem.new(
34
- id: link.url,
35
- name: link.text,
36
- position: index,
37
- )
38
- end
17
+ itemListElement: @items
18
+ }.to_json(*args)
39
19
  end
40
20
  end
41
21
  end
@@ -1,33 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "json"
4
- require "active_support"
5
- require "active_support/json/encoding"
6
4
 
7
5
  module Gretel
8
6
  module JSONLD
9
7
  module Breadcrumb
10
8
  class ListItem
11
- def initialize(id:, name:, position:)
12
- @id = id
13
- @name = name
9
+ def initialize(position:, title:, url:)
14
10
  @position = position
11
+ @title = title
12
+ @url = url
15
13
  end
16
14
 
17
- # NOTE: Override #as_json to cope with Rails 4.0 or former
18
- def as_json(options = nil)
15
+ def to_json(*args)
19
16
  {
20
17
  "@type": "ListItem",
21
18
  position: @position,
22
19
  item: {
23
- "@id": @id,
24
- name: @name,
20
+ "@id": @url,
21
+ name: @title
25
22
  }
26
- }.as_json(options)
27
- end
28
-
29
- def to_json(*args)
30
- as_json.to_json(*args)
23
+ }.to_json(*args)
31
24
  end
32
25
  end
33
26
  end
@@ -1,15 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support"
4
3
  require "active_support/lazy_load_hooks"
5
- require "rails/railtie"
4
+ require "gretel/jsonld/view_helpers"
6
5
 
7
6
  module Gretel
8
7
  module JSONLD
9
8
  class Railtie < ::Rails::Railtie
10
- initializer "gretel.jsonld" do
9
+ initializer "gretel.jsonld", after: "gretel.view_helpers" do
11
10
  ::ActiveSupport.on_load(:action_view) do
12
- require "gretel/jsonld/view_helpers"
11
+ include ::Gretel::JSONLD::ViewHelpers
13
12
  end
14
13
  end
15
14
  end
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "json"
4
3
  require "active_support"
5
4
  require "active_support/core_ext/string/output_safety"
5
+ require "json"
6
6
  require "gretel/jsonld/breadcrumb/list"
7
+ require "gretel/jsonld/breadcrumb/list_item"
8
+ require "uri"
7
9
 
8
10
  module Gretel
9
11
  module JSONLD
@@ -17,10 +19,28 @@ module Gretel
17
19
 
18
20
  @view_context.content_tag(
19
21
  :script,
20
- JSON.generate(::Gretel::JSONLD::Breadcrumb::List.new(link_collection)).html_safe,
22
+ JSON.generate(to_breadcrumb_list(link_collection)).html_safe,
21
23
  type: "application/ld+json",
22
24
  )
23
25
  end
26
+
27
+ private
28
+
29
+ def resolve_uri(uri_reference)
30
+ ::URI.join(@view_context.request.base_url, uri_reference)
31
+ end
32
+
33
+ def to_breadcrumb_list(link_collection)
34
+ link_collection
35
+ .select { |link, _| link.url }
36
+ .map.with_index(1) { |link, position|
37
+ ::Gretel::JSONLD::Breadcrumb::ListItem.new(
38
+ position: position,
39
+ title: link.text,
40
+ url: resolve_uri(link.url),
41
+ )
42
+ }.yield_self { |items| ::Gretel::JSONLD::Breadcrumb::List.new(items) }
43
+ end
24
44
  end
25
45
  end
26
46
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Gretel
4
4
  module JSONLD
5
- VERSION = "0.2.0".freeze
5
+ VERSION = "1.0.0.rc1".freeze
6
6
  end
7
7
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "action_view"
4
3
  require "gretel"
5
4
  require "gretel/jsonld/renderer"
6
5
 
@@ -19,5 +18,3 @@ module Gretel
19
18
  end
20
19
  end
21
20
  end
22
-
23
- ActionView::Base.include(Gretel::JSONLD::ViewHelpers)
data/lib/gretel/jsonld.rb CHANGED
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "action_view"
3
4
  require "gretel/jsonld/version"
4
5
 
5
- if defined?(Rails)
6
+ if defined?(Rails::Railtie)
6
7
  require "gretel/jsonld/railtie"
7
8
  else
8
9
  require "gretel/jsonld/view_helpers"
10
+ ActionView::Base.include(Gretel::JSONLD::ViewHelpers)
9
11
  end
metadata CHANGED
@@ -1,29 +1,56 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gretel-jsonld
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - yasaichi
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2017-11-25 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: activesupport
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '5.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '5.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: actionview
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '5.0'
13
40
  - !ruby/object:Gem::Dependency
14
41
  name: gretel
15
42
  requirement: !ruby/object:Gem::Requirement
16
43
  requirements:
17
44
  - - ">="
18
45
  - !ruby/object:Gem::Version
19
- version: 3.0.0
46
+ version: '3.0'
20
47
  type: :runtime
21
48
  prerelease: false
22
49
  version_requirements: !ruby/object:Gem::Requirement
23
50
  requirements:
24
51
  - - ">="
25
52
  - !ruby/object:Gem::Version
26
- version: 3.0.0
53
+ version: '3.0'
27
54
  - !ruby/object:Gem::Dependency
28
55
  name: appraisal
29
56
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +66,7 @@ dependencies:
39
66
  - !ruby/object:Gem::Version
40
67
  version: '0'
41
68
  - !ruby/object:Gem::Dependency
42
- name: sqlite3
69
+ name: nokogiri
43
70
  requirement: !ruby/object:Gem::Requirement
44
71
  requirements:
45
72
  - - ">="
@@ -52,6 +79,20 @@ dependencies:
52
79
  - - ">="
53
80
  - !ruby/object:Gem::Version
54
81
  version: '0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: railties
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '5.0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '5.0'
55
96
  - !ruby/object:Gem::Dependency
56
97
  name: reek
57
98
  requirement: !ruby/object:Gem::Requirement
@@ -81,7 +122,7 @@ dependencies:
81
122
  - !ruby/object:Gem::Version
82
123
  version: '0'
83
124
  - !ruby/object:Gem::Dependency
84
- name: rubocop
125
+ name: rubocop-rails-omakase
85
126
  requirement: !ruby/object:Gem::Requirement
86
127
  requirements:
87
128
  - - ">="
@@ -108,6 +149,20 @@ dependencies:
108
149
  - - ">="
109
150
  - !ruby/object:Gem::Version
110
151
  version: '0'
152
+ - !ruby/object:Gem::Dependency
153
+ name: sqlite3
154
+ requirement: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ type: :development
160
+ prerelease: false
161
+ version_requirements: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
111
166
  description: gretel-jsonld enables gretel gem to handle JSON-LD based breadcrumbs.
112
167
  email:
113
168
  - yasaichi@users.noreply.github.com
@@ -130,7 +185,6 @@ homepage: https://github.com/yasaichi/gretel-jsonld
130
185
  licenses:
131
186
  - MIT
132
187
  metadata: {}
133
- post_install_message:
134
188
  rdoc_options: []
135
189
  require_paths:
136
190
  - lib
@@ -138,16 +192,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
192
  requirements:
139
193
  - - ">="
140
194
  - !ruby/object:Gem::Version
141
- version: 2.2.2
195
+ version: '2.5'
142
196
  required_rubygems_version: !ruby/object:Gem::Requirement
143
197
  requirements:
144
198
  - - ">="
145
199
  - !ruby/object:Gem::Version
146
200
  version: '0'
147
201
  requirements: []
148
- rubyforge_project:
149
- rubygems_version: 2.5.2.1
150
- signing_key:
202
+ rubygems_version: 4.0.16
151
203
  specification_version: 4
152
204
  summary: Gretel extension for supporting JSON-LD breadcrumbs
153
205
  test_files: []