From ac88fb60eeeca3f3752948f6310e4ce3061db6eb Mon Sep 17 00:00:00 2001 From: Emii Tatsuo Date: Mon, 30 Nov 2020 01:11:12 -0500 Subject: [PATCH 1/2] Add a `blank_line()` method to `Builder` Many times users may want to seperate lines of text using a blank line. Currently, this can be accomplished by either adding '\n' to the previous `text()` call, which requires that the user has the ability to access this, and can also look a little messy, or by calling `text()` with an empty string, which definately works, but having an explicit method might be a nice sugar for a lot of users, and barely adds any weight to the codebase. This is definately a small thing, and almost closer to a personal preferance than anything, but I definately think it would make the library a tiny bit nicer to use, and there's barely any tradeoff. It's still up to you though if you'd rather keep your codebase small. --- gemtext/src/lib.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gemtext/src/lib.rs b/gemtext/src/lib.rs index e350b95..ae69e3d 100644 --- a/gemtext/src/lib.rs +++ b/gemtext/src/lib.rs @@ -18,6 +18,17 @@ impl Builder { self } + /// Append a single blank line to the document + /// + /// This is equivilent to calling [`text()`] with an empty string, or pushing a blank + /// [`Node`] + /// + /// [`text()`]: Self::text() + pub fn blank_line(mut self) -> Self { + self.nodes.push(Node::blank()); + self + } + pub fn link>(mut self, to: T, name: Option) -> Builder { self.nodes.push(Node::Link { to: to.into(), From adf82e9d9bd3b3bbbb67c1b33f1068239a209bde Mon Sep 17 00:00:00 2001 From: Emii Tatsuo Date: Mon, 30 Nov 2020 01:17:41 -0500 Subject: [PATCH 2/2] Add a doctest for the `blank_line()` method This adds a simple doctest for `blank_line()` but will not be included in the original PR because it is contingent on the merge of a pending PR for adding the `to_string()` method. --- gemtext/src/lib.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gemtext/src/lib.rs b/gemtext/src/lib.rs index c83a7bd..090f2f9 100644 --- a/gemtext/src/lib.rs +++ b/gemtext/src/lib.rs @@ -23,6 +23,17 @@ impl Builder { /// This is equivilent to calling [`text()`] with an empty string, or pushing a blank /// [`Node`] /// + /// ``` + /// # use gemtext::Builder; + /// let greeting = Builder::new() + /// .text("Hello") + /// .blank_line() + /// .text("universe") + /// .to_string(); + /// + /// assert_eq!(greeting.trim(), "Hello\n\nuniverse"); + /// ``` + /// /// [`text()`]: Self::text() pub fn blank_line(mut self) -> Self { self.nodes.push(Node::blank());