Tholp's bespoke website generator
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

for_each_file_in_group, output_filename

Tholp 13a99e73 dd8618df

+293 -183
+5 -5
src/closures.rs
··· 5 5 use boa_engine::Context; 6 6 7 7 use crate::{ 8 - project::ProjectContext, 8 + project::Project, 9 9 types::{SkidContext, Token}, 10 10 }; 11 11 12 - type ClosureFunction = fn(&[Token], &mut ProjectContext, &mut SkidContext) -> Vec<Token>; 12 + type ClosureFunction = fn(&[Token], &mut Project, &mut SkidContext) -> Vec<Token>; 13 13 14 14 pub struct Closure { 15 15 pub opener: &'static str, ··· 55 55 56 56 fn closure_comment( 57 57 _tokens: &[Token], 58 - _project_context: &mut ProjectContext, 58 + _project_context: &mut Project, 59 59 _skid_context: &mut SkidContext, 60 60 ) -> Vec<Token> { 61 61 Vec::new() ··· 63 63 64 64 fn closure_section( 65 65 tokens: &[Token], 66 - _project_context: &mut ProjectContext, 66 + _project_context: &mut Project, 67 67 _skid_context: &mut SkidContext, 68 68 ) -> Vec<Token> { 69 69 tokens.to_vec() ··· 71 71 72 72 fn closure_js( 73 73 tokens: &[Token], 74 - project_context: &mut ProjectContext, 74 + project_context: &mut Project, 75 75 skid_context: &mut SkidContext, 76 76 ) -> Vec<Token> { 77 77 Vec::new()
+7 -7
src/console.rs
··· 2 2 3 3 use colored::Colorize; 4 4 5 - use crate::project::{Indexing, ProjectContext}; 5 + use crate::project::{Indexing, Project}; 6 6 7 7 pub fn error_generic(msg: &String) { 8 8 println!("{} {}", "[ERROR]".red(), msg); 9 9 exit(1); 10 10 } 11 11 12 - pub fn error_skid(context: &ProjectContext, origin_index: usize, origin_line: usize, msg: &String) { 12 + pub fn error_skid(proj_context: &Project, origin_index: usize, origin_line: usize, msg: &String) { 13 13 println!( 14 14 "{} {}:{}; {}", 15 15 "[ERROR]".red(), 16 - context 16 + proj_context 17 17 .file_for_index(origin_index) 18 18 .expect("Panic in the error func.... (file_for_index() was None!)") 19 19 .into_os_string() ··· 29 29 println!("{} {}", "[WARN]".yellow(), msg); 30 30 } 31 31 32 - pub fn warn_skid(context: &ProjectContext, origin_index: usize, origin_line: usize, msg: &String) { 32 + pub fn warn_skid(proj_context: &Project, origin_index: usize, origin_line: usize, msg: &String) { 33 33 println!( 34 34 "{} {}:{}; {}", 35 35 "[WARN]".yellow(), 36 - context 36 + proj_context 37 37 .file_for_index(origin_index) 38 38 .expect("Panic in the warn func.... (file_for_index() was None!)") 39 39 .into_os_string() ··· 49 49 } 50 50 51 51 pub fn reminder_skid( 52 - context: &ProjectContext, 52 + proj_context: &Project, 53 53 origin_index: usize, 54 54 origin_line: usize, 55 55 msg: &String, ··· 57 57 println!( 58 58 "{} {}:{}; {}", 59 59 "[REMINDER]".cyan(), 60 - context 60 + proj_context 61 61 .file_for_index(origin_index) 62 62 .expect("Panic in the warn func.... (file_for_index() was None!)") 63 63 .into_os_string()
+131
src/macros/for_each.rs
··· 1 + use crate::{console::*, project::Project, stringtools::*, types::*}; 2 + 3 + fn for_each_base( 4 + identifier: &String, 5 + replacements: &[String], 6 + proj_context: &mut Project, 7 + origin_index: usize, 8 + origin_line: usize, 9 + scope: &[Token], 10 + ) -> Vec<Token> { 11 + let mut output = Vec::new(); 12 + let block: Vec<Token> = scope.into(); 13 + 14 + let mut replacement_count: usize = 0; 15 + 16 + let mut replacement_pattern = find_pattern(scope, format!("[[{}..1]]", identifier)); 17 + 18 + if replacement_pattern.is_none() { 19 + warn_skid( 20 + proj_context, 21 + origin_index, 22 + origin_line, 23 + &format!( 24 + "Macro `for_each_arg` given block with no \"[[{}..1]]\", intentional?", 25 + identifier 26 + ), 27 + ); 28 + } 29 + 30 + while replacement_pattern.is_some() { 31 + replacement_count += 1; 32 + replacement_pattern = find_pattern( 33 + scope, 34 + format!("[[{}..{}]]", identifier, replacement_count + 1), 35 + ); 36 + } 37 + 38 + if replacement_count == 0 { 39 + for _i in 0..replacements.iter().count() { 40 + output.append(&mut block.clone()); 41 + } 42 + return output; 43 + } 44 + 45 + if replacements.len() % replacement_count != 0 { 46 + error_skid(proj_context, origin_index, origin_line, 47 + &format!("`for_each_var` was not given a number of arguments({}) that was a multiple of its replacement posistions({}) (got {:?})", 48 + replacements.len(), 49 + replacement_count, 50 + replacements)); 51 + } 52 + 53 + let mut replacement_index: usize = 0; 54 + let mut arg_output: Vec<Token> = block.clone(); 55 + for r in replacements { 56 + let mut found_pattern = find_pattern( 57 + &arg_output, 58 + format!("[[{}..{}]]", identifier, replacement_index + 1), 59 + ); 60 + 61 + while found_pattern.is_some() { 62 + let (start, len) = found_pattern.unwrap(); 63 + let replacement = split_to_tokens(r.clone(), origin_index); 64 + arg_output.splice(start..start + len, replacement); 65 + found_pattern = find_pattern( 66 + &arg_output, 67 + format!("[[{}..{}]]", identifier, replacement_index + 1), 68 + ); 69 + //println!("{}", replacement_index + 1); 70 + } 71 + 72 + //println!("{} {}", replacement_index, replacement_count); 73 + replacement_index += 1; 74 + if replacement_index == replacement_count { 75 + replacement_index = 0; 76 + output.append(&mut arg_output.trim_whitespace().into()); 77 + arg_output = block.clone(); 78 + //println!("push"); 79 + } 80 + //println!("test"); 81 + } 82 + return output; 83 + } 84 + 85 + pub fn macro_for_each_arg( 86 + origin_index: usize, 87 + origin_line: usize, 88 + proj_context: &mut Project, 89 + _skid_context: &mut SkidContext, 90 + args: &Vec<String>, 91 + scope: &[Token], 92 + ) -> Vec<Token> { 93 + return for_each_base( 94 + &args[0], 95 + &args[1..], 96 + proj_context, 97 + origin_index, 98 + origin_line, 99 + scope, 100 + ); 101 + } 102 + 103 + pub fn macro_for_each_file_in_group( 104 + origin_index: usize, 105 + origin_line: usize, 106 + proj_context: &mut Project, 107 + _skid_context: &mut SkidContext, 108 + args: &Vec<String>, 109 + scope: &[Token], 110 + ) -> Vec<Token> { 111 + let mut files: Vec<String> = Vec::new(); 112 + for g in &proj_context.filegroups { 113 + if g.name == args[1] { 114 + for f in &g.files { 115 + let path = f 116 + .file_input 117 + .strip_prefix(&proj_context.input_folder) 118 + .unwrap(); 119 + files.push(path.to_str().unwrap().into()); 120 + } 121 + } 122 + } 123 + return for_each_base( 124 + &args[0], 125 + &files, 126 + proj_context, 127 + origin_index, 128 + origin_line, 129 + scope, 130 + ); 131 + }
+2 -2
src/macros/insert.rs
··· 3 3 use crate::{ 4 4 console::error_skid, 5 5 macros::template::SkidTemplate, 6 - project::{Indexing, ProjectContext}, 6 + project::{Indexing, Project}, 7 7 stringtools::split_to_tokens, 8 8 types::{SkidContext, Token}, 9 9 }; ··· 11 11 pub fn macro_insert( 12 12 origin_index: usize, 13 13 origin_line: usize, 14 - context: &mut ProjectContext, 14 + context: &mut Project, 15 15 _skid_context: &mut SkidContext, 16 16 args: &Vec<String>, 17 17 _scope: &[Token],
+28 -14
src/macros/mod.rs
··· 1 + pub mod for_each; 1 2 pub mod insert; 2 3 pub mod simple_blocks; 3 4 pub mod simple_macros; 4 5 pub mod template; 5 - use crate::macros::simple_macros::macro_reminder; 6 6 7 7 use super::types::Macro; 8 - 8 + use for_each::*; 9 9 use insert::macro_insert; 10 - use simple_blocks::{macro_comment, macro_for_each_arg, macro_repeat, macro_section}; 11 - use simple_macros::{macro_filename, macro_filename_canonical, macro_time}; 10 + use simple_blocks::*; 11 + use simple_macros::*; 12 12 use template::macro_template; 13 13 14 14 pub static MACRO_LIST: &'static [Macro] = &[ ··· 16 16 Macro { 17 17 symbol: "insert", // Inserts another file 18 18 expansion: macro_insert, 19 - has_scope: false, 19 + takes_block: false, 20 20 min_args: 1, 21 21 max_args: 1, 22 22 }, 23 23 Macro { 24 24 symbol: "time", 25 25 expansion: macro_time, 26 - has_scope: false, 26 + takes_block: false, 27 27 min_args: 1, 28 28 max_args: 1, 29 29 }, 30 30 Macro { 31 31 symbol: "filename", 32 32 expansion: macro_filename, 33 - has_scope: false, 33 + takes_block: false, 34 34 min_args: 0, 35 35 max_args: 0, 36 36 }, 37 37 Macro { 38 38 symbol: "filename_canonical", 39 39 expansion: macro_filename_canonical, 40 - has_scope: false, 40 + takes_block: false, 41 41 min_args: 0, 42 42 max_args: 0, 43 43 }, 44 44 Macro { 45 45 symbol: "reminder", 46 46 expansion: macro_reminder, 47 - has_scope: false, 47 + takes_block: false, 48 48 min_args: 1, 49 49 max_args: 1, 50 50 }, 51 + Macro { 52 + symbol: "output_filename", 53 + expansion: macro_output_filename, 54 + takes_block: false, 55 + min_args: 0, 56 + max_args: 1, 57 + }, 51 58 // Scoped 52 59 Macro { 53 60 symbol: "comment", // Nothing 54 61 expansion: macro_comment, 55 - has_scope: true, 62 + takes_block: true, 56 63 min_args: 0, 57 64 max_args: 0, 58 65 }, 59 66 Macro { 60 67 symbol: "repeat", // Outputs what its give x number of times 61 68 expansion: macro_repeat, 62 - has_scope: true, 69 + takes_block: true, 63 70 min_args: 1, 64 71 max_args: 1, 65 72 }, 66 73 Macro { 67 74 symbol: "section", 68 75 expansion: macro_section, 69 - has_scope: true, 76 + takes_block: true, 70 77 min_args: 0, 71 78 max_args: 1, 72 79 }, 73 80 Macro { 74 81 symbol: "template", 75 82 expansion: macro_template, 76 - has_scope: true, 83 + takes_block: true, 77 84 min_args: 1, 78 85 max_args: usize::max_value(), 79 86 }, 80 87 Macro { 81 88 symbol: "for_each_arg", 82 89 expansion: macro_for_each_arg, 83 - has_scope: true, 90 + takes_block: true, 84 91 min_args: 1, 85 92 max_args: usize::max_value(), 93 + }, 94 + Macro { 95 + symbol: "for_each_file_in_group", 96 + expansion: macro_for_each_file_in_group, 97 + takes_block: true, 98 + min_args: 2, 99 + max_args: 2, 86 100 }, 87 101 ];
+6 -90
src/macros/simple_blocks.rs
··· 1 1 // This file for implementations of short blocks, im qualifying that as less than 30ish lines 2 - 3 2 use crate::{ 4 - console::{error_skid, warn_skid}, 5 - project::ProjectContext, 6 - stringtools::{find_pattern, split_to_tokens, TokenTools}, 3 + console::*, 4 + project::Project, 5 + stringtools::TokenTools, 7 6 types::{SkidContext, Token}, 8 7 }; 9 8 10 9 pub fn macro_comment( 11 10 _origin_index: usize, 12 11 _origin_line: usize, 13 - _context: &mut ProjectContext, 12 + _context: &mut Project, 14 13 _skid_context: &mut SkidContext, 15 14 _args: &Vec<String>, 16 15 _scope: &[Token], ··· 21 20 pub fn macro_section( 22 21 _origin_index: usize, 23 22 _origin_line: usize, 24 - _context: &mut ProjectContext, 23 + _context: &mut Project, 25 24 _skid_context: &mut SkidContext, 26 25 _args: &Vec<String>, 27 26 scope: &[Token], ··· 36 35 pub fn macro_repeat( 37 36 _origin_index: usize, 38 37 _origin_line: usize, 39 - _context: &mut ProjectContext, 38 + _context: &mut Project, 40 39 _skid_context: &mut SkidContext, 41 40 args: &Vec<String>, 42 41 scope: &[Token], ··· 54 53 } 55 54 return tokens; 56 55 } 57 - 58 - pub fn macro_for_each_arg( 59 - origin_index: usize, 60 - origin_line: usize, 61 - context: &mut ProjectContext, 62 - _skid_context: &mut SkidContext, 63 - args: &Vec<String>, 64 - scope: &[Token], 65 - ) -> Vec<Token> { 66 - let mut output = Vec::new(); 67 - let block: Vec<Token> = scope.into(); 68 - let varname = &args[0]; 69 - let real_args = &args[1..]; 70 - 71 - let mut replacement_count: usize = 0; 72 - 73 - let mut replacement_pattern = find_pattern(scope, format!("[[{}..1]]", varname)); 74 - 75 - if replacement_pattern.is_none() { 76 - warn_skid( 77 - context, 78 - origin_index, 79 - origin_line, 80 - &format!( 81 - "Macro `for_each_arg` given block with no \"[[{}..1]]\", intentional?", 82 - varname 83 - ), 84 - ); 85 - } 86 - 87 - while replacement_pattern.is_some() { 88 - replacement_count += 1; 89 - replacement_pattern = 90 - find_pattern(scope, format!("[[{}..{}]]", varname, replacement_count + 1)); 91 - } 92 - 93 - if replacement_count == 0 { 94 - for _i in 0..real_args.iter().count() { 95 - output.append(&mut block.clone()); 96 - } 97 - return output; 98 - } 99 - 100 - if real_args.len() % replacement_count != 0 { 101 - error_skid(context, origin_index, origin_line, 102 - &format!("`for_each_var` was not given a number of arguments({}) that was a multiple of its replacement posistions({}) (got {:?})", 103 - real_args.len(), 104 - replacement_count, 105 - real_args)); 106 - } 107 - 108 - let mut replacement_index: usize = 0; 109 - let mut arg_output: Vec<Token> = block.clone(); 110 - for arg in real_args { 111 - let mut found_pattern = find_pattern( 112 - &arg_output, 113 - format!("[[{}..{}]]", varname, replacement_index + 1), 114 - ); 115 - 116 - while found_pattern.is_some() { 117 - let (start, len) = found_pattern.unwrap(); 118 - let replacement = split_to_tokens(arg.clone(), origin_index); 119 - arg_output.splice(start..start + len, replacement); 120 - found_pattern = find_pattern( 121 - &arg_output, 122 - format!("[[{}..{}]]", varname, replacement_index + 1), 123 - ); 124 - //println!("{}", replacement_index + 1); 125 - } 126 - 127 - //println!("{} {}", replacement_index, replacement_count); 128 - replacement_index += 1; 129 - if replacement_index == replacement_count { 130 - replacement_index = 0; 131 - output.append(&mut arg_output.trim_whitespace().into()); 132 - arg_output = block.clone(); 133 - //println!("push"); 134 - } 135 - //println!("test"); 136 - } 137 - 138 - return output; 139 - }
+52 -9
src/macros/simple_macros.rs
··· 4 4 use chrono::Local; 5 5 6 6 use crate::{ 7 - console::{error_skid, reminder_skid}, 8 - macros::template::SkidTemplate, 9 - project::{Indexing, ProjectContext}, 7 + args, 8 + console::{error_skid, reminder_skid, warn_skid}, 9 + project::{Indexing, Project}, 10 10 stringtools::split_to_tokens, 11 11 types::{SkidContext, Token}, 12 12 }; ··· 14 14 pub fn macro_time( 15 15 origin_index: usize, 16 16 origin_line: usize, 17 - context: &mut ProjectContext, 17 + context: &mut Project, 18 18 _skid_context: &mut SkidContext, 19 19 args: &Vec<String>, 20 20 _scope: &[Token], ··· 40 40 41 41 pub fn macro_filename( 42 42 origin_index: usize, 43 - origin_line: usize, 44 - context: &mut ProjectContext, 43 + _origin_line: usize, 44 + proj_context: &mut Project, 45 45 _skid_context: &mut SkidContext, 46 46 _args: &Vec<String>, 47 47 _scope: &[Token], 48 48 ) -> Vec<Token> { 49 49 return split_to_tokens( 50 - context 50 + proj_context 51 51 .file_for_index(origin_index) 52 52 .unwrap() 53 53 .to_str() ··· 57 57 ); 58 58 } 59 59 60 + pub fn macro_output_filename( 61 + origin_index: usize, 62 + origin_line: usize, 63 + proj_context: &mut Project, 64 + _skid_context: &mut SkidContext, 65 + args: &Vec<String>, 66 + _scope: &[Token], 67 + ) -> Vec<Token> { 68 + let mut in_filepath = proj_context.input_folder.clone(); 69 + if args.len() == 0 { 70 + in_filepath.push(proj_context.file_for_index(origin_index).unwrap()); 71 + } else { 72 + in_filepath.push(&args[0]); 73 + } 74 + 75 + if in_filepath.exists() { 76 + for g in &proj_context.filegroups { 77 + if !g.process { 78 + continue; 79 + } 80 + for f in &g.files { 81 + if f.file_input == in_filepath { 82 + let stripped = f 83 + .file_out 84 + .strip_prefix(&proj_context.output_folder) 85 + .unwrap(); 86 + return split_to_tokens(stripped.to_str().unwrap().into(), origin_index); 87 + } 88 + } 89 + } 90 + } 91 + warn_skid( 92 + proj_context, 93 + origin_index, 94 + origin_line, 95 + &format!( 96 + "output_filename given a file with no matching output file ({:?}), returning empty", 97 + in_filepath 98 + ), 99 + ); 100 + Vec::new() 101 + } 102 + 60 103 pub fn macro_filename_canonical( 61 104 origin_index: usize, 62 105 _origin_line: usize, 63 - context: &mut ProjectContext, 106 + context: &mut Project, 64 107 _skid_context: &mut SkidContext, 65 108 _args: &Vec<String>, 66 109 _scope: &[Token], ··· 79 122 pub fn macro_reminder( 80 123 origin_index: usize, 81 124 origin_line: usize, 82 - context: &mut ProjectContext, 125 + context: &mut Project, 83 126 _skid_context: &mut SkidContext, 84 127 args: &Vec<String>, 85 128 _scope: &[Token],
+3 -3
src/macros/template.rs
··· 1 1 use crate::{ 2 2 console::error_skid, 3 - project::ProjectContext, 3 + project::Project, 4 4 reservednames::{RESERVED_NAMES_HTML, RESERVED_NAMES_MISC}, 5 5 stringtools::{find_pattern, split_to_tokens, WhitespaceChecks}, 6 6 types::{IsScoped, SkidContext, Token}, ··· 36 36 //_file: &mut InputFile, 37 37 origin_index: usize, 38 38 origin_line: usize, 39 - proj_context: &mut ProjectContext, 39 + proj_context: &mut Project, 40 40 args: &Vec<String>, 41 41 scope: &[Token], 42 42 ) -> Vec<Token> { ··· 137 137 pub fn macro_template( 138 138 origin_index: usize, 139 139 origin_line: usize, 140 - project_context: &mut ProjectContext, 140 + project_context: &mut Project, 141 141 skid_context: &mut SkidContext, 142 142 args: &Vec<String>, 143 143 scope: &[Token],
+23 -23
src/main.rs
··· 16 16 use console::*; 17 17 use macros::MACRO_LIST; 18 18 use markdown::{CompileOptions, Constructs, Options, ParseOptions}; 19 - use project::{parse_project, Indexing, ProjectContext}; 19 + use project::{parse_project, Indexing, Project}; 20 20 use reservednames::RESERVED_NAMES_HTML; 21 21 use std::{ 22 22 env, ··· 30 30 // strings split on kind of abitrary chars.. 31 31 static DELIMITERS: &'static [char] = &[ 32 32 ' ', '\n', '\t', '(', ')', '{', '}', '[', ']', '<', '>', '\\', '\'', '\"', ';', '?', '^', '-', 33 + '`', 33 34 ]; 34 35 35 36 #[derive(PartialEq)] ··· 75 76 // } 76 77 // } 77 78 78 - for group in &mut project.filegroups { 79 - if !group.process { 79 + for i in 0..project.filegroups.len() { 80 + if !project.filegroups[i].process { 80 81 continue; 81 82 } 82 - for infile in &mut group.files { 83 - let contents = 84 - fs::read_to_string(&infile.file_input).expect("File unreadable or missing"); 85 - let tokens = 86 - split_to_tokens(contents, project.context.index_of_file(&infile.file_input)); 83 + let convert_html = project.filegroups[i].convert_html; 84 + for k in 0..project.filegroups[i].files.len() { 85 + let file_input = project.filegroups[i].files[k].file_input.clone(); 86 + let contents = fs::read_to_string(&project.filegroups[i].files[k].file_input) 87 + .expect("File unreadable or missing"); 88 + let tokens = split_to_tokens(contents, project.index_of_file(&file_input)); 87 89 88 - let mut skid_context = 89 - SkidContext::new(project.context.index_of_file(&infile.file_input)); 90 + let mut skid_context = SkidContext::new(project.index_of_file(&file_input)); 90 91 write_file( 91 - infile, 92 - group.convert_html, 93 - &process_skid(&tokens, &mut project.context, &mut skid_context), 92 + &project.filegroups[i].files[k].file_skidout.clone(), 93 + &project.filegroups[i].files[k].file_out.clone(), 94 + convert_html, 95 + &process_skid(&tokens, &mut project, &mut skid_context), 94 96 ); 95 97 } 96 98 } ··· 98 100 99 101 fn find_and_run_macro( 100 102 tokens_in: &[Token], 101 - proj_context: &mut ProjectContext, 103 + proj_context: &mut Project, 102 104 skid_context: &mut SkidContext, 103 105 ) -> Option<(Vec<Token>, usize)> { 104 106 // (Output, to be consumed size) ··· 288 290 289 291 fn process_skid( 290 292 tokens_in: &[Token], 291 - proj_context: &mut ProjectContext, 293 + proj_context: &mut Project, 292 294 skid_context: &mut SkidContext, 293 295 ) -> Vec<Token> { 294 296 //}, context: &mut ProjectContext) { ··· 351 353 return tokens; 352 354 } 353 355 354 - fn write_file(file: &InputFile, convert_html: bool, tokens: &[Token]) { 356 + fn write_file(file_skidout: &PathBuf, file_out: &PathBuf, convert_html: bool, tokens: &[Token]) { 355 357 //println!("{:?}", tokens); 356 358 let mut skid_output: String = "".to_string(); 357 359 for t in tokens { 358 360 skid_output.push(t.contents); 359 361 } 360 362 361 - let mut folder = file.file_skidout.clone(); 363 + let mut folder = file_skidout.clone(); 362 364 folder.pop(); 363 365 if fs::create_dir_all(&folder).is_err() { 364 366 error_generic(&format!("Could not make the folder {:?}", &folder)); 365 367 } 366 368 367 369 if convert_html { 368 - fs::write(&file.file_skidout, &skid_output).expect("Couldn't write skid to file"); 370 + fs::write(&file_skidout, &skid_output).expect("Couldn't write skid to file"); 369 371 370 372 //let html_output = markdown::to_html(&skid_output); 371 373 let html_output = markdown::to_html_with_options( ··· 392 394 }, 393 395 ) 394 396 .unwrap(); 395 - fs::write(&file.file_out, &html_output).expect("Couldn't write output to file"); 397 + fs::write(&file_out, &html_output).expect("Couldn't write output to file"); 396 398 } else { 397 - fs::write(&file.file_out, &skid_output).expect("Couldn't write output to file"); 399 + fs::write(&file_out, &skid_output).expect("Couldn't write output to file"); 398 400 } 399 401 ok_generic(&format!( 400 402 "{} written", 401 - file.file_out 402 - .to_str() 403 - .unwrap_or("Couldnt Unwrap file_out name") 403 + file_out.to_str().unwrap_or("Couldnt Unwrap file_out name") 404 404 )); 405 405 }
+29 -23
src/project.rs
··· 8 8 pub struct Project { 9 9 pub filegroups: Vec<FileGroup>, 10 10 //pub settings: ProjectSettings, 11 - pub context: ProjectContext, 11 + //pub context: ProjectContext, 12 + pub input_folder: PathBuf, 13 + pub output_folder: PathBuf, 14 + pub global_pre_insert: PathBuf, 15 + pub global_post_insert: PathBuf, 16 + 17 + pub filemap: Vec<PathBuf>, // mapped to index 12 18 } 13 19 14 20 pub struct FileGroup { ··· 20 26 pub convert_html: bool, 21 27 } 22 28 23 - pub struct ProjectContext { 24 - pub input_folder: PathBuf, 25 - pub output_folder: PathBuf, 26 - pub global_pre_insert: PathBuf, 27 - pub global_post_insert: PathBuf, 29 + // pub struct ProjectContext { 30 + // pub input_folder: PathBuf, 31 + // pub output_folder: PathBuf, 32 + // pub global_pre_insert: PathBuf, 33 + // pub global_post_insert: PathBuf, 28 34 29 - pub filemap: Vec<PathBuf>, // mapped to index 30 - } 35 + // pub filemap: Vec<PathBuf>, // mapped to index 36 + // } 31 37 32 38 macro_rules! get_table_bool_or_default { 33 39 ($table:ident, $key:expr, $default:expr) => { ··· 59 65 60 66 let mut project: Project = Project { 61 67 filegroups: Vec::new(), 62 - context: ProjectContext { 63 - input_folder: PathBuf::new(), 64 - output_folder: PathBuf::new(), 65 - global_pre_insert: PathBuf::new(), 66 - global_post_insert: PathBuf::new(), 67 - filemap: Vec::new(), 68 - }, 68 + //context: ProjectContext { 69 + input_folder: PathBuf::new(), 70 + output_folder: PathBuf::new(), 71 + global_pre_insert: PathBuf::new(), 72 + global_post_insert: PathBuf::new(), 73 + filemap: Vec::new(), 74 + //}, 69 75 }; 70 76 let config = tomlfile 71 77 .parse::<Table>() ··· 81 87 .parent() 82 88 .expect("Project file unreadable or missing."); 83 89 84 - project.context.input_folder = PathBuf::from(get_table_string_or_default!( 90 + project.input_folder = PathBuf::from(get_table_string_or_default!( 85 91 settings_section, 86 92 "inputFolder", 87 93 "skid" 88 94 )); 89 95 90 - project.context.output_folder = PathBuf::from(get_table_string_or_default!( 96 + project.output_folder = PathBuf::from(get_table_string_or_default!( 91 97 settings_section, 92 98 "outputFolder", 93 99 "content" 94 100 )); 95 101 96 - project.context.global_pre_insert = project_root.join(get_table_string_or_default!( 102 + project.global_pre_insert = project_root.join(get_table_string_or_default!( 97 103 settings_section, 98 104 "preInsertGlobal", 99 105 "" 100 106 )); 101 - project.context.global_post_insert = project_root.join(get_table_string_or_default!( 107 + project.global_post_insert = project_root.join(get_table_string_or_default!( 102 108 settings_section, 103 109 "postInsertGlobal", 104 110 "" ··· 112 118 113 119 let pre_insert = get_table_string_or_default!(filegroup_def, "preInsert", ""); 114 120 let post_insert = get_table_string_or_default!(filegroup_def, "postInsert", ""); 115 - let process = get_table_bool_or_default!(filegroup_def, "process", false); 121 + let process = get_table_bool_or_default!(filegroup_def, "process", true); 116 122 let convert_html = get_table_bool_or_default!(filegroup_def, "convertHTML", true); 117 123 let extention = get_table_string_or_default!(filegroup_def, "outputExtention", "html"); 118 124 ··· 142 148 }); 143 149 144 150 let mut new_file = crate::types::InputFile::new(); 145 - new_file.file_input = project.context.input_folder.clone(); 151 + new_file.file_input = project.input_folder.clone(); 146 152 new_file.file_input.push(filename); 147 153 148 - new_file.file_out = project.context.output_folder.clone(); 154 + new_file.file_out = project.output_folder.clone(); 149 155 new_file.file_out.push(filename); 150 156 new_file.file_out.set_extension(extention); 151 157 ··· 171 177 // fn section_name_for_index(&self, index: usize) -> String; 172 178 } 173 179 174 - impl Indexing for ProjectContext { 180 + impl Indexing for Project { 175 181 fn index_of_file(&mut self, f: &PathBuf) -> usize { 176 182 let cannonical = f.canonicalize().unwrap(); 177 183 let mut index = 0;
+7 -7
src/types.rs
··· 3 3 use crate::{ 4 4 console::error_skid, 5 5 macros::{simple_blocks::macro_comment, template::SkidTemplate}, 6 - project::ProjectContext, 6 + project::Project, 7 7 }; 8 8 9 9 pub struct Token { ··· 42 42 } 43 43 44 44 type MacroExpansion = 45 - fn(usize, usize, &mut ProjectContext, &mut SkidContext, &Vec<String>, &[Token]) -> Vec<Token>; 45 + fn(usize, usize, &mut Project, &mut SkidContext, &Vec<String>, &[Token]) -> Vec<Token>; 46 46 // ( 47 47 // origin_index: usize, 48 48 // origin_line: usize, ··· 55 55 pub struct Macro { 56 56 pub symbol: &'static str, 57 57 pub expansion: MacroExpansion, 58 - pub has_scope: bool, //takes blocks of text input as well as parameters using [[{}]] 58 + pub takes_block: bool, //takes blocks of text input as well as parameters using [[{}]] 59 59 pub min_args: usize, 60 60 pub max_args: usize, 61 61 } ··· 65 65 &self, 66 66 origin_index: usize, 67 67 origin_line: usize, 68 - context: &mut ProjectContext, 68 + context: &mut Project, 69 69 skid_context: &mut SkidContext, 70 70 args: &Vec<String>, 71 71 scope: &[Token], ··· 81 81 Macro { 82 82 symbol: "default_symbol", 83 83 expansion: macro_comment, 84 - has_scope: true, 84 + takes_block: true, 85 85 min_args: 0, 86 86 max_args: usize::max_value(), 87 87 } ··· 93 93 &self, 94 94 origin_index: usize, 95 95 origin_line: usize, 96 - proj_context: &mut ProjectContext, 96 + proj_context: &mut Project, 97 97 skid_context: &mut SkidContext, 98 98 args: &Vec<String>, 99 99 block: &[Token], ··· 117 117 118 118 impl IsScoped for Macro { 119 119 fn is_scoped(&self) -> bool { 120 - self.has_scope 120 + self.takes_block 121 121 } 122 122 } 123 123