Skip to content

Commit

Permalink
Remove output_comment in stub (since it is stored in write commands)
Browse files Browse the repository at this point in the history
  • Loading branch information
daxida committed Mar 19, 2024
1 parent 1bbc513 commit 6ea6652
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/stub/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl<'a, I: Iterator<Item = &'a str>> Parser<I> {

#[rustfmt::skip]
fn parse(&mut self) -> Stub {
let mut stub = Stub::new();
let mut stub = Stub::default();

while let Some(token) = self.stream.next() {
match token {
Expand Down
10 changes: 1 addition & 9 deletions src/stub/parser/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,17 @@ use serde::Serialize;
#[derive(Clone, Default)]
pub struct Stub {
pub commands: Vec<Cmd>,
pub output_comment: String,
pub statement: String,
}

// More visual than derive(Debug)
impl std::fmt::Debug for Stub {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Stub {{\n commands: [")?;

// Print commands recursively
for command in &self.commands {
write!(f, "\n {:?}", command)?;
}

write!(
f,
"\n ],\n output_comment: {:?},\n statement: {:?}\n}}",
self.output_comment, self.statement
)
write!(f, "\n ],\n statement: {:?}\n}}", self.statement)
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/stub/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct Renderer {
}

impl Renderer {
fn new(lang: Language, mut stub: Stub, debug_mode: bool) -> Result<Renderer> {
fn new(lang: Language, stub: Stub, debug_mode: bool) -> Result<Renderer> {
let tera = Tera::new(&lang.template_glob())?;

Ok(Self {
Expand Down Expand Up @@ -90,8 +90,8 @@ impl Renderer {

fn render_write(&self, text: &str, output_comment: &str) -> String {
let mut context = Context::new();
let output_comments: Vec<&str> = output_comment.lines().map(|msg| msg.trim_end()).collect();
let messages: Vec<&str> = text.lines().map(|msg| msg.trim_end()).collect();
let output_comments: Vec<&str> = output_comment.lines().collect();
let messages: Vec<&str> = text.lines().collect();

context.insert("messages", &messages);
context.insert("output_comments", &output_comments);
Expand All @@ -101,7 +101,7 @@ impl Renderer {

fn render_write_join(&self, terms: &[JoinTerm], output_comment: &str) -> String {
let mut context = Context::new();
let output_comments: Vec<&str> = output_comment.lines().map(|msg| msg.trim_end()).collect();
let output_comments: Vec<&str> = output_comment.lines().collect();
let terms: Vec<JoinTerm> = terms
.iter()
.cloned()
Expand Down

0 comments on commit 6ea6652

Please sign in to comment.