XML Extension for Dhall in Ruby
This is an extension for the dhall
gem that adds some XML related features.
Versioning
This project follows semantic versioning. For the purposes of considering what is a "breaking change" only the API as documented in this README is considered, regardless of any other exposed parts of the library. Anything not documented here may change at any time, but backward-incompatible changes to anything documented here will be accompanied by a major-version increment.
Installation
Add this line to your application's Gemfile:
gem "dhall-xml"
And then execute:
bundle
Or install it yourself as:
gem install dhall-xml
dhall-to-xml
and xml-to-dhall
This package comes with two executables you can run even if you don't intend to use it as a library.
$ echo 'https://github.com/dhall-lang/dhall-lang/raw/master/Prelude/XML/text "<&>"' | dhall-to-xml
<&>
$ echo '<root><child id="1">hello</child></root>' | xml-to-dhall | dhall decode
λ(_ : Type)
→ λ ( _
: { element :
{ attributes :
List { mapKey : Text, mapValue : Text }
, content :
List _
, name :
Text
}
→ _@1
, text :
Text → _@1
}
)
→ _.element
{ attributes =
[] : List { mapKey : Text, mapValue : Text }
, content =
[ _.element
{ attributes =
[ { mapKey = "id", mapValue = "1" } ]
, content =
[ _.text "hello" ]
, name =
"child"
}
]
, name =
"root"
}
A Type Definition
Dhall::XML::TYPE
is the Dhall type of an XML node, for use in constructing Dhall expressions.
A Coder that supports Nokogiri nodes
Works exactly the same as Dhall::Coder
but also supports loading and dumping Nokogiri nodes:
Dhall::XML::Coder.load(<<~DHALL
https://github.com/dhall-lang/dhall-lang/raw/master/Prelude/XML/text "<&>"
DHALL
) # => #<Nokogiri::XML::Text:0x2ac307365958 "<&>">
Dhall::XML::Coder.load(<<~DHALL
https://github.com/dhall-lang/dhall-lang/raw/master/Prelude/XML/leaf {
name = "root",
attributes = toMap { id = "12" }
}
DHALL
) # => #<Nokogiri::XML::Element name="root" attributes=[#<Nokogiri::XML::Attr name="id" value="12">]>
A Refinement for Nokogiri nodes
Works exactly the same as using Dhall::AsDhall
but for Nokogiri nodes and documents:
using Dhall::XML::AsDhall
Nokogiri::XML::Document.new.create_text_node("<&>").as_dhall # => #<Dhall::Function ...>
Getting Help
If you have any questions about this library, or wish to report a bug, please send email to: dev@singpolyma.net
Contributing
Tests can be run with:
make test
If you have code or patches you wish to contribute, the maintainer's preferred mechanism is a git pull request. Push your changes to a git repository somewhere, for example:
git remote rename origin upstream
git remote add origin git@git.sr.ht:~yourname/dhall-xml-ruby
git push -u origin master
Then generate the pull request:
git fetch upstream master
git request-pull -p upstream/master origin
And copy-paste the result into a plain-text email to: dev@singpolyma.net
You may alternately use a patch-based approach as described on https://git-send-email.io
Contributions follow an inbound=outbound model -- you (or your employer) keep all copyright on your patches, but agree to license them according to this project's COPYING file.