diff options
| author | Mike Buland <mike@xagasoft.com> | 2026-08-19 10:06:25 -0700 |
|---|---|---|
| committer | Mike Buland <mike@xagasoft.com> | 2026-08-19 10:06:25 -0700 |
| commit | 5602585e7afe431f25e68f30ac54761db2a710e5 (patch) | |
| tree | 94461a3d5eba1ce0a6402e2c07cdfc9facf21d76 /deepcrow/src/lib.rs | |
| parent | ba96bd8a4a1583edd3677dd613c89504d9ce88cf (diff) | |
| download | deepcrow-5602585e7afe431f25e68f30ac54761db2a710e5.tar.gz deepcrow-5602585e7afe431f25e68f30ac54761db2a710e5.tar.bz2 deepcrow-5602585e7afe431f25e68f30ac54761db2a710e5.tar.xz deepcrow-5602585e7afe431f25e68f30ac54761db2a710e5.zip | |
Renamed to DeepCrow
Diffstat (limited to '')
| -rw-r--r-- | deepcrow/src/lib.rs (renamed from crimtag/src/lib.rs) | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/crimtag/src/lib.rs b/deepcrow/src/lib.rs index 0fe0e4e..b10cd03 100644 --- a/crimtag/src/lib.rs +++ b/deepcrow/src/lib.rs | |||
| @@ -9,14 +9,14 @@ mod position; | |||
| 9 | mod error; | 9 | mod error; |
| 10 | pub mod context; | 10 | pub mod context; |
| 11 | 11 | ||
| 12 | pub use derive::CrimtagMappable; | 12 | pub use derive::DeepCrowMappable; |
| 13 | 13 | ||
| 14 | pub use error::{CrimError,CrimResult}; | 14 | pub use error::{DeepCrowError,Result}; |
| 15 | pub use position::*; | 15 | pub use position::*; |
| 16 | pub use context::{Context,Value,MappedStructure,StatefulContext,MappedValue,MappedList,MappedHash}; | 16 | pub use context::{Context,Value,MappedStructure,StatefulContext,MappedValue,MappedList,MappedHash}; |
| 17 | 17 | ||
| 18 | #[derive(Debug)] | 18 | #[derive(Debug)] |
| 19 | pub struct Crimtag { | 19 | pub struct DeepCrow { |
| 20 | views: HashMap<String, View>, | 20 | views: HashMap<String, View>, |
| 21 | sources: Vec<ViewSource>, | 21 | sources: Vec<ViewSource>, |
| 22 | } | 22 | } |
| @@ -43,7 +43,7 @@ struct View { | |||
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | impl View { | 45 | impl View { |
| 46 | fn process(&self, input: &dyn for<'a> MappedStructure<'a>) -> CrimResult<Context> { | 46 | fn process(&self, input: &dyn for<'a> MappedStructure<'a>) -> Result<Context> { |
| 47 | let mut out_vars = Context::new(); | 47 | let mut out_vars = Context::new(); |
| 48 | for output in &self.outputs { | 48 | for output in &self.outputs { |
| 49 | let mut buf = String::new(); | 49 | let mut buf = String::new(); |
| @@ -80,7 +80,7 @@ pub enum IdentifierValue { | |||
| 80 | 80 | ||
| 81 | pub type Identifier = Vec<IdentifierValue>; | 81 | pub type Identifier = Vec<IdentifierValue>; |
| 82 | 82 | ||
| 83 | impl Crimtag { | 83 | impl DeepCrow { |
| 84 | pub fn new() -> Self { | 84 | pub fn new() -> Self { |
| 85 | Self { | 85 | Self { |
| 86 | views: HashMap::new(), | 86 | views: HashMap::new(), |
| @@ -101,7 +101,7 @@ impl Crimtag { | |||
| 101 | idx | 101 | idx |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | pub fn load_file(&mut self, path: &Path) -> Result<(),Box::<dyn Error>> { | 104 | pub fn load_file(&mut self, path: &Path) -> std::result::Result<(),Box::<dyn Error>> { |
| 105 | let time = if let Ok(meta) = path.metadata() { | 105 | let time = if let Ok(meta) = path.metadata() { |
| 106 | if let Ok(t) = meta.modified() { | 106 | if let Ok(t) = meta.modified() { |
| 107 | t | 107 | t |
| @@ -129,13 +129,13 @@ impl Crimtag { | |||
| 129 | Ok(()) | 129 | Ok(()) |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | pub fn load_static(&mut self, data: &str) -> CrimResult<()> { | 132 | pub fn load_static(&mut self, data: &str) -> Result<()> { |
| 133 | let source_id = self.id_source( &ViewSource::Static ); | 133 | let source_id = self.id_source( &ViewSource::Static ); |
| 134 | let p = parser::Parser::new(); | 134 | let p = parser::Parser::new(); |
| 135 | self.register_views( p.parse( &data, source_id )? ) | 135 | self.register_views( p.parse( &data, source_id )? ) |
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | pub fn load_external(&mut self, key: &str, data: &str) -> CrimResult<()> { | 138 | pub fn load_external(&mut self, key: &str, data: &str) -> Result<()> { |
| 139 | let source_id = self.id_source( | 139 | let source_id = self.id_source( |
| 140 | &ViewSource::External{ key: key.to_string()} | 140 | &ViewSource::External{ key: key.to_string()} |
| 141 | ); | 141 | ); |
| @@ -146,7 +146,7 @@ impl Crimtag { | |||
| 146 | ) | 146 | ) |
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | fn register_views(&mut self, views: Vec<View>) -> CrimResult<()> { | 149 | fn register_views(&mut self, views: Vec<View>) -> Result<()> { |
| 150 | for view in views { | 150 | for view in views { |
| 151 | self.views.insert( view.name.clone(), view ); | 151 | self.views.insert( view.name.clone(), view ); |
| 152 | } | 152 | } |
| @@ -165,15 +165,15 @@ impl Crimtag { | |||
| 165 | } | 165 | } |
| 166 | } | 166 | } |
| 167 | 167 | ||
| 168 | pub fn render_partial(&self, view: &str, input: &dyn for<'a> MappedStructure<'a> ) -> CrimResult<Context> { | 168 | pub fn render_partial(&self, view: &str, input: &dyn for<'a> MappedStructure<'a> ) -> Result<Context> { |
| 169 | if let Some(view) = self.views.get(view) { | 169 | if let Some(view) = self.views.get(view) { |
| 170 | return view.process( input ) | 170 | return view.process( input ) |
| 171 | } else { | 171 | } else { |
| 172 | return Err(CrimError::other("No such view found".into())); | 172 | return Err(DeepCrowError::other("No such view found".into())); |
| 173 | } | 173 | } |
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | pub fn render(&self, view: &str, input: &dyn for<'a> MappedStructure<'a> ) -> CrimResult<String> { | 176 | pub fn render(&self, view: &str, input: &dyn for<'a> MappedStructure<'a> ) -> Result<String> { |
| 177 | if let Some(view) = self.views.get( view ) { | 177 | if let Some(view) = self.views.get( view ) { |
| 178 | //println!("::Token tree::\n{:?}", view ); | 178 | //println!("::Token tree::\n{:?}", view ); |
| 179 | let mut output = view.process( input )?; | 179 | let mut output = view.process( input )?; |
| @@ -185,17 +185,17 @@ impl Crimtag { | |||
| 185 | 185 | ||
| 186 | Ok(s) | 186 | Ok(s) |
| 187 | } else { | 187 | } else { |
| 188 | Err(CrimError::other("No content found in root layout.".into())) | 188 | Err(DeepCrowError::other("No content found in root layout.".into())) |
| 189 | } | 189 | } |
| 190 | } | 190 | } |
| 191 | 191 | ||
| 192 | } else { | 192 | } else { |
| 193 | Err(CrimError::other("No such view found".into())) | 193 | Err(DeepCrowError::other("No such view found".into())) |
| 194 | } | 194 | } |
| 195 | } | 195 | } |
| 196 | } | 196 | } |
| 197 | 197 | ||
| 198 | fn exec<'a>(input: &StatefulContext<'a>, tokens: &Vec<Token>, buf: &mut String) -> CrimResult<()> { | 198 | fn exec<'a>(input: &StatefulContext<'a>, tokens: &Vec<Token>, buf: &mut String) -> Result<()> { |
| 199 | for token in tokens { | 199 | for token in tokens { |
| 200 | match token { | 200 | match token { |
| 201 | Token::Loop(ident,code) => { | 201 | Token::Loop(ident,code) => { |
| @@ -320,7 +320,7 @@ mod tests { | |||
| 320 | 320 | ||
| 321 | #[test] | 321 | #[test] |
| 322 | fn parsing() { | 322 | fn parsing() { |
| 323 | let mut ct = Crimtag::new(); | 323 | let mut ct = DeepCrow::new(); |
| 324 | if let Err(e) = ct.load_static(r#"Here is a sample | 324 | if let Err(e) = ct.load_static(r#"Here is a sample |
| 325 | [|view "index" theme="standard"|><html><body>Hi</body></html><|view|] | 325 | [|view "index" theme="standard"|><html><body>Hi</body></html><|view|] |
| 326 | That was fun! now a placeholder: [|view "placeholder"|] and now one with an implicit [|view "simple"|>Body -> [|show content|] <- and end<|view|] aoeu | 326 | That was fun! now a placeholder: [|view "placeholder"|] and now one with an implicit [|view "simple"|>Body -> [|show content|] <- and end<|view|] aoeu |
| @@ -360,8 +360,8 @@ Now with explicit outputs: | |||
| 360 | } | 360 | } |
| 361 | 361 | ||
| 362 | #[test] | 362 | #[test] |
| 363 | fn loops() -> Result<(),CrimError> { | 363 | fn loops() -> Result<()> { |
| 364 | let mut ct = Crimtag::new(); | 364 | let mut ct = DeepCrow::new(); |
| 365 | ct.load_static(r#"Looping code: | 365 | ct.load_static(r#"Looping code: |
| 366 | [|view "index"|>We will enumerate people here:[|loop people|> | 366 | [|view "index"|>We will enumerate people here:[|loop people|> |
| 367 | - [|show last_name|], [|show first_name|][|if show_title |>: [|show title|] <|else|> **title redacted** <|if|] ::>[|loop tags|> [|show tag|]<|loop|] <:: <|loop|] | 367 | - [|show last_name|], [|show first_name|][|if show_title |>: [|show title|] <|else|> **title redacted** <|if|] ::>[|loop tags|> [|show tag|]<|loop|] <:: <|loop|] |
| @@ -419,8 +419,8 @@ Now with explicit outputs: | |||
| 419 | } | 419 | } |
| 420 | 420 | ||
| 421 | #[test] | 421 | #[test] |
| 422 | fn conditional() -> Result<(),CrimError> { | 422 | fn conditional() -> Result<()> { |
| 423 | let mut ct = Crimtag::new(); | 423 | let mut ct = DeepCrow::new(); |
| 424 | ct.load_static(r#"Hi there | 424 | ct.load_static(r#"Hi there |
| 425 | [|view "index"|> | 425 | [|view "index"|> |
| 426 | Color: [|if is_red|> red <|elif is_blue |> blue <|else|> green <|if|] | 426 | Color: [|if is_red|> red <|elif is_blue |> blue <|else|> green <|if|] |
| @@ -525,7 +525,7 @@ Now with explicit outputs: | |||
| 525 | } | 525 | } |
| 526 | 526 | ||
| 527 | #[test] | 527 | #[test] |
| 528 | fn custom() -> Result<(), CrimError> { | 528 | fn custom() -> Result<()> { |
| 529 | let page = Page::new(); | 529 | let page = Page::new(); |
| 530 | 530 | ||
| 531 | println!("{:?}", | 531 | println!("{:?}", |
