Skip to content

Commit

Permalink
Merge pull request #6 from exyi/template_engine
Browse files Browse the repository at this point in the history
Introduced template engine to code generation
  • Loading branch information
vakabus authored Oct 29, 2020
2 parents 3f37e4d + 6c0b915 commit 4a3faa4
Show file tree
Hide file tree
Showing 9 changed files with 482 additions and 183 deletions.
189 changes: 182 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ authors = ["exyi", "vakabus"]

[dependencies]
base64 = "*"
argparse = "*"
argparse = "*"
askama = "0.8"
34 changes: 34 additions & 0 deletions src/code/c_code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use ::code::CodeTemplate;
use askama::Template;

#[derive(Template)]
#[template(path = "c_code.c", escape = "none")]
pub struct CCodeTemplate {
comment_files: Vec<(String, Vec<String>)>,
executable: String,
assets: Vec<(String, String)>,
}

impl CodeTemplate for CCodeTemplate {
fn render(executable_b64: String, payload_b64: Vec<(String, String)>, comment_files: Vec<(String, Vec<String>)>) -> String {
let template = CCodeTemplate {executable: executable_b64, assets: payload_b64 , comment_files};
template.render().unwrap()
}
}



#[derive(Template)]
#[template(path = "c_code_with_checks.c", escape = "none")]
pub struct CCodeWithChecksTemplate {
comment_files: Vec<(String, Vec<String>)>,
executable: String,
assets: Vec<(String, String)>,
}

impl CodeTemplate for CCodeWithChecksTemplate {
fn render(executable_b64: String, payload_b64: Vec<(String, String)>, comment_files: Vec<(String, Vec<String>)>) -> String {
let template = CCodeWithChecksTemplate {executable: executable_b64, assets: payload_b64 , comment_files};
template.render().unwrap()
}
}
17 changes: 17 additions & 0 deletions src/code/csharp_code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use ::code::CodeTemplate;
use askama::Template;

#[derive(Template)]
#[template(path = "csharp_code.cs", escape = "none")]
pub struct CSharpCodeTemplate {
comment_files: Vec<(String, Vec<String>)>,
executable: String,
assets: Vec<(String, String)>,
}

impl CodeTemplate for CSharpCodeTemplate {
fn render(executable_b64: String, payload_b64: Vec<(String, String)>, comment_files: Vec<(String, Vec<String>)>) -> String {
let template = CSharpCodeTemplate {executable: executable_b64, assets: payload_b64, comment_files};
template.render().unwrap()
}
}
6 changes: 6 additions & 0 deletions src/code/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub mod c_code;
pub mod csharp_code;

pub trait CodeTemplate {
fn render(executable_b64: String, payload_b64: Vec<(String, String)>, comment_files: Vec<(String, Vec<String>)>) -> String;
}
Loading

0 comments on commit 4a3faa4

Please sign in to comment.