Tholp's bespoke website generator

Ignore template redefinitions if on the same line

+25 -7
+2 -5
src/macros/simple_macros.rs
··· 19 19 _scope: &[Token], 20 20 ) -> Vec<Token> { 21 21 let t = Local::now(); 22 - let fmt = 23 - if args.len() == 0 { 22 + let fmt = if args.len() == 0 { 24 23 &"%+".to_string() // RFC-3339 25 - } 26 - else 27 - { 24 + } else { 28 25 &args[0] 29 26 }; 30 27
+23 -2
src/macros/template.rs
··· 15 15 16 16 pub has_scope: bool, 17 17 pub allows_trailing_args: bool, 18 + 19 + pub origin_index: usize, 20 + pub origin_line: usize, 18 21 } 19 22 20 23 impl SkidTemplate { 21 - pub fn new(name: String, args: &[String], tokens: &[Token]) -> SkidTemplate { 24 + pub fn new( 25 + name: String, 26 + args: &[String], 27 + tokens: &[Token], 28 + origin_index: usize, 29 + origin_line: usize, 30 + ) -> SkidTemplate { 22 31 let scoped: bool = find_pattern(&tokens, "[[{}]]".into()).is_some(); 23 32 let trailing: bool = find_pattern(&tokens, "[[..]]".into()).is_some() 24 33 || find_pattern(&tokens, "[[\"..\"]]".into()).is_some(); ··· 29 38 tokens: tokens.to_vec(), 30 39 has_scope: scoped, 31 40 allows_trailing_args: trailing, 41 + origin_index, 42 + origin_line, 32 43 } 33 44 } 34 45 pub fn expand( ··· 144 155 ) -> Vec<Token> { 145 156 for t in skid_context.templates.iter().as_ref() { 146 157 if t.symbol == args[0] { 158 + // If its the same file and line then we know its the same exact thing, just skip over it 159 + if t.origin_index == origin_index && t.origin_line == origin_line { 160 + return Vec::new(); 161 + } 147 162 error_skid( 148 163 project_context, 149 164 origin_index, ··· 241 256 ); 242 257 } 243 258 244 - let template = SkidTemplate::new(args[0].clone(), &args[1..], scope); 259 + let template = SkidTemplate::new( 260 + args[0].clone(), 261 + &args[1..], 262 + scope, 263 + origin_index, 264 + origin_line, 265 + ); 245 266 skid_context.templates.push(template); 246 267 247 268 return Vec::new();