lib/json/ld/writer.rb in json-ld-1.1.5 vs lib/json/ld/writer.rb in json-ld-1.1.6

- old
+ new

@@ -83,10 +83,12 @@ # the prefix mappings to use (not supported by all writers) # @option options [Boolean] :standard_prefixes (false) # Add standard prefixes to @prefixes, if necessary. # @option options [IO, Array, Hash, String, Context] :context ({}) # context to use when serializing. Constructed context for native serialization. + # @option options [IO, Array, Hash, String, Context] :frame ({}) + # frame to use when serializing. # @option options [Boolean] :unique_bnodes (false) # Use unique bnode identifiers, defaults to using the identifier which the node was originall initialized with (if any). # @yield [writer] `self` # @yieldparam [RDF::Writer] writer # @yieldreturn [void] @@ -166,11 +168,16 @@ # Rename BNodes to uniquify them, if necessary if options[:unique_bnodes] result = API.flatten(result, context, @options) end - # Perform compaction, if we have a context - if context + frame = RDF::Util::File.open_file(@options[:frame]) if @options[:frame].is_a?(String) + if frame ||= @options[:frame] + # Perform framing, if given a frame + debug("writer") { "frame result"} + result = API.frame(result, frame, @options) + elsif context + # Perform compaction, if we have a context debug("writer") { "compact result"} result = API.compact(result, context, @options) end @output.write(result.to_json(JSON_STATE))