summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index b0bc688..8c91686 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -65,7 +65,7 @@ enum Token {
65 Loop(Identifier, Vec<Token>), 65 Loop(Identifier, Vec<Token>),
66 Show(Identifier,Properties), 66 Show(Identifier,Properties),
67 If(Identifier, Vec<Token>), 67 If(Identifier, Vec<Token>),
68 ElseIf(Identifier, Vec<Token>), 68 ElIf(Identifier, Vec<Token>),
69 Else(Vec<Token>), 69 Else(Vec<Token>),
70 Text(String), 70 Text(String),
71} 71}
@@ -205,6 +205,14 @@ fn exec(input: &impl MappedStructure, tokens: &Vec<Token>, buf: &mut String) ->
205 } 205 }
206 } 206 }
207 } 207 }
208 Token::If(ident,code) => {
209 if let Some(value) = input.get_value( &ident ) &&
210 let Value::Bool(b) = value &&
211 b {
212
213 exec(input, code, buf)?
214 }
215 }
208 Token::Show(ident,p) => { 216 Token::Show(ident,p) => {
209 let format = if let Some(s) = p.get("format") { 217 let format = if let Some(s) = p.get("format") {
210 s 218 s
@@ -219,6 +227,13 @@ fn exec(input: &impl MappedStructure, tokens: &Vec<Token>, buf: &mut String) ->
219 Value::List(_) => { 227 Value::List(_) => {
220 buf.push_str("<list>"); 228 buf.push_str("<list>");
221 } 229 }
230 Value::Bool(b) => {
231 if b {
232 buf.push_str("true");
233 } else {
234 buf.push_str("false");
235 }
236 }
222 Value::String(s) => { 237 Value::String(s) => {
223 buf.push_str(s.as_str()); 238 buf.push_str(s.as_str());
224 } 239 }
@@ -313,7 +328,7 @@ Now with explicit outputs:
313 let mut ct = Crimtag::new(); 328 let mut ct = Crimtag::new();
314 if let Err(e) = ct.load_static(r#"Looping code: 329 if let Err(e) = ct.load_static(r#"Looping code:
315[|view "index"|>We will enumerate people here:[|loop people|> 330[|view "index"|>We will enumerate people here:[|loop people|>
316 - [|show last_name|], [|show first_name|]: [|show title|] [|loop tags|> [|show tag|]<|loop|] <|loop|] 331 - [|show last_name|], [|show first_name|][|if show_title |>: [|show title|] <|if|] [|loop tags|> [|show tag|]<|loop|] <|loop|]
317<|view|] 332<|view|]
318"#) { 333"#) {
319 println!("Error: {:?}", e ); 334 println!("Error: {:?}", e );
@@ -325,21 +340,25 @@ Now with explicit outputs:
325 [ 340 [
326 ("first_name".into(), "Joe".into()), 341 ("first_name".into(), "Joe".into()),
327 ("last_name".into(), "Smith".into()), 342 ("last_name".into(), "Smith".into()),
343 ("show_title".into(), true.into()),
328 ("title".into(), "CEO".into()), 344 ("title".into(), "CEO".into()),
329 ].into(), 345 ].into(),
330 [ 346 [
331 ("first_name".into(), "Chris".into()), 347 ("first_name".into(), "Chris".into()),
332 ("last_name".into(), "Perkens".into()), 348 ("last_name".into(), "Perkens".into()),
349 ("show_title".into(), false.into()),
333 ("title".into(), "Baconeer".into()), 350 ("title".into(), "Baconeer".into()),
334 ].into(), 351 ].into(),
335 [ 352 [
336 ("first_name".into(), "Will".into()), 353 ("first_name".into(), "Will".into()),
337 ("last_name".into(), "Power".into()), 354 ("last_name".into(), "Power".into()),
355 ("show_title".into(), false.into()),
338 ("title".into(), "CFO".into()), 356 ("title".into(), "CFO".into()),
339 ].into(), 357 ].into(),
340 [ 358 [
341 ("first_name".into(), "Justin".into()), 359 ("first_name".into(), "Justin".into()),
342 ("last_name".into(), "Time".into()), 360 ("last_name".into(), "Time".into()),
361 ("show_title".into(), true.into()),
343 ("title".into(), "CIO".into()), 362 ("title".into(), "CIO".into()),
344 ].into(), 363 ].into(),
345 ].into()), 364 ].into()),