Skip to content

Commit

Permalink
move the extraction of namespace bindings and additional namespace de…
Browse files Browse the repository at this point in the history
…clarations

into the Namespace module
  • Loading branch information
mccraigmccraig committed May 10, 2011
1 parent 54f9f9f commit ee51185
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
15 changes: 15 additions & 0 deletions lib/rsxml/namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,21 @@ def merge_namespace_bindings(ns1, ns2)
m
end

# given the existing +ns_stack+ of ns bindings, a +tag+ and it's +attributes+,
# return a pair <tt>[ns_bindings, ns_additional_decls]</tt> containing
# ns bindings for the stack, and additional required (exploded) namespace
# declarations to be added to the attributes
def namespace_bindings_declarations(ns_stack, tag, attrs)
ns_declared = extract_declared_namespace_bindings(attrs)
ns_explicit = extract_explicit_namespace_bindings(tag, attrs)
ns_undeclared = undeclared_namespace_bindings(ns_stack + [ns_declared], ns_explicit)
ns_bindings = merge_namespace_bindings(ns_declared, ns_undeclared)

# and declarations for undeclared namespaces
ns_additional_decls = exploded_namespace_declarations(ns_undeclared)

[ns_bindings, ns_additional_decls]
end

end
end
13 changes: 3 additions & 10 deletions lib/rsxml/sexp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,14 @@ def to_s
def traverse(sexp, visitor, context=Context.new)
tag, attrs, children = decompose_sexp(sexp)

# create ns bindings for explicit namespaces which need them
ns_declared = Namespace::extract_declared_namespace_bindings(attrs)
ns_explicit = Namespace::extract_explicit_namespace_bindings(tag, attrs)
ns_undeclared = Namespace::undeclared_namespace_bindings(context.ns_stack + [ns_declared], ns_explicit)
ns_new_bindings = Namespace::merge_namespace_bindings(ns_declared, ns_undeclared)
ns_bindings, ns_additional_decls = Namespace::namespace_bindings_declarations(context.ns_stack, tag, attrs)

# and declarations for undeclared namespaces
ns_undeclared_decls = Namespace::exploded_namespace_declarations(ns_undeclared)

context.ns_stack.push(ns_new_bindings)
context.ns_stack.push(ns_bindings)

etag = Namespace::explode_qname(context.ns_stack, tag)
eattrs = Namespace::explode_attr_qnames(context.ns_stack, attrs)

eattrs = eattrs.merge(ns_undeclared_decls)
eattrs = eattrs.merge(ns_additional_decls)

begin
visitor.tag(context, etag, eattrs) do
Expand Down

0 comments on commit ee51185

Please sign in to comment.