Skip to content

Commit

Permalink
The extractAllScripts should default to false in flatten.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Jul 24, 2024
1 parent c5493c1 commit 24a67f4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/json/ld/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
36 changes: 34 additions & 2 deletions spec/flatten_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,37 @@
"@graph": [{"@id": "_:b0","foo": ["bar"]}]
})
},
'Flattens first script element by default': {
input: %(
<html>
<head>
<script type="application/ld+json">
{
"@context": {
"foo": {"@id": "http://example.com/foo", "@container": "@list"}
},
"foo": [{"@value": "bar"}]
}
</script>
<script type="application/ld+json">
{
"@context": {"ex": "http://example.com/"},
"@graph": [
{"ex:foo": {"@value": "foo"}},
{"ex:bar": {"@value": "bar"}}
]
}
</script>
</head>
</html>),
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: %(
<html>
Expand Down Expand Up @@ -622,7 +653,7 @@
}),
base: "http://example.org/doc#second"
},
'Flattens all script elements by default': {
'Flattens all script elements extractAllScripts: true': {
input: %(
<html>
<head>
Expand Down Expand Up @@ -656,7 +687,8 @@
{"@id": "_:b1", "ex:foo": "foo"},
{"@id": "_:b2", "ex:bar": "bar"}
]
})
}),
extractAllScripts: true
}
}.each do |title, params|
it(title) do
Expand Down

0 comments on commit 24a67f4

Please sign in to comment.