Skip to content

Commit

Permalink
only need to add options now
Browse files Browse the repository at this point in the history
  • Loading branch information
tovedetered committed Mar 13, 2024
1 parent 42a37be commit 379ffde
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/xmleam/xml_builder.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub type BuilderError {
EncodingEmpty
TagPlacedBeforeNew
InnerEmpty
EmptyDocument

NOTAPPLICABLE
}
Expand Down Expand Up @@ -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. <owner>
/// <email>[email protected]</email>
/// </owner>
///
/// Usage: |>block_tag("owner", {
/// new()
/// |> tag("email", "[email protected]")
/// })
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))
Expand Down Expand Up @@ -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
}

0 comments on commit 379ffde

Please sign in to comment.