Rust-ൽ Go html/template ശൈലിയിലുള്ള റെൻഡറിംഗ്.
go_html_template പ്രധാന Go html/template പ്രവർത്തന പ്രവാഹങ്ങളെ അനുകരിക്കുന്ന ഒരു Rust crate ആണ്. പരിചിതമായ API രൂപം നിലനിർത്തിക്കൊണ്ട് template syntax, pipeline-കൾ, സന്ദർഭാധിഷ്ഠിത escaping, സുരക്ഷിതമല്ലാത്ത URL scheme-കളുടെ തടയൽ എന്നിവ പിന്തുണയ്ക്കുന്നു.
Go പോലുള്ള Template API
define/template/range/with/pipeline സവിശേഷതകളോടൊപ്പം Template::new(...).parse(...).execute(...) ഉപയോഗിക്കുക.
സന്ദർഭാധിഷ്ഠിത escaping
HTML ടെക്സ്റ്റ്, attributes, URL attributes, script/style contexts എന്നിവയ്ക്ക് context-aware escaping പ്രയോഗിക്കുകയും സുരക്ഷിതമല്ലാത്ത javascript: URL-കൾ തടയുകയും ചെയ്യുന്നു.
web-rust മോഡ്
web-rust സവിശേഷത ഉപയോഗിക്കുമ്പോൾ parse_files/parse_glob/parse_fs അപ്രാപ്തമാക്കപ്പെടുന്നു, അതിനാൽ in-memory template loading നിർബന്ധിപ്പിക്കാം.
ക്രമീകരണവും അടിസ്ഥാന ഉപയോഗവും
crate ചേർക്കുക, തുടർന്ന് ഏറ്റവും കുറഞ്ഞ parse + execute_to_string പ്രവാഹം പരിശോധിക്കുക. web-rust അന്തരീക്ഷങ്ങളിൽ file-loading API-കൾക്ക് പകരം in-memory template string-കൾ ഉപയോഗിക്കുക.
ഇൻസ്റ്റാൾ ചെയ്യുക
cargo add go_html_template
Rust ഉദാഹരണം
use go_html_template::{Template, Value};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let tpl = Template::new("page")
.parse(r#"<h1>{{.Title}}</h1>\n<p>{{.Body | safe_html}}</p>"#)?;
let out = tpl.execute_to_string(&serde_json::json!({
"Title": "go_html_template",
"Body": "<em>trusted</em>"
}))?;
println!("{out}");
Ok(())
}
പൊരുത്തക്ഷമത നില
go_html_template ഇപ്പോൾ അടിസ്ഥാന പ്രവർത്തന പ്രവാഹങ്ങൾ നടപ്പിലാക്കിക്കൊണ്ടിരിക്കുമ്പോഴും അനുയോജ്യതയിലെ വിടവുകൾ അടയ്ക്കുന്നത് തുടരുന്നു . ഇത് ഇനിയും Go html/template-നൊപ്പം കർശനമായ 1:1 പൊരുത്ത ലക്ഷ്യമല്ല; അതിനാൽ നിങ്ങളുടെ production template-കളിൽ പെരുമാറ്റം പരിശോധിക്കുക.
മുമ്പത്തെത്
OSS പട്ടികഅടുത്തത്
README / പൂർണ്ണ സ്പെസിഫിക്കേഷനുകൾ