Skip to content

Commit

Permalink
added generic segment
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentine-Mario committed Sep 22, 2020
1 parent 00e5c9e commit 8792ca7
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 30 deletions.
17 changes: 17 additions & 0 deletions app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang='en'><head><meta charset='UTF-8'>

<meta name='viewport' content='width=device-width, initial-scale=1.0'>

<title>app</title>

</head>

<body><p>hi: {name}</p>i said hello
<p>Age:{age}</p><p>title:{title}</p>

in[one:[name="kenneth"]]in[two:[age="34" title="chief"]]in[one:[name="val"]]
in[one:[name="ken"]]
</body>
<script type='text/javascript' src='app.js'></script>
</html>
Empty file added app.js
Empty file.
17 changes: 17 additions & 0 deletions gen.scml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[html one]
<p>hi: {name}</p>
i said hello
[html]

[html two]
<p>Age:{age}</p>
<p>title:{title}</p>
[html]

[html]
in[one:[name="kenneth"]]
in[two:[age="34" title="chief"]]
in[one:[name="val"]]
[html]

in[one:[name="ken"]]
73 changes: 44 additions & 29 deletions src/html_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,35 +41,50 @@ pub mod process_html{
tmp
}

// pub fn replace_variable_parameter(scml_string:&str, scml_hash:HashMap<String, &str>)->String{
// let mut tmp=String::from(scml_string);
// let mut html_id = HashMap::new();

// for (key, mut value) in scml_hash{
// let string_target=format!(r#"in\[{}\s*?:\s*?\[(\w+=\s*?["|']\s*?[[:alnum:]]*[[:punct:]]*\s*?["|']\s*?)\]+?\s*?\]"#, key);
// let string_regex=Regex::new(&string_target).unwrap();
// for val in string_regex.captures_iter(scml_string){

// for val2 in Regex::new(r#"\s*?(\w+)\s*?=["|']\s*?(.*)["|'],??"#).unwrap().captures_iter(val.get(1).unwrap().as_str()){
// if Regex::new(r#"\s*?(\w+)\s*?=["|']\s*?(.*)["|']"#).unwrap().is_match(val.get(1).unwrap().as_str()){

// html_id.insert(String::from(val2.get(1).unwrap().as_str()), val2.get(2).unwrap().as_str());
// }
// }

// let mut new_val=String::from(value);

// for (key2, value2) in &html_id{
// let var_format=format!("{{{{{}}}}}", key2);

// new_val= value.replace(&var_format, &value2);
// }
// let string_litral=format!("in[{}:[{}]]", key, val.get(1).unwrap().as_str());
// tmp=tmp.replace(&string_litral, &new_val);
// }
// }
// tmp
// }
pub fn replace_variable_parameter(scml_string:&str, scml_hash:&HashMap<String, String>)->String{
let mut tmp=String::from(scml_string);

// for _i in 1..50{
for (key, value) in scml_hash{
//get hash conten
let mut key_content= value.to_string();

//in[seg_name:[name="value"]]
let string_target=format!(r#"in\[{}\s*?:\s*?(\[\w+=\s*?["|']\s*?.+?\s*?["|']\s*?\]+?)\s*?\]"#, key);
let string_regex=Regex::new(&string_target).unwrap();


let generic_hash=generate_generic_hash(&scml_string, &key);
for(generic_hash_key, generic_hash_value) in &generic_hash{

let key=format!(r#"{{{}}}"#, generic_hash_key);

key_content=key_content.replace(&key, &generic_hash_value);

}
tmp=string_regex.replace(&tmp, key_content.as_str()).to_string();
}
// }

tmp
}

fn generate_generic_hash(scml_string:&str, key:&str)->HashMap<String, String>{
let mut generic_hash = HashMap::new();

let string_target=format!(r#"in\[{}\s*?:\s*?(\[\w+=\s*?["|']\s*?.+?\s*?["|']\s*?\]+?)\s*?\]"#, key);
let string_regex=Regex::new(&string_target).unwrap();

let variables=format!(r#"(\w+)=\s*?["|']\s*?(.+?)\s*?["|']\s*?"#);
let string_variables=Regex::new(&variables).unwrap();

for val in string_regex.captures_iter(scml_string){
for val2 in string_variables.captures_iter(val.get(1).unwrap().as_str()){
generic_hash.insert(String::from(val2.get(1).unwrap().as_str()), String::from(val2.get(2).unwrap().as_str()));
}
}
generic_hash
}

pub fn generate_scml_hash(value:&str)->HashMap<String, String>{
let re= Regex::new(r"\[html (\w+)\]\s*?(.+?)\s*?\[html\]").unwrap();
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ fn main() {
let hash_value=process_html::generate_scml_hash(&file_content);

let final_string=process_html::replace_variable(&file_content, &hash_value);
let generaic_seg=process_html::replace_variable_parameter(&file_content, &hash_value);
println!("{}", generaic_seg);

let vector=process_js::process_innerjs(&file_content);
if vector.len()>0 {
Expand Down
6 changes: 5 additions & 1 deletion tester.scml
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,9 @@ inFile[head.scml]
<div>
<p id="to_copy">copy me</p>
<button id="copy_me" copyArea=to_copy>copy</button>
in[five:[name="val house" age="34" date="23/34/2020"]]
in[three:[name="kin" age="44" date="23/34/2020"]]

</div>
[html]
in[one]
[html]

0 comments on commit 8792ca7

Please sign in to comment.