Skip to content

Commit 24a67f4

Browse files
committed
The extractAllScripts should default to false in flatten.
1 parent c5493c1 commit 24a67f4

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

lib/json/ld/api.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,7 @@ def self.compact(input, context, expanded: false, serializer: nil, **options)
290290
def self.flatten(input, context, expanded: false, serializer: nil, **options)
291291
flattened = []
292292
options = {
293-
compactToRelative: true,
294-
extractAllScripts: true
293+
compactToRelative: true
295294
}.merge(options)
296295

297296
# Expand input to simplify processing
@@ -518,6 +517,8 @@ def self.frame(input, frame, expanded: false, serializer: nil, **options)
518517
# @option options (see #initialize)
519518
# @option options [Boolean] :produceGeneralizedRdf (false)
520519
# If true, output will include statements having blank node predicates, otherwise they are dropped.
520+
# @option options [Boolean] :extractAllScripts (true)
521+
# 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.
521522
# @raise [JsonLdError]
522523
# @yield statement
523524
# @yieldparam [RDF::Statement] statement

spec/flatten_spec.rb

+34-2
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,37 @@
557557
"@graph": [{"@id": "_:b0","foo": ["bar"]}]
558558
})
559559
},
560+
'Flattens first script element by default': {
561+
input: %(
562+
<html>
563+
<head>
564+
<script type="application/ld+json">
565+
{
566+
"@context": {
567+
"foo": {"@id": "http://example.com/foo", "@container": "@list"}
568+
},
569+
"foo": [{"@value": "bar"}]
570+
}
571+
</script>
572+
<script type="application/ld+json">
573+
{
574+
"@context": {"ex": "http://example.com/"},
575+
"@graph": [
576+
{"ex:foo": {"@value": "foo"}},
577+
{"ex:bar": {"@value": "bar"}}
578+
]
579+
}
580+
</script>
581+
</head>
582+
</html>),
583+
context: %({"foo": {"@id": "http://example.com/foo", "@container": "@list"}}),
584+
output: %({
585+
"@context": {
586+
"foo": {"@id": "http://example.com/foo", "@container": "@list"}
587+
},
588+
"@graph": [{"@id": "_:b0","foo": ["bar"]}]
589+
})
590+
},
560591
'Flattens first script element with extractAllScripts: false': {
561592
input: %(
562593
<html>
@@ -622,7 +653,7 @@
622653
}),
623654
base: "http://example.org/doc#second"
624655
},
625-
'Flattens all script elements by default': {
656+
'Flattens all script elements extractAllScripts: true': {
626657
input: %(
627658
<html>
628659
<head>
@@ -656,7 +687,8 @@
656687
{"@id": "_:b1", "ex:foo": "foo"},
657688
{"@id": "_:b2", "ex:bar": "bar"}
658689
]
659-
})
690+
}),
691+
extractAllScripts: true
660692
}
661693
}.each do |title, params|
662694
it(title) do

0 commit comments

Comments
 (0)