From dd2f66f2fe7ee687d8c0b7ca6e60ef7221223fb2 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 19 Jun 2026 23:04:37 -0700 Subject: Just cleaned up unsued functions. --- src/lib.rs | 53 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 15 deletions(-) (limited to 'src/lib.rs') 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 { } impl View { - fn process MappedStructure<'a>>(&self, input: &T) -> CrimResult { + fn process(&self, input: &dyn for<'a> MappedStructure<'a>) -> CrimResult { let mut out_vars = Context::new(); for output in &self.outputs { let mut buf = String::new(); let sc = StatefulContext::root( input ); - exec::( &sc, &output.code, &mut buf )?; + exec( &sc, &output.code, &mut buf )?; out_vars.insert( output.name.clone(), Value::String(buf) ); } Ok(out_vars) @@ -163,7 +163,7 @@ impl Crimtag { } } - pub fn render_partial MappedStructure<'a>>(&self, view: &str, input: &T ) -> CrimResult { + pub fn render_partial(&self, view: &str, input: &dyn for<'a> MappedStructure<'a> ) -> CrimResult { if let Some(view) = self.views.get(view) { return view.process( input ) } else { @@ -171,7 +171,7 @@ impl Crimtag { } } - pub fn render MappedStructure<'a>>(&self, view: &str, input: &T ) -> CrimResult { + pub fn render(&self, view: &str, input: &dyn for<'a> MappedStructure<'a> ) -> CrimResult { if let Some(view) = self.views.get( view ) { //println!("::Token tree::\n{:?}", view ); let mut output = view.process( input )?; @@ -193,19 +193,23 @@ impl Crimtag { } } -fn exec MappedStructure<'a>>(input: &StatefulContext, tokens: &Vec, buf: &mut String) -> CrimResult<()> { +fn exec<'a>(input: &StatefulContext<'a>, tokens: &Vec, buf: &mut String) -> CrimResult<()> { for token in tokens { match token { Token::Loop(ident,code) => { + //println!("!!! Loop over: {:?} {:?}", ident, input.get_value( &ident )); if let Some(value) = input.get_value( &ident ) && let MappedValue::List(list) = value { - list.for_each(&|rec: &MappedValue| { - if let MappedValue::Struct(d) = rec { - exec( &StatefulContext::root(d), code, buf )? - } - }); + let output = + &list.for_each(&|rec: &MappedValue, buf: &mut String| { + if let MappedValue::Struct(d) = rec { + exec( &input.local(*d), code, buf )?; + } + Ok(()) + })?; + //println!("!!! Output from loop: {}", output ); + buf.push_str( &output ); } - return Ok(()); } Token::If(ident,code,other) => { if let Some(value) = input.get_value( &ident ) && @@ -360,7 +364,7 @@ Now with explicit outputs: let mut ct = Crimtag::new(); ct.load_static(r#"Looping code: [|view "index"|>We will enumerate people here:[|loop people|> - - [|show last_name|], [|show first_name|][|if show_title |>: [|show title|] <|else|> **title redacted** <|if|] [|loop tags|> [|show tag|]<|loop|] <|loop|] + - [|show last_name|], [|show first_name|][|if show_title |>: [|show title|] <|else|> **title redacted** <|if|] ::>[|loop tags|> [|show tag|]<|loop|] <:: <|loop|] <|view|] "#)?; @@ -371,24 +375,40 @@ Now with explicit outputs: ("last_name".into(), "Smith".into()), ("show_title".into(), true.into()), ("title".into(), "CEO".into()), + ("tags".into(), vec![ + Context::from([("tag".into(), "jerk".into()),]).into(), + Context::from([("tag".into(), "ugly".into()),]).into(), + ].into()), ].into(), [ ("first_name".into(), "Chris".into()), ("last_name".into(), "Perkens".into()), ("show_title".into(), false.into()), ("title".into(), "Baconeer".into()), + ("tags".into(), vec![ + Context::from([("tag".into(), "jerk".into()),]).into(), + Context::from([("tag".into(), "ugly".into()),]).into(), + ].into()), ].into(), [ ("first_name".into(), "Will".into()), ("last_name".into(), "Power".into()), ("show_title".into(), false.into()), ("title".into(), "CFO".into()), + ("tags".into(), vec![ + Context::from([("tag".into(), "jerk".into()),]).into(), + Context::from([("tag".into(), "ugly".into()),]).into(), + ].into()), ].into(), [ ("first_name".into(), "Justin".into()), ("last_name".into(), "Time".into()), ("show_title".into(), true.into()), ("title".into(), "CIO".into()), + ("tags".into(), vec![ + Context::from([("tag".into(), "jerk".into()),]).into(), + Context::from([("tag".into(), "ugly".into()),]).into(), + ].into()), ].into(), ].into()), ]); @@ -513,10 +533,12 @@ Now with explicit outputs: } } - fn for_each(&'a self, func: &dyn Fn(&MappedValue<'a>)) { + fn for_each(&'a self, func: &dyn Fn(&MappedValue<'a>, &mut String) -> CrimResult<()>) -> CrimResult { + let mut buf = String::new(); for i in self { - func( &MappedValue::Struct(i) ); + func( &MappedValue::Struct(i), &mut buf )?; } + Ok(buf) } } @@ -529,10 +551,11 @@ Now with explicit outputs: ); if let Some(MappedValue::List(l)) = page.get_value(&"items") { - l.for_each(&|x: &MappedValue| { + l.for_each(&|x: &MappedValue, buf: &mut String| { if let MappedValue::Struct(s) = x { println!(" - {:?}", s.get_value(&"title")); } + Ok(()) }); } Ok(()) -- cgit v1.2.3