From 379ffde652b735604ed8826b67284bba8427d528 Mon Sep 17 00:00:00 2001 From: tovedetered Date: Wed, 13 Mar 2024 14:15:55 -0400 Subject: [PATCH] only need to add options now --- src/xmleam/xml_builder.gleam | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/xmleam/xml_builder.gleam b/src/xmleam/xml_builder.gleam index 3114c67..875a198 100644 --- a/src/xmleam/xml_builder.gleam +++ b/src/xmleam/xml_builder.gleam @@ -25,6 +25,7 @@ pub type BuilderError { EncodingEmpty TagPlacedBeforeNew InnerEmpty + EmptyDocument NOTAPPLICABLE } @@ -96,6 +97,15 @@ pub fn tag(label: String, contents: String, document: XmlBuilder) -> XmlBuilder } } +/// this starts a block which is a tag with other tags inside of it +/// ie. +/// example@example.com +/// +/// +/// Usage: |>block_tag("owner", { +/// new() +/// |> tag("email", "example@example.com") +/// }) pub fn block_tag(label: String, inner: XmlBuilder, document: XmlBuilder) { let label_empty = string.is_empty(label) use <- bool.guard(when: label_empty, return: Error(LabelEmpty)) @@ -123,3 +133,16 @@ pub fn block_tag(label: String, inner: XmlBuilder, document: XmlBuilder) { } } } + +/// this one ends the xml document +/// takes in the Xml Document and outputs +/// a Result(String, BuilderError) +pub fn end_xml(document: XmlBuilder) -> Result(String, BuilderError) { + let document_empty = + string_builder.is_empty(result.unwrap(document, string_builder.new())) + use <- bool.guard(when: document_empty, return: Error(EmptyDocument)) + + result.unwrap(document, string_builder.new()) + |> string_builder.to_string + |> Ok +}