summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorMike Buland <mike@xagasoft.com>2026-06-19 23:04:37 -0700
committerMike Buland <mike@xagasoft.com>2026-06-19 23:04:37 -0700
commitdd2f66f2fe7ee687d8c0b7ca6e60ef7221223fb2 (patch)
tree8efe8bb68e08c9462b2a5641bdc970df5362fc9f /src/lib.rs
parent977c35eaebb39e6ae33661fc8ac8537adfbeceff (diff)
downloadcrimtag-dd2f66f2fe7ee687d8c0b7ca6e60ef7221223fb2.tar.gz
crimtag-dd2f66f2fe7ee687d8c0b7ca6e60ef7221223fb2.tar.bz2
crimtag-dd2f66f2fe7ee687d8c0b7ca6e60ef7221223fb2.tar.xz
crimtag-dd2f66f2fe7ee687d8c0b7ca6e60ef7221223fb2.zip
Just cleaned up unsued functions.
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs53
1 files changed, 38 insertions, 15 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 95462b4..9867615 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -41,12 +41,12 @@ struct View {
41} 41}
42 42
43impl View { 43impl View {
44 fn process<T: for<'a> MappedStructure<'a>>(&self, input: &T) -> CrimResult<Context> { 44 fn process(&self, input: &dyn for<'a> MappedStructure<'a>) -> CrimResult<Context> {
45 let mut out_vars = Context::new(); 45 let mut out_vars = Context::new();
46 for output in &self.outputs { 46 for output in &self.outputs {
47 let mut buf = String::new(); 47 let mut buf = String::new();
48 let sc = StatefulContext::root( input ); 48 let sc = StatefulContext::root( input );
49 exec::<T>( &sc, &output.code, &mut buf )?; 49 exec( &sc, &output.code, &mut buf )?;
50 out_vars.insert( output.name.clone(), Value::String(buf) ); 50 out_vars.insert( output.name.clone(), Value::String(buf) );
51 } 51 }
52 Ok(out_vars) 52 Ok(out_vars)
@@ -163,7 +163,7 @@ impl Crimtag {
163 } 163 }
164 } 164 }
165 165
166 pub fn render_partial<T: for<'a> MappedStructure<'a>>(&self, view: &str, input: &T ) -> CrimResult<Context> { 166 pub fn render_partial(&self, view: &str, input: &dyn for<'a> MappedStructure<'a> ) -> CrimResult<Context> {
167 if let Some(view) = self.views.get(view) { 167 if let Some(view) = self.views.get(view) {
168 return view.process( input ) 168 return view.process( input )
169 } else { 169 } else {
@@ -171,7 +171,7 @@ impl Crimtag {
171 } 171 }
172 } 172 }
173 173
174 pub fn render<T: for<'a> MappedStructure<'a>>(&self, view: &str, input: &T ) -> CrimResult<String> { 174 pub fn render(&self, view: &str, input: &dyn for<'a> MappedStructure<'a> ) -> CrimResult<String> {
175 if let Some(view) = self.views.get( view ) { 175 if let Some(view) = self.views.get( view ) {
176 //println!("::Token tree::\n{:?}", view ); 176 //println!("::Token tree::\n{:?}", view );
177 let mut output = view.process( input )?; 177 let mut output = view.process( input )?;
@@ -193,19 +193,23 @@ impl Crimtag {
193 } 193 }
194} 194}
195 195
196fn exec<T: for<'a> MappedStructure<'a>>(input: &StatefulContext<T>, tokens: &Vec<Token>, buf: &mut String) -> CrimResult<()> { 196fn exec<'a>(input: &StatefulContext<'a>, tokens: &Vec<Token>, buf: &mut String) -> CrimResult<()> {
197 for token in tokens { 197 for token in tokens {
198 match token { 198 match token {
199 Token::Loop(ident,code) => { 199 Token::Loop(ident,code) => {
200 //println!("!!! Loop over: {:?} {:?}", ident, input.get_value( &ident ));
200 if let Some(value) = input.get_value( &ident ) && 201 if let Some(value) = input.get_value( &ident ) &&
201 let MappedValue::List(list) = value { 202 let MappedValue::List(list) = value {
202 list.for_each(&|rec: &MappedValue| { 203 let output =
203 if let MappedValue::Struct(d) = rec { 204 &list.for_each(&|rec: &MappedValue, buf: &mut String| {
204 exec( &StatefulContext::root(d), code, buf )? 205 if let MappedValue::Struct(d) = rec {
205 } 206 exec( &input.local(*d), code, buf )?;
206 }); 207 }
208 Ok(())
209 })?;
210 //println!("!!! Output from loop: {}", output );
211 buf.push_str( &output );
207 } 212 }
208 return Ok(());
209 } 213 }
210 Token::If(ident,code,other) => { 214 Token::If(ident,code,other) => {
211 if let Some(value) = input.get_value( &ident ) && 215 if let Some(value) = input.get_value( &ident ) &&
@@ -360,7 +364,7 @@ Now with explicit outputs:
360 let mut ct = Crimtag::new(); 364 let mut ct = Crimtag::new();
361 ct.load_static(r#"Looping code: 365 ct.load_static(r#"Looping code:
362[|view "index"|>We will enumerate people here:[|loop people|> 366[|view "index"|>We will enumerate people here:[|loop people|>
363 - [|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|]
364<|view|] 368<|view|]
365"#)?; 369"#)?;
366 370
@@ -371,24 +375,40 @@ Now with explicit outputs:
371 ("last_name".into(), "Smith".into()), 375 ("last_name".into(), "Smith".into()),
372 ("show_title".into(), true.into()), 376 ("show_title".into(), true.into()),
373 ("title".into(), "CEO".into()), 377 ("title".into(), "CEO".into()),
378 ("tags".into(), vec![
379 Context::from([("tag".into(), "jerk".into()),]).into(),
380 Context::from([("tag".into(), "ugly".into()),]).into(),
381 ].into()),
374 ].into(), 382 ].into(),
375 [ 383 [
376 ("first_name".into(), "Chris".into()), 384 ("first_name".into(), "Chris".into()),
377 ("last_name".into(), "Perkens".into()), 385 ("last_name".into(), "Perkens".into()),
378 ("show_title".into(), false.into()), 386 ("show_title".into(), false.into()),
379 ("title".into(), "Baconeer".into()), 387 ("title".into(), "Baconeer".into()),
388 ("tags".into(), vec![
389 Context::from([("tag".into(), "jerk".into()),]).into(),
390 Context::from([("tag".into(), "ugly".into()),]).into(),
391 ].into()),
380 ].into(), 392 ].into(),
381 [ 393 [
382 ("first_name".into(), "Will".into()), 394 ("first_name".into(), "Will".into()),
383 ("last_name".into(), "Power".into()), 395 ("last_name".into(), "Power".into()),
384 ("show_title".into(), false.into()), 396 ("show_title".into(), false.into()),
385 ("title".into(), "CFO".into()), 397 ("title".into(), "CFO".into()),
398 ("tags".into(), vec![
399 Context::from([("tag".into(), "jerk".into()),]).into(),
400 Context::from([("tag".into(), "ugly".into()),]).into(),
401 ].into()),
386 ].into(), 402 ].into(),
387 [ 403 [
388 ("first_name".into(), "Justin".into()), 404 ("first_name".into(), "Justin".into()),
389 ("last_name".into(), "Time".into()), 405 ("last_name".into(), "Time".into()),
390 ("show_title".into(), true.into()), 406 ("show_title".into(), true.into()),
391 ("title".into(), "CIO".into()), 407 ("title".into(), "CIO".into()),
408 ("tags".into(), vec![
409 Context::from([("tag".into(), "jerk".into()),]).into(),
410 Context::from([("tag".into(), "ugly".into()),]).into(),
411 ].into()),
392 ].into(), 412 ].into(),
393 ].into()), 413 ].into()),
394 ]); 414 ]);
@@ -513,10 +533,12 @@ Now with explicit outputs:
513 } 533 }
514 } 534 }
515 535
516 fn for_each(&'a self, func: &dyn Fn(&MappedValue<'a>)) { 536 fn for_each(&'a self, func: &dyn Fn(&MappedValue<'a>, &mut String) -> CrimResult<()>) -> CrimResult<String> {
537 let mut buf = String::new();
517 for i in self { 538 for i in self {
518 func( &MappedValue::Struct(i) ); 539 func( &MappedValue::Struct(i), &mut buf )?;
519 } 540 }
541 Ok(buf)
520 } 542 }
521 } 543 }
522 544
@@ -529,10 +551,11 @@ Now with explicit outputs:
529 ); 551 );
530 552
531 if let Some(MappedValue::List(l)) = page.get_value(&"items") { 553 if let Some(MappedValue::List(l)) = page.get_value(&"items") {
532 l.for_each(&|x: &MappedValue| { 554 l.for_each(&|x: &MappedValue, buf: &mut String| {
533 if let MappedValue::Struct(s) = x { 555 if let MappedValue::Struct(s) = x {
534 println!(" - {:?}", s.get_value(&"title")); 556 println!(" - {:?}", s.get_value(&"title"));
535 } 557 }
558 Ok(())
536 }); 559 });
537 } 560 }
538 Ok(()) 561 Ok(())