Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentine-Mario authored Aug 4, 2020
2 parents 4fedd21 + b11ba71 commit 5dd7517
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 22 deletions.
46 changes: 38 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
`<tag id="id_here" helper_func>`
Every tag that uses JS helper function must have an ID and the helper function should come right after the ID. eg
Expand All @@ -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:

```
<p id="tag1" append="Let's go there!!!"></p>
```
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:
Expand All @@ -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
<p id="tag1" append="Let's go there!!!" end></p>
#to grab text from a string and add it dynamically to another tag using the append helper function
<p id="id2" innerHTML=var2>get this text</p>
<p id="id3" append=var2 end></p>
```
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:

Expand Down Expand Up @@ -330,6 +359,7 @@ To submit a form input to an endpoint:
<button id="mybut" submitForm[https://submit.com]=myForm>click</button>
</form>
```

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
Expand Down
15 changes: 11 additions & 4 deletions src/html_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

Expand Down Expand Up @@ -91,8 +91,15 @@ pub mod process_html{
impl Config {
pub fn new(mut value: std::env::Args) -> Result<Config, &'static str> {
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 <email: [email protected]>
");
return Err("");
}else {
value.next();
let filename = match value.next() {
Some(arg) => arg,
Expand Down
2 changes: 1 addition & 1 deletion src/js_processing.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod process_js{
use regex::Regex;
pub fn process_innerhtml(value:&str)->Vec<String>{
pub fn process_innerjs(value:&str)->Vec<String>{
// append text <tag id="id here" append="append this text to tag" end> 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();

Expand Down
27 changes: 18 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,40 @@ 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| {
eprintln!("Problem reading file: {}", err);
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, "");


Expand Down
1 change: 1 addition & 0 deletions tester.scml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ inFile[head.scml]
[html]

[html four]
#this is a comment
<p id="four_head" visibility=visible>text four<p>
<div id="some_date" formatDate=dd/mm/yyyy>2020-06-10T17:47:29.156Z</div>
<div id="some_date3" formatDate=mm/dd/yyyy>2020-06-10T17:47:29.156Z</div>
Expand Down

0 comments on commit 5dd7517

Please sign in to comment.