Tholp's bespoke website generator

Ignore template redefinitions if on the same line

Changed files
+25 -7
src
+2 -5
src/macros/simple_macros.rs
···
_scope: &[Token],
) -> Vec<Token> {
let t = Local::now();
-
let fmt =
-
if args.len() == 0 {
+
let fmt = if args.len() == 0 {
&"%+".to_string() // RFC-3339
-
}
-
else
-
{
+
} else {
&args[0]
};
+23 -2
src/macros/template.rs
···
pub has_scope: bool,
pub allows_trailing_args: bool,
+
+
pub origin_index: usize,
+
pub origin_line: usize,
}
impl SkidTemplate {
-
pub fn new(name: String, args: &[String], tokens: &[Token]) -> SkidTemplate {
+
pub fn new(
+
name: String,
+
args: &[String],
+
tokens: &[Token],
+
origin_index: usize,
+
origin_line: usize,
+
) -> SkidTemplate {
let scoped: bool = find_pattern(&tokens, "[[{}]]".into()).is_some();
let trailing: bool = find_pattern(&tokens, "[[..]]".into()).is_some()
|| find_pattern(&tokens, "[[\"..\"]]".into()).is_some();
···
tokens: tokens.to_vec(),
has_scope: scoped,
allows_trailing_args: trailing,
+
origin_index,
+
origin_line,
}
}
pub fn expand(
···
) -> Vec<Token> {
for t in skid_context.templates.iter().as_ref() {
if t.symbol == args[0] {
+
// If its the same file and line then we know its the same exact thing, just skip over it
+
if t.origin_index == origin_index && t.origin_line == origin_line {
+
return Vec::new();
+
}
error_skid(
project_context,
origin_index,
···
);
}
-
let template = SkidTemplate::new(args[0].clone(), &args[1..], scope);
+
let template = SkidTemplate::new(
+
args[0].clone(),
+
&args[1..],
+
scope,
+
origin_index,
+
origin_line,
+
);
skid_context.templates.push(template);
return Vec::new();