~singpolyma/dhall-xml-ruby

f795b8507c2a21158e15d880a64e438751464746 — Stephen Paul Weber 5 years ago a683674
Initial README
1 files changed, 116 insertions(+), 0 deletions(-)

A README.md
A README.md => README.md +116 -0
@@ 0,0 1,116 @@
# 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
    &lt;&amp;&gt;

    $ 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.