Class: Builder::RdfXml

Inherits:
XmlMarkup
  • Object
show all
Defined in:
vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfxml-6b89d4c13d63/lib/rdf/rdfxml/extensions.rb

Overview

Extends XmlMarkup#tag! to better control whitespace when adding content from a block

Instance Method Summary collapse

Instance Method Details

#tag!(sym, *args, &block) ⇒ Object

Create a tag named +sym+. Other than the first argument which is the tag name, the arguments are the same as the tags implemented via method_missing.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfxml-6b89d4c13d63/lib/rdf/rdfxml/extensions.rb', line 14

def tag!(sym, *args, &block)
  text = nil
  attrs = args.last.is_a?(::Hash) ? args.last : {}
  return super unless block && attrs[:no_whitespace]
  attrs.delete(:no_whitespace)

  sym = "#{sym}:#{args.shift}".to_sym if args.first.kind_of?(::Symbol)

  args.each do |arg|
    case arg
    when ::Hash
      attrs.merge!(arg)
    when nil
      attrs.merge!({:nil => true}) if explicit_nil_handling?
    else
      text ||= ''
      text << arg.to_s
    end
  end

  unless text.nil?
    ::Kernel::raise ::ArgumentError,
      "XmlMarkup cannot mix a text argument with a block"
  end

  # Indent
  _indent
  #unless @indent == 0 || @level == 0
  #  text!(" " * (@level * @indent))
  #end

  _start_tag(sym, attrs)
  begin
    _nested_structures(block)
  ensure
    _end_tag(sym)
    _newline
  end
end