gretel-jsonld 0.3.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
2
  SHA256:
3
- metadata.gz: 1e7bf55860ae8f21a3d5a931806e9c550cf4e1d31af9546703d86d125d14c00e
4
- data.tar.gz: 3286dab9d4dbcc9b9e61a7e4528359ada4e3cb63e59af75a40c765497d2e3c68
3
+ metadata.gz: b8ed941958ee879b901c34cc71df02879f48d39da255bf3adb6d41597792833e
4
+ data.tar.gz: bd4529a8789dbc6bffcc1deced291dd59e01a7cd5524a93cfa9a48f87e303e72
5
5
  SHA512:
6
- metadata.gz: 79b86b733f968da7bca93b29a9ca65486783bb814ebf396d3906ae7ca9646d3b952c36f65a26c99ba191d4edc954ce7af855999b51a320f46ce9d50d7472564c
7
- data.tar.gz: 16b507af8635110bece74b61f433cc401ae4bf2140414f0ab0ac3c73abb07c9eedc7cb7191b4988660c5d94b760f67c3f648c74cfcbe90530704ec1bafdae804
6
+ metadata.gz: 237c2f713dc99b29a7ff3986ef6a34ab9d78eb738020d2325e01f583eab1e8115c7d28160e894249cd06119ffab794fcc7aa4621c77d542618e8b5f61b202c37
7
+ data.tar.gz: 4f85e13c1f0606c0b841309e7591af2b82033e081e5ca8edda74cfab2a6b84aa7f8331aecd35b9365b0ba0458065d30317786c0a96e8c421f062288190013018
data/CHANGELOG.md CHANGED
@@ -1,15 +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
+
2
11
  ## [0.3.0](https://github.com/yasaichi/gretel-jsonld/releases/tag/v0.3.0) (July 22, 2026)
12
+
3
13
  * [Test against Rails 6 through 8](https://github.com/yasaichi/gretel-jsonld/pull/18)
4
14
  * [Drop support for Ruby 2.4 and earlier](https://github.com/yasaichi/gretel-jsonld/pull/16)
5
15
 
6
16
  ## [0.2.0](https://github.com/yasaichi/gretel-jsonld/releases/tag/v0.2.0) (November 25, 2017)
17
+
7
18
  * [Write README](https://github.com/yasaichi/gretel-jsonld/pull/7)
8
19
  * [Use `JSONLD` as module name instead of `Jsonld`](https://github.com/yasaichi/gretel-jsonld/pull/6)
9
20
  * [Specify the required Ruby version](https://github.com/yasaichi/gretel-jsonld/pull/5)
10
21
 
11
22
  ## [0.1.1](https://github.com/yasaichi/gretel-jsonld/releases/tag/v0.1.1) (November 25, 2017)
23
+
12
24
  * [Cope with Rails 4.0 or former](https://github.com/yasaichi/gretel-jsonld/pull/4)
13
25
 
14
26
  ## [0.1.0](https://github.com/yasaichi/gretel-jsonld/releases/tag/v0.1.0) (November 23, 2017)
27
+
15
28
  * The initial release to reserve the gem name
data/README.md CHANGED
@@ -2,46 +2,44 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/gretel-jsonld.svg)](http://badge.fury.io/rb/gretel-jsonld)
4
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
- [![Maintainability](https://qlty.sh/gh/yasaichi/projects/gretel-jsonld/maintainability.svg)](https://qlty.sh/gh/yasaichi/projects/gretel-jsonld)
6
5
  [![Code Coverage](https://qlty.sh/gh/yasaichi/projects/gretel-jsonld/coverage.svg)](https://qlty.sh/gh/yasaichi/projects/gretel-jsonld)
7
6
 
8
- 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.
9
9
 
10
10
  ## Installation
11
11
 
12
- Add this line to your application's `Gemfile`:
12
+ In your `Gemfile`:
13
13
 
14
14
  ```ruby
15
- gem 'gretel-jsonld'
15
+ gem "gretel-jsonld"
16
16
  ```
17
17
 
18
- And then execute:
18
+ And run:
19
19
 
20
20
  ```bash
21
- $ bundle
21
+ $ bundle install
22
22
  ```
23
23
 
24
- ## Usage
24
+ ## Example
25
25
 
26
- First, run the installation generator with:
26
+ Start by generating the breadcrumbs configuration file:
27
27
 
28
28
  ```sh
29
29
  $ rails generate gretel:install
30
30
  ```
31
31
 
32
- Next, define "crumbs" in `config/breadcrumbs.rb`:
32
+ Then, in `config/breadcrumbs.rb`:
33
33
 
34
34
  ```ruby
35
- # See also: https://github.com/lassebunk/gretel#more-examples
36
-
37
35
  # Root crumb
38
36
  crumb :root do
39
- link 'Home', root_path
37
+ link "Home", root_path
40
38
  end
41
39
 
42
40
  # Issue list
43
41
  crumb :issues do
44
- link 'All issues', issues_path
42
+ link "All issues", issues_path
45
43
  end
46
44
 
47
45
  # Issue
@@ -51,19 +49,21 @@ crumb :issue do |issue|
51
49
  end
52
50
  ```
53
51
 
54
- 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):
55
54
 
56
55
  ```erb
57
- <%= jsonld_breadcrumbs %>
56
+ <% breadcrumb :issue, @issue %>
58
57
  ```
59
58
 
60
- Finally, specify a current breadcrumb in each view:
59
+ Then, in `app/views/layouts/application.html.erb`:
61
60
 
62
61
  ```erb
63
- <% breadcrumb :issue, @issue %>
62
+ <%= jsonld_breadcrumbs %>
64
63
  ```
65
64
 
66
- 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):
67
67
 
68
68
  ```html
69
69
  <script type="application/ld+json">
@@ -75,7 +75,7 @@ This will generate the following breadcrumbs, marked up with JSON-LD (indented f
75
75
  "@type": "ListItem",
76
76
  "position": 1,
77
77
  "item": {
78
- "@id": "/",
78
+ "@id": "https://example.com/",
79
79
  "name": "Home"
80
80
  }
81
81
  },
@@ -83,7 +83,7 @@ This will generate the following breadcrumbs, marked up with JSON-LD (indented f
83
83
  "@type": "ListItem",
84
84
  "position": 2,
85
85
  "item": {
86
- "@id": "/issues",
86
+ "@id": "https://example.com/issues",
87
87
  "name": "All issues"
88
88
  }
89
89
  },
@@ -91,7 +91,7 @@ This will generate the following breadcrumbs, marked up with JSON-LD (indented f
91
91
  "@type": "ListItem",
92
92
  "position": 3,
93
93
  "item": {
94
- "@id": "/issues/46",
94
+ "@id": "https://example.com/issues/46",
95
95
  "name": "My Issue"
96
96
  }
97
97
  }
@@ -102,25 +102,56 @@ This will generate the following breadcrumbs, marked up with JSON-LD (indented f
102
102
 
103
103
  ## Options
104
104
 
105
- You can pass `jsonld_breadcrumbs` the same options as `breadcrumbs`:
105
+ You can pass options to `<%= jsonld_breadcrumbs %>`, e.g.:
106
106
 
107
107
  ```erb
108
- <%= jsonld_breadcrumbs link_current_to_request_path: false %>
108
+ <%= jsonld_breadcrumbs autoroot: false, link_current_to_request_path: false %>
109
109
  ```
110
110
 
111
- For further information, please see [gretel's documentation](https://github.com/WilHall/gretel/blob/develop/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).
112
138
 
113
139
  ## Supported versions
114
140
 
115
- Note that gretel-jsonld doesn't support all versions of gretel, Ruby and Rails:
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 |
116
149
 
117
- - gretel: gretel-jsonld supports **only 3.x** for now
118
- - Ruby: gretel 3.x supports **1.9.3 or later**, but gretel-jsonld does **only 2.5 or later**
119
- - Rails: gretel 3.x supports **3.1 or later**, but gretel-jsonld does **only 5 or later**
150
+ CI covers the lowest and highest supported Rails majors for each gretel major.
120
151
 
121
152
  ## Contributing
122
153
 
123
- You should follow the steps below:
154
+ To contribute:
124
155
 
125
156
  1. [Fork the repository](https://help.github.com/articles/fork-a-repo/)
126
157
  2. Create a feature branch: `git checkout -b add-new-feature`
@@ -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.3.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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gretel-jsonld
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - yasaichi
@@ -9,20 +9,48 @@ bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
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'
12
40
  - !ruby/object:Gem::Dependency
13
41
  name: gretel
14
42
  requirement: !ruby/object:Gem::Requirement
15
43
  requirements:
16
44
  - - ">="
17
45
  - !ruby/object:Gem::Version
18
- version: 3.0.0
46
+ version: '3.0'
19
47
  type: :runtime
20
48
  prerelease: false
21
49
  version_requirements: !ruby/object:Gem::Requirement
22
50
  requirements:
23
51
  - - ">="
24
52
  - !ruby/object:Gem::Version
25
- version: 3.0.0
53
+ version: '3.0'
26
54
  - !ruby/object:Gem::Dependency
27
55
  name: appraisal
28
56
  requirement: !ruby/object:Gem::Requirement
@@ -38,7 +66,7 @@ dependencies:
38
66
  - !ruby/object:Gem::Version
39
67
  version: '0'
40
68
  - !ruby/object:Gem::Dependency
41
- name: sqlite3
69
+ name: nokogiri
42
70
  requirement: !ruby/object:Gem::Requirement
43
71
  requirements:
44
72
  - - ">="
@@ -51,6 +79,20 @@ dependencies:
51
79
  - - ">="
52
80
  - !ruby/object:Gem::Version
53
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'
54
96
  - !ruby/object:Gem::Dependency
55
97
  name: reek
56
98
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +122,7 @@ dependencies:
80
122
  - !ruby/object:Gem::Version
81
123
  version: '0'
82
124
  - !ruby/object:Gem::Dependency
83
- name: rubocop
125
+ name: rubocop-rails-omakase
84
126
  requirement: !ruby/object:Gem::Requirement
85
127
  requirements:
86
128
  - - ">="
@@ -94,7 +136,7 @@ dependencies:
94
136
  - !ruby/object:Gem::Version
95
137
  version: '0'
96
138
  - !ruby/object:Gem::Dependency
97
- name: rubocop-performance
139
+ name: simplecov
98
140
  requirement: !ruby/object:Gem::Requirement
99
141
  requirements:
100
142
  - - ">="
@@ -108,7 +150,7 @@ dependencies:
108
150
  - !ruby/object:Gem::Version
109
151
  version: '0'
110
152
  - !ruby/object:Gem::Dependency
111
- name: simplecov
153
+ name: sqlite3
112
154
  requirement: !ruby/object:Gem::Requirement
113
155
  requirements:
114
156
  - - ">="