neutralts/bif/
parse_bif_fetch.rs1#![doc = include_str!("../../doc/bif-fetch.md")]
2
3use crate::{bif::constants::*, bif::Bif, bif::BifError, constants::*};
4
5impl<'a> Bif<'a> {
6 pub(crate) fn parse_bif_fetch(&mut self) -> Result<(), BifError> {
10 if self.mod_filter || self.mod_negate || self.mod_scope {
11 return Err(self.bif_error(BIF_ERROR_MODIFIER_NOT_ALLOWED));
12 }
13
14 self.extract_params_code(true);
15
16 if !self.flags.is_empty() {
17 return Err(self.bif_error(BIF_ERROR_FLAGS_NOT_ALLOWED));
18 }
19
20 let args = self.extract_args();
21
22 let url = args
23 .get(1)
24 .cloned()
25 .ok_or_else(|| self.bif_error(BIF_ERROR_ARGUMENTS_NOT_FOUND))?;
26
27 let event = args.get(2).cloned().unwrap_or("".to_string());
28 let wrap = args.get(3).cloned().unwrap_or("".to_string());
29 let class = args.get(4).cloned().unwrap_or("".to_string());
30 let id = args.get(5).cloned().unwrap_or("".to_string());
31 let name = args.get(6).cloned().unwrap_or("".to_string());
32 let div;
33
34 match event.as_str() {
35 "form" => div = DIV_FETCH_FORM,
36 "none" => div = DIV_FETCH_NONE,
37 "visible" => div = DIV_FETCH_VISIBLE,
38 "click" => div = DIV_FETCH_CLICK,
39 "auto" => div = DIV_FETCH_AUTO,
40 _ => div = DIV_FETCH_AUTO,
41 }
42
43 if self.code.contains(BIF_OPEN) {
44 self.code = new_child_parse!(self, &self.code, self.mod_scope);
45 }
46
47 self.out = div
48 .replace("{id}", &id)
49 .replace("{name}", &name)
50 .replace("{wrap}", &wrap)
51 .replace("{class}", &class)
52 .replace("{body}", &self.code)
53 .replace("{endpoint}", &url);
54
55 if !self.shared.disable_js && !self.shared.already_js {
56 self.out = format!(
57 "{}{}{}{}",
58 self.out,
59 "{:!cache;{:moveto;</body>>",
60 NEUTRAL_JS.to_string(),
61 ":}:}"
62 );
63 self.shared.already_js = true;
64 }
65
66 Ok(())
67 }
68}
69
70#[cfg(test)]
71#[path = "parse_bif_fetch_tests.rs"]
72mod tests;