Add XML::Utils module
This commit is contained in:
@@ -3,6 +3,8 @@ require 'calligraphy/web_dav_request'
|
|||||||
require 'calligraphy/xml/builder'
|
require 'calligraphy/xml/builder'
|
||||||
require 'calligraphy/xml/namespace'
|
require 'calligraphy/xml/namespace'
|
||||||
require 'calligraphy/xml/node'
|
require 'calligraphy/xml/node'
|
||||||
|
require 'calligraphy/xml/utils'
|
||||||
|
|
||||||
module Calligraphy
|
module Calligraphy
|
||||||
|
DAV_NS = 'DAV:'
|
||||||
end
|
end
|
||||||
|
|||||||
18
lib/calligraphy/xml/utils.rb
Normal file
18
lib/calligraphy/xml/utils.rb
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
module Calligraphy::XML
|
||||||
|
module Utils
|
||||||
|
def xml_for(body:, node:)
|
||||||
|
xml = Nokogiri::XML body
|
||||||
|
return :bad_request unless xml.errors.empty?
|
||||||
|
|
||||||
|
namespace = nil
|
||||||
|
xml.root.namespace_definitions.each do |n|
|
||||||
|
namespace = "#{n.prefix}|" if n&.href == Calligraphy::DAV_NS && !n.prefix.nil?
|
||||||
|
end
|
||||||
|
namespace
|
||||||
|
|
||||||
|
node = node.split(' ').map! { |n| namespace + n }.join(' ') if namespace
|
||||||
|
|
||||||
|
xml.css(node).children
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user