From 24a67f495d2c112fb38f2d03ef91b14ac25f3830 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Wed, 24 Jul 2024 10:07:39 -0700 Subject: [PATCH] The extractAllScripts should default to false in flatten. --- lib/json/ld/api.rb | 5 +++-- spec/flatten_spec.rb | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/lib/json/ld/api.rb b/lib/json/ld/api.rb index a8032b1..5919324 100644 --- a/lib/json/ld/api.rb +++ b/lib/json/ld/api.rb @@ -290,8 +290,7 @@ def self.compact(input, context, expanded: false, serializer: nil, **options) def self.flatten(input, context, expanded: false, serializer: nil, **options) flattened = [] options = { - compactToRelative: true, - extractAllScripts: true + compactToRelative: true }.merge(options) # Expand input to simplify processing @@ -518,6 +517,8 @@ def self.frame(input, frame, expanded: false, serializer: nil, **options) # @option options (see #initialize) # @option options [Boolean] :produceGeneralizedRdf (false) # If true, output will include statements having blank node predicates, otherwise they are dropped. + # @option options [Boolean] :extractAllScripts (true) + # If set, when given an HTML input without a fragment identifier, extracts all `script` elements with type `application/ld+json` into an array during expansion. # @raise [JsonLdError] # @yield statement # @yieldparam [RDF::Statement] statement diff --git a/spec/flatten_spec.rb b/spec/flatten_spec.rb index a8fefe3..990eb9a 100644 --- a/spec/flatten_spec.rb +++ b/spec/flatten_spec.rb @@ -557,6 +557,37 @@ "@graph": [{"@id": "_:b0","foo": ["bar"]}] }) }, + 'Flattens first script element by default': { + input: %( + + + + + + ), + context: %({"foo": {"@id": "http://example.com/foo", "@container": "@list"}}), + output: %({ + "@context": { + "foo": {"@id": "http://example.com/foo", "@container": "@list"} + }, + "@graph": [{"@id": "_:b0","foo": ["bar"]}] + }) + }, 'Flattens first script element with extractAllScripts: false': { input: %( @@ -622,7 +653,7 @@ }), base: "http://example.org/doc#second" }, - 'Flattens all script elements by default': { + 'Flattens all script elements extractAllScripts: true': { input: %( @@ -656,7 +687,8 @@ {"@id": "_:b1", "ex:foo": "foo"}, {"@id": "_:b2", "ex:bar": "bar"} ] - }) + }), + extractAllScripts: true } }.each do |title, params| it(title) do