Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

mustache template library for rust

License

NotificationsYou must be signed in to change notification settings

nickel-org/rust-mustache

Repository files navigation

Inspired byctemplate andet,Mustache is a framework-agnostic wayto render logic-free views.

As ctemplates says, "It emphasizes separating logic from presentation: it isimpossible to embed application logic in this template language."

rust-mustache is a rust implementation of Mustache.

Documentation

The different Mustache tags are documented atmustache(5).

Documentation for this library ishere.

Install

Install it through Cargo!

[dependencies]mustache ="*"

Basic example

#[macro_use]externcrate serde_derive;externcrate mustache;use std::io;use mustache::MapBuilder;#[derive(Serialize)]structPlanet{name:String,}fnmain(){// First the string needs to be compiled.let template = mustache::compile_str("hello {{name}}").unwrap();// You can either use an encodable type to print "hello Mercury".let planet =Planet{name:"Mercury".into()};    template.render(&mut io::stdout(),&planet).unwrap();println!("");// ... or you can use a builder to print "hello Venus".let data =MapBuilder::new().insert_str("name","Venus").build();    template.render_data(&mut io::stdout(),&data).unwrap();println!("");// ... you can even use closures.letmut planets =vec!("Jupiter","Mars","Earth");let data =MapBuilder::new().insert_fn("name",move |_|{            planets.pop().unwrap().into()}).build();// prints "hello Earth"    template.render_data(&mut io::stdout(),&data).unwrap();println!("");// prints "hello Mars"    template.render_data(&mut io::stdout(),&data).unwrap();println!("");// prints "hello Jupiter"    template.render_data(&mut io::stdout(),&data).unwrap();println!("");}

Testing

Simply clone and run:

# If you want to run the test cases, you'll need the spec as well.git submodule initgit submodule updatecargotest# If you want to test the readme example, we're currently using the unstable feature to do so.cargo +nightlytest --features unstable

Releasing

If cutting a new release, please follow something along the lines of the below:

# Assuming master is the current release commit, ideally it will be a commit# announcing the release and the only change would be the version number.# Ensure everything looks goodcargo publish --dry-run# Actually publishcargo publish# Tag the release, prefix it with 'v' for easy tag searching, i.e. git tag --list 'v*'git tag vX.Y.Zgit push --tags origin master

License

See LICENSE File

About

mustache template library for rust

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp