Module: RDF::TriX::Writer::Nokogiri
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/rdf-trix-4b113f65db0e/lib/rdf/trix/writer/nokogiri.rb
Overview
Nokogiri implementation of the TriX writer.
Class Method Summary collapse
-
.library ⇒ Symbol
Returns the name of the underlying XML library.
Instance Method Summary collapse
-
#create_comment(text) ⇒ Nokogiri::XML::Comment
Creates an XML comment element with the given
text
. -
#create_element(name, content = nil, attributes = {}) {|element| ... } ⇒ Nokogiri::XML::Element
Creates an XML element of the given
name
, with optional givencontent
andattributes
. -
#create_graph(name = nil) {|element| ... } ⇒ Nokogiri::XML::Element
Creates an XML graph element with the given
name
. -
#initialize_xml(**options)
Initializes the underlying XML library.
-
#write_epilogue
Outputs the TriX document.
-
#write_prologue
Generates the TriX root element.
Class Method Details
.library ⇒ Symbol
Returns the name of the underlying XML library.
12 13 14 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-trix-4b113f65db0e/lib/rdf/trix/writer/nokogiri.rb', line 12 def self.library :nokogiri end |
Instance Method Details
#create_comment(text) ⇒ Nokogiri::XML::Comment
Creates an XML comment element with the given text
.
71 72 73 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-trix-4b113f65db0e/lib/rdf/trix/writer/nokogiri.rb', line 71 def create_comment(text) ::Nokogiri::XML::Comment.new(@xml, text.to_s) end |
#create_element(name, content = nil, attributes = {}) {|element| ... } ⇒ Nokogiri::XML::Element
Creates an XML element of the given name
, with optional given
content
and attributes
.
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-trix-4b113f65db0e/lib/rdf/trix/writer/nokogiri.rb', line 85 def create_element(name, content = nil, attributes = {}, &block) element = @xml.create_element(name.to_s) if xmlns = attributes.delete(:xmlns) element.default_namespace = xmlns end fragment = attributes.delete(:fragment) attributes.each { |k, v| element[k.to_s] = v } element.content = content.to_s unless content.nil? element << fragment if fragment block.call(element) if block_given? element end |
#create_graph(name = nil) {|element| ... } ⇒ Nokogiri::XML::Element
Creates an XML graph element with the given name
.
55 56 57 58 59 60 61 62 63 64 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-trix-4b113f65db0e/lib/rdf/trix/writer/nokogiri.rb', line 55 def create_graph(name = nil, &block) @trix << (graph = create_element(:graph)) case name when nil then nil when RDF::Node then graph << create_element(:id, name.to_s) # non-standard else graph << create_element(:uri, name.to_s) end block.call(graph) if block_given? graph end |
#initialize_xml(**options)
This method returns an undefined value.
Initializes the underlying XML library.
21 22 23 24 25 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-trix-4b113f65db0e/lib/rdf/trix/writer/nokogiri.rb', line 21 def initialize_xml(**) require 'nokogiri' unless defined?(::Nokogiri) @xml = ::Nokogiri::XML::Document.new @xml.encoding = @encoding end |
#write_epilogue
This method returns an undefined value.
Outputs the TriX document.
42 43 44 45 46 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-trix-4b113f65db0e/lib/rdf/trix/writer/nokogiri.rb', line 42 def write_epilogue puts @xml.to_xml @xml = @trix = nil super end |
#write_prologue
This method returns an undefined value.
Generates the TriX root element.
31 32 33 34 35 36 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-trix-4b113f65db0e/lib/rdf/trix/writer/nokogiri.rb', line 31 def write_prologue = {xmlns: Format::XMLNS, xml: "http://www.w3.org/XML/1998/namespace"} ["xml:base"] = base_uri.to_s if base_uri @xml << (@trix = create_element(:TriX, nil, )) super end |