Skip to content

Commit

Permalink
accordion improve terminology
Browse files Browse the repository at this point in the history
  • Loading branch information
Lurk committed Nov 4, 2023
1 parent 03747db commit 462efe5
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/nodes/accordion_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ impl From<Code> for AccordionTabNodes {

#[derive(Debug, PartialEq, Serialize, Clone)]
pub struct AccordionTab {
pub header: Option<String>,
pub title: Option<String>,
pub nodes: Vec<AccordionTabNodes>,
}

impl AccordionTab {
pub fn new<S: Into<String>>(header: Option<S>, nodes: Vec<AccordionTabNodes>) -> Self {
pub fn new<S: Into<String>>(title: Option<S>, nodes: Vec<AccordionTabNodes>) -> Self {
Self {
nodes,
header: header.map(|s| s.into()),
title: title.map(|s| s.into()),
}
}
}
Expand All @@ -133,11 +133,11 @@ impl Display for AccordionTab {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"//\n{header}{nodes}\n\\\\",
header = self
.header
"//\n{title}{nodes}\n\\\\",
title = self
.title
.as_ref()
.map_or("".to_string(), |header| format!("/ {}\n", header)),
.map_or("".to_string(), |title| format!("/ {}\n", title)),
nodes = self
.nodes
.iter()
Expand Down Expand Up @@ -184,7 +184,7 @@ impl Branch<AccordionTabNodes> for AccordionTab {
}

fn get_outer_token_length(&self) -> usize {
6 + self.header.as_ref().map_or(0, |header| header.len() + 3)
6 + self.title.as_ref().map_or(0, |header| header.len() + 3)
}

fn is_empty(&self) -> bool {
Expand All @@ -197,11 +197,11 @@ impl Deserializer for AccordionTab {
let mut matcher = Matcher::new(input);
if let Some(tab) = matcher.get_match("//\n", "\n\\\\", false) {
let mut inner_matcher = Matcher::new(tab.body);
let header = inner_matcher
let title = inner_matcher
.get_match("/ ", "\n", false)
.map(|header| header.body);

return Self::parse_branch(inner_matcher.get_rest(), "\n\n", Self::new(header, vec![]));
return Self::parse_branch(inner_matcher.get_rest(), "\n\n", Self::new(title, vec![]));
}
None
}
Expand All @@ -227,9 +227,9 @@ mod cfg {
#[test]
fn test_accordion_tab_deserialize() {
assert_eq!(
AccordionTab::deserialize("//\n/ Header\n# Heading\n\\\\\n\n"),
AccordionTab::deserialize("//\n/ Title\n# Heading\n\\\\\n\n"),
Some(AccordionTab::new(
Some("Header"),
Some("Title"),
vec![Heading::new("Heading", 1).into()]
))
);
Expand Down Expand Up @@ -260,17 +260,17 @@ mod cfg {
#[test]
fn test_accordion_tab_len() {
assert_eq!(
AccordionTab::new(Some("Header"), vec![Heading::new("Heading", 1).into()]).len(),
24
AccordionTab::new(Some("Title"), vec![Heading::new("Heading", 1).into()]).len(),
23
);
assert_eq!(AccordionTab::new(Some("Header"), vec![]).len(), 15);
assert_eq!(AccordionTab::new(Some("Title"), vec![]).len(), 14);
}

#[test]
fn test_accordion_tab_serialize() {
assert_eq!(
AccordionTab::new(Some("Header"), vec![Heading::new("Heading", 1).into()]).to_string(),
"//\n/ Header\n# Heading\n\\\\"
AccordionTab::new(Some("Title"), vec![Heading::new("Heading", 1).into()]).to_string(),
"//\n/ Title\n# Heading\n\\\\"
);
}

Expand All @@ -282,7 +282,7 @@ mod cfg {
#[test]
fn with_all_nodes() {
let input = r#"//
/ Header
/ Title
# hello
```rust
Expand All @@ -308,7 +308,7 @@ t**b**
{{cloudinary_gallery|cloud_name&tag}}
\\"#;
let tab = AccordionTab::new(
Some("Header"),
Some("Title"),
vec![
Heading::new("hello", 1).into(),
Code::new("rust", "let a=1;").into(),
Expand Down

0 comments on commit 462efe5

Please sign in to comment.