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

A flexible template engine for Rust

NotificationsYou must be signed in to change notification settings

rustache/rustache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rustache is aRust implementation of theMustache spec.

Documentation

The different Mustache tags are documented at themustache(5) man page.

The project's docs page is locatedhere.

Install

Install it throughCargo:

rustache ="^0.1"

Then link it within your crate like so:

externcrate rustache;

API Methods

The main forward interface that users will interact with when using Rustacheis therender method provided by therustache::Render trait like so:

// Renders the given template stringlet data = rustache::HashBuilder::new().insert("name","your name");letmut out =Cursor::new(Vec::new());data.render("{{ name }}",&mut out).unwrap();println!("{}",String::from_utf8(out.into_inner()).unwrap());

Examples

Here's an example of how to pass in data to therender_text method using theHashBuilder:

let data =HashBuilder::new().insert("name","Bob");letmut out =Cursor::new(Vec::new());data.render("{{ name }}",&mut out);

Here's an example of how to pass in data in the form of a JSONenum to arender method:

let data = json::from_str(r#"{"name": "Bob"}"#);letmut out =Cursor::new(Vec::new());data.render("{{ name }}",&mut out);

For more examples please see thetests directory.

Testing

Simply clone and run:

cargotest

Roadmap

  • Full Mustache spec compliance.

    • Comment and Section whitespace handling
    • Handle change of delimeters
  • Thread errors through the parser and compiler:

  • Real world project examples.

  • Handle Build and Parser operations concurrently

Contribute

SeeCONTRIBUTING.md for guidelines on how to contribute.

License

Copyright (c) 2014 Team Rustache

Permission is hereby granted, free of charge, to any person obtaininga copy of this software and associated documentation files (the"Software"), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sublicense, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:

The above copyright notice and this permission notice shall beincluded in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE ANDNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BELIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTIONOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTIONWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Inspired byhttps://github.com/erickt/rust-mustache:

Copyright (c) 2012 Erick Tryzelaar

Permission is hereby granted, free of charge, to any person obtaininga copy of this software and associated documentation files (the"Software"), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sublicense, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:

The above copyright notice and this permission notice shall beincluded in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE ANDNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BELIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTIONOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTIONWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

A flexible template engine for Rust

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors12


[8]ページ先頭

©2009-2025 Movatter.jp