Created
September 7, 2011 22:26
-
-
Save barmintor/1201986 to your computer and use it in GitHub Desktop.
Working around the presence of method names on Nokogiri::XML::Builder that may also be in OM templates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def xml_builder_template(extra_opts = {}) | |
extra_attributes = extra_opts.fetch(:attributes, {}) | |
node_options = [] | |
node_child_template = "" | |
if !self.default_content_path.nil? | |
node_child_options = ["\':::builder_new_value:::\'"] | |
node_child_template = " { xml.#{self.default_content_path}( #{OM::XML.delimited_list(node_child_options)} ) }" | |
else | |
node_options = ["\':::builder_new_value:::\'"] | |
end | |
if !self.attributes.nil? | |
self.attributes.merge(extra_attributes).each_pair do |k,v| | |
node_options << "\'#{k}\'=>\'#{v}\'" | |
end | |
end | |
b_ref = "xml" | |
b_method = self.path | |
if self.path.include?(":") | |
ns_prefix = self.path[0..path.index(":")-1] | |
b_method = self.path[path.index(":")+1..-1] | |
b_ref = "xml['#{ns_prefix}']" | |
elsif !self.namespace_prefix.nil? and self.namespace_prefix != 'oxns' | |
b_ref = "xml['#{self.namespace_prefix}']" | |
end | |
if Nokogiri::XML::Builder.method_defined? b_method.to_sym | |
b_method += '_' | |
end | |
template = "#{b_ref}.#{b_method}( #{OM::XML.delimited_list(node_options)} )" + node_child_template | |
return template.gsub( /:::(.*?):::/ ) { '#{'+$1+'}' } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment