module Representable::XML::Namespace
Experimental! Best explanation so far: books.xmlschemata.org/relaxng/relax-CHP-11-SECT-1.html
Note: This module doesn’t work with JRuby because Nokogiri uses a completely different implementation in Java which has other requirements that we couldn’t fulfil. Please wait for Representable
4 where we replace Nokogiri with Oga.
Public Class Methods
Source
# File lib/representable/xml/namespace.rb, line 111 def self.Namespaced(prefix, name) [ prefix, name ].compact.join(":") end
Source
# File lib/representable/xml/namespace.rb, line 9 def self.included(includer) includer.extend(DSL) end
Public Instance Methods
Source
# File lib/representable/xml/namespace.rb, line 104 def add_namespace_definitions!(node, namespaces) namespaces.each do |uri, prefix| prefix = prefix.nil? ? nil : prefix.to_s node.add_namespace_definition(prefix, uri) end end
“Physically” add ‘xmlns` attributes to `node`.
Source
# File lib/representable/xml/namespace.rb, line 81 def from_node(node, options={}) super end
FIXME: some “bug” in Representable’s XML
doesn’t consider the container tag, so we could theoretically pick the wrong namespaced tag here :O
Calls superclass method
Source
# File lib/representable/xml/namespace.rb, line 116 def representable_map(options, format) super.tap do |map| map.each { |bin| bin.extend(AsWithNamespace) unless bin.is_a?(Binding::Attribute) } end end
FIXME: this is a PoC, we need a better API to inject code.
Calls superclass method
Source
# File lib/representable/xml/namespace.rb, line 85 def to_node(options={}) local_uri = representable_attrs.options[:local_namespace] # every decorator MUST have a local namespace. prefix = self.class.namespace_defs[local_uri] root_tag = [prefix, representation_wrap(options)].compact.join(":") options = { wrap: root_tag }.merge(options) # TODO: there should be an easier way to pass a set of options to all nested #to_node decorators. representable_attrs.keys.each do |property| options[property.to_sym] = { show_definition: false, namespaces: options[:namespaces] } end super(options).tap do |node| add_namespace_definitions!(node, self.class.namespace_defs) unless options[:show_definition] == false end end
Calls superclass method