-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
42a37be
commit 379ffde
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. <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)) | ||
|
@@ -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 | ||
} |