Extract config text parsing into the type
This commit is contained in:
parent
0c2f9707cd
commit
99b9feeb95
3 changed files with 22 additions and 15 deletions
|
|
@ -2,7 +2,7 @@ use axum::{body::Body, extract::Path, http::Response};
|
|||
use crate::syntax::content::parsers::line::elements::paragraph::Paragraph;
|
||||
use crate::syntax::content;
|
||||
|
||||
use crate::syntax::content::parsers::word::elements::literal::Literal;
|
||||
use crate::syntax::content::parsers::compound::elements::literal::Literal;
|
||||
use crate::{formats::populate_graph, handlers, types::Node};
|
||||
|
||||
pub async fn node(Path(id): Path<String>) -> Response<Body> {
|
||||
|
|
@ -15,7 +15,7 @@ pub async fn node(Path(id): Path<String>) -> Response<Body> {
|
|||
context.insert("title", &node.title);
|
||||
context.insert("connections", &node.connections.clone());
|
||||
context.insert("incoming", &graph.incoming.get(&id));
|
||||
context.insert("config", &graph.meta.config);
|
||||
context.insert("config", &graph.meta.config.parse_text());
|
||||
|
||||
let out_text = content::parse::<Paragraph, Literal>(&node.text);
|
||||
context.insert("text", &out_text);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use crate::{
|
|||
self,
|
||||
parsers::{
|
||||
line::elements::{paragraph::Paragraph, span::Span},
|
||||
word::elements::literal::Literal,
|
||||
compound::elements::literal::Literal,
|
||||
},
|
||||
},
|
||||
types::{Config, Node},
|
||||
|
|
@ -27,18 +27,7 @@ pub async fn page(template: &str) -> Response<Body> {
|
|||
|
||||
context.insert("nodes", &nodes);
|
||||
context.insert("root_node", &root_node);
|
||||
|
||||
let text_parsed_config = Config {
|
||||
footer_text: content::parse::<Span, Literal>(
|
||||
&graph.meta.config.footer_text,
|
||||
),
|
||||
about_text: content::parse::<Paragraph, Literal>(
|
||||
&graph.meta.config.about_text,
|
||||
),
|
||||
..graph.meta.config
|
||||
};
|
||||
|
||||
context.insert("config", &text_parsed_config);
|
||||
context.insert("config", &graph.meta.config.parse_text());
|
||||
|
||||
handlers::template::by_filename(template, &context, 500, None, false)
|
||||
}
|
||||
|
|
|
|||
18
src/types.rs
18
src/types.rs
|
|
@ -2,6 +2,8 @@ use std::collections::HashMap;
|
|||
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use crate::syntax::content::parsers::{compound::elements::literal::Literal, line::elements::{paragraph::Paragraph, span::Span}};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Default, PartialEq, Eq, Debug)]
|
||||
pub struct Graph {
|
||||
pub nodes: HashMap<String, Node>,
|
||||
|
|
@ -149,3 +151,19 @@ impl Node {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
#[must_use]
|
||||
pub fn parse_text(self) -> Config {
|
||||
|
||||
Config {
|
||||
footer_text: crate::syntax::content::parse::<Span, Literal>(
|
||||
&self.footer_text,
|
||||
),
|
||||
about_text: crate::syntax::content::parse::<Paragraph, Literal>(
|
||||
&self.about_text,
|
||||
),
|
||||
..self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue