diff --git a/README.md b/README.md index d6a83ce..ce69da0 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,13 @@ Scripting Markup Language is a custom easy to use markup language with HTML-like syntax with extra features that transpile to Javascript and HTML. + The idea of SCML was to give simple markup extra features, that anyone can easily get started with and get a web page running with little knowledge of JS. It allows you to write less and get more! It is written entirely in the Rust programming language. -To download the binary for the cli [click](https://github.com/Valentine-Mario/SCML/releases/tag/0.1.0) +To download the binary for the cli [click](https://github.com/Valentine-Mario/SCML/releases/tag/1.0.0) -- For Linux users: Place the binary in your **/usr/bin** or **/usr/local/bin** directory to make the CLI command globally accessible +- For Linux users: Place the binary in your **/usr/bin** or **/usr/local/bin** directory to make the CLI command globally accessible +- You might need to run the chmod command first **chmod +x scml** - For Windows users: @@ -101,14 +103,18 @@ in[seg_2] ``` + Notice that seg_2 imports seg_1 but the final segment does not directly call seg_1. But because the anonymous segment calls seg_2 which calls seg_1, it would import seg_1 along with it. And this can go on 20 layers deep :scream: Note: Avoid importing segments in itself. #### Import SCML files and reuse segments from other files + + SCML also allows you reuse other SCML files. Instead of rewriting headers and footers for every HTML files, you can easily create an SCML header and footer file, then import it to be used in your current file using the syntax inFile[path_to_scml]. Sweet right? :grin: + Let's look at an example. Create a file called **header.scml** and add the following content to it @@ -188,12 +194,26 @@ inFile[file2.scml] Notice that file 1 is imported in file 2 while file 2 is imported in file 3. When File 3 is transpiled, it would contain the contents of file 1 and file 2 because it is dependent on file 2 which is dependent on file 1. And of course you can reuse segments in either file 2 or file 1 from file 3. + +#### Comments + +Adding comments is pretty simple. To add a comment to your SCML code, just start the line with # to comment out a particular line + +``` +[html ind1] +#this is a comment +[html] +``` +Commented sections would not be included in the transpiled HTML + + Note: Avoid using extra spaces when importing files eg: inFile[ file.scml], inFile [file.scml] would be ignored. ## JS PROCESSING SCML also has some helper functions that transpile to your regular javascript. But don't be afraid, this syntax helpers also feel like regular HTML :grin: + **Please note that when using JS helper functions the following syntax structure is to be followed `` Every tag that uses JS helper function must have an ID and the helper function should come right after the ID. eg @@ -203,13 +223,7 @@ If you wish to assign class or extra attribues to the tag, it should be added af and be sure to use the protocol for naming variables when naming ID because in some cases, some ID would be used as variable names. Improperly formatted syntax would be ignored. Also note that not more than one helper js function should be used per tag else, only the first helper function would be used and the rest ignored. And finally, avoid reusing segments that contain helper functions since reusing replicates the ID again and ID has to be unique to a tag in HTML** -#### Append text -To append text to a particular html tag, use the following syntax: -``` -

-``` -This helps you dynamically append the text "Let's go there!!!" to the tag using JS. #### Limit text To limit text in a tag, use the following syntax: @@ -227,6 +241,21 @@ This allows you to get the content of a tag: ``` This would get the content of the tag and assign them to the variable name var1 we decleard above. + +#### Append text +To append text to a particular html tag, use the following syntax: + +``` +#to dynamically add static string +

+ +#to grab text from a string and add it dynamically to another tag using the append helper function +

get this text

+

+ +``` +This helps you dynamically append the text "Let's go there!!!" to the tag using JS. The end helps specify the end of the sentence or variable. Notice in the second example how i dynamically extracted text from the first tag using innerHTML and used the append to append it into another tag + #### Get form input To get the imput from a form: @@ -330,6 +359,7 @@ To submit a form input to an endpoint: ``` + notice in the button tag, we did *id="mybut" submitForm[https://submit.com]=myForm*. We pass an id to the button, followed by submitForm[https://submit.com] which contains the submit url, followed by the id of the form we want to submit. #### Share link diff --git a/src/html_processing.rs b/src/html_processing.rs index dc06b6c..b778016 100644 --- a/src/html_processing.rs +++ b/src/html_processing.rs @@ -14,10 +14,10 @@ pub mod process_html{ let mut tmp=String::from(scml_string); //loop through 20 times to be sure all values of in are correctly replaced - for _i in 1..20{ + for _i in 1..50{ for (key, value) in scml_hash{ let key=format!("in[{}]", key); - tmp=tmp.replace(&key, value); + tmp=tmp.replace(&key, value); } @@ -91,8 +91,15 @@ pub mod process_html{ impl Config { pub fn new(mut value: std::env::Args) -> Result { if value.len() < 3 { - return Err("at least 2 arguments are expected"); - } else { + println!(" +Inavlid number of arguments parsed +SCML CLI options +Options:\n\tscml scml_path new_file_name => Transpile SCML and create HTML and JS + +Author: Oragbakosi Valentine + "); + return Err(""); + }else { value.next(); let filename = match value.next() { Some(arg) => arg, diff --git a/src/js_processing.rs b/src/js_processing.rs index b345f58..78fc291 100644 --- a/src/js_processing.rs +++ b/src/js_processing.rs @@ -1,6 +1,6 @@ pub mod process_js{ use regex::Regex; - pub fn process_innerhtml(value:&str)->Vec{ + pub fn process_innerjs(value:&str)->Vec{ // append text or tag id="id here" append=var_name end> let append_text=Regex::new(r#"<\s*?\w+?\s*?id=\s*?["|']\s*?(\w+)\s*?["|']\s*?append\s*?=\s*?(.+?)\s*?end\s*?.*?>"#).unwrap(); diff --git a/src/main.rs b/src/main.rs index 60ecf0e..8a5fe52 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,9 +7,12 @@ mod js_processing; use crate::js_processing::process_js; fn main() { + let args = env::args(); + + let get_filename = process_html::Config::new(args).unwrap_or_else(|error| { - eprintln!("Problem parsing arguments: {}", error); + eprintln!("{}", error); process::exit(1); }); let file_content=process_html::read_file(&get_filename.filename).unwrap_or_else(|err| { @@ -17,21 +20,27 @@ fn main() { process::exit(1) }); println!("processing html"); + let comment_re = Regex::new(r"(?m)#.*\n").unwrap(); + let file_content = comment_re.replace_all(&file_content, "\n\n"); + let file_content_from_another_file=process_html::replace_file(&file_content); let file_content=file_content_from_another_file.replace("\n", ""); let hash_value=process_html::generate_scml_hash(&file_content); - let vector=process_js::process_innerhtml(&file_content); let final_string=process_html::replace_variable(&file_content, &hash_value); - if vector.len()>0 { - println!("processing javascript"); - } - process_html::write_to_js_file(&vector, &get_filename).unwrap_or_else(|error|{ - eprintln!("problem writing to file {}", error); - process::exit(1); - }); + let vector=process_js::process_innerjs(&file_content); + if vector.len()>0 { + println!("processing javascript"); + } + process_html::write_to_js_file(&vector, &get_filename).unwrap_or_else(|error|{ + eprintln!("problem writing to file {}", error); + process::exit(1); + }); + + let re= Regex::new(r#"\[\s*?html \w*?\s*?\]|append\s*?=\s*?(.+?)\s*?end|limit\s*?=\s*?(\d{1,})|innerHTML\s*?=\s*?(\w+)|getValue\s*?=\s*?(\w+)|disable\s*?=\s*?true|(\w+)\s*?=\s*?\{(.*?)\}\s*?|formatInt|formatFloat|visibility\s*?=\s*?(\w+)|formatDate\s*?=\s*?(\w+/\w+/\w+)\s*?|formatTimeAgo|formatCurrency\s*?=\s*?["|']\s*?(\w+)\s*?["|']|reverseString|shortenNum|onChange=\s*?(\w+)|submitForm\s*?\[(.+?)\]\s*?=\s*?(\w+)|shareDefault=\s*?["|']\s*?(\w+)\s*?["|']|shareCustome\s*?\[\s*?(.*?)\s*?\]\s*?=\s*?["|']\s*?(\w+)\s*?["|']|copyArea=\s*?(\w+)"#).unwrap(); + let result=re.replace_all(&final_string, ""); diff --git a/tester.scml b/tester.scml index cb7d8b3..fb3087b 100644 --- a/tester.scml +++ b/tester.scml @@ -25,6 +25,7 @@ inFile[head.scml] [html] [html four] +#this is a comment

text four

2020-06-10T17:47:29.156Z
2020-06-10T17:47:29.156Z