Tholp's bespoke website generator

add !time macro, uses rust chorno formatting https://docs.rs/chrono/latest/chrono/format/strftime/index.html#specifiers

Tholp1 b7afa10e 7e4e57e9

+61 -22
+3 -1
Cargo.toml
··· 4 4 edition = "2021" 5 5 6 6 [dependencies] 7 + chrono = "0.4.41" 7 8 glob = "0.3.2" 8 - markdown = "1.0.0-alpha.21" 9 + markdown = "1.0.0" 10 + # markdown = {path = "/home/tholp/Desktop/Code/libs/markdown-rs"} 9 11 serde = "1.0.218" 10 12 toml = "0.8.19"
-18
src/macros/clear.rs
··· 1 - use crate::{ 2 - projectparse::ProjectContext, 3 - stringtools::{split_keep_delimiters, strings_to_tokens}, 4 - types::{InputFile, Token}, 5 - }; 6 - 7 - pub fn macro_clear( 8 - _file: &mut InputFile, 9 - _origin_index: usize, 10 - _origin_line: usize, 11 - _context: &mut ProjectContext, 12 - _args: &Vec<String>, 13 - _scope: &[Token], 14 - ) -> Vec<Token> { 15 - _file.tokens = _file.tokens.split_off(_file.working_index); 16 - _file.working_index = 0; 17 - return Vec::new(); 18 - }
+8 -3
src/macros/mod.rs
··· 1 - pub mod clear; 1 + pub mod simple_macros; 2 2 pub mod insert; 3 3 pub mod simple_blocks; 4 4 pub mod template; 5 5 use super::types::Macro; 6 6 7 - use clear::macro_clear; 7 + use simple_macros::{macro_clear, macro_time}; 8 8 use insert::macro_insert; 9 9 use simple_blocks::{macro_comment, macro_null, macro_repeat}; 10 10 use template::macro_template; 11 11 12 - pub static MACRO_LIST: [Macro<'_>; 6] = [ 12 + pub static MACRO_LIST: [Macro<'_>; 7] = [ 13 13 // Unscoped 14 14 Macro { 15 15 symbol: "insert", // Inserts another file ··· 20 20 symbol: "clear", // Clears text buffer 21 21 expand: macro_clear, 22 22 has_scope: false, 23 + }, 24 + Macro { 25 + symbol: "time", 26 + expand: macro_time, 27 + has_scope:false, 23 28 }, 24 29 // Scoped 25 30 Macro {
+50
src/macros/simple_macros.rs
··· 1 + use std::process::exit; 2 + 3 + use chrono::{DateTime, Local}; 4 + 5 + use crate::{ 6 + projectparse::{FileIndexing, ProjectContext}, 7 + stringtools::split_to_tokens, 8 + types::{InputFile, Token}, 9 + }; 10 + 11 + pub fn macro_clear( 12 + _file: &mut InputFile, 13 + _origin_index: usize, 14 + _origin_line: usize, 15 + _context: &mut ProjectContext, 16 + _args: &Vec<String>, 17 + _scope: &[Token], 18 + ) -> Vec<Token> { 19 + _file.tokens = _file.tokens.split_off(_file.working_index); 20 + _file.working_index = 0; 21 + return Vec::new(); 22 + } 23 + 24 + pub fn macro_time( 25 + file: &mut InputFile, 26 + origin_index: usize, 27 + origin_line: usize, 28 + context: &mut ProjectContext, 29 + args: &Vec<String>, 30 + _scope: &[Token], 31 + ) -> Vec<Token> { 32 + let t = Local::now(); 33 + 34 + if args.len() != 1 { 35 + let origin_file = context 36 + .file_for_index(origin_index) 37 + .expect("Macro 'Time' was given a bad origin index") 38 + .clone(); 39 + println!( 40 + "{:?}:{} ;Time only accepts 1 argument, got given {} ({:?})", 41 + origin_file.to_str(), 42 + origin_line, 43 + args.len(), 44 + args 45 + ); 46 + exit(1); 47 + } 48 + 49 + return split_to_tokens(t.format(&args[0]).to_string(), origin_index); 50 + }