-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These are based on Tera and Handlebars. shopify/liquid's are a bit more work to port over. The process for running this has been documented in `CONTRIBUTING.md`, along with a lot of other things.
- Loading branch information
Showing
2 changed files
with
147 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,43 @@ | ||
Thanks for contributing! :snowman: | ||
Thanks for wanting to contribute! :snowman: | ||
|
||
Feel free to create issues and make pull requests, we'll try to quickly review them. | ||
Feel free to create issues or make pull requests, we'll try to quickly review them. | ||
|
||
If you need assistance, you can join the `#cobalt` channel on `irc.mozilla.org` or the Gitter chat [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/cobalt-org/cobalt.rs) | ||
|
||
We want you to feel safe and welcome and will enforce the **[The Rust Code of Conduct](https://www.rust-lang.org/conduct.html)** on all communication platforms of this project. | ||
Please contact [@johannhof](https://github.com/johannhof) for questions or in cases of violation. | ||
|
||
# Issues | ||
|
||
This project aims to be a Rust implementation of [https://shopify.github.io/liquid/](Liquid). | ||
- Notice that we deviate from shopify/liquid? Please, open an issue if there isn't an [existing one](https://github.com/cobalt-org/liquid-rust/labels/shopify-compatibility) | ||
- Want a new tag or filter? Check for an [https://github.com/cobalt-org/liquid-rust/labels/enhancement](existing issue) and open one if needed. | ||
|
||
# Pull Requests | ||
|
||
## Project Ideas | ||
|
||
If you're looking for things to do check out the [open issues](https://github.com/cobalt-org/cobalt.rs/issues), especially those with the | ||
[easy](https://github.com/cobalt-org/liquid-rust/issues?q=is%3Aissue+is%3Aopen+label%3Aeasy) and [help wanted](https://github.com/cobalt-org/liquid-rust/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) flags. | ||
Or take a grep through [all TODO comments](https://github.com/cobalt-org/liquid-rust/search?q=TODO) in the code and feel free to help us out there! | ||
|
||
## Best Practices | ||
|
||
We appreciate your help as-is. We'd love to help you through the process for contributing. We have some suggestions to help make things go more smoothly. | ||
|
||
🌈 **Here's a checklist for the perfect pull request:** | ||
- [ ] Make sure existing tests still work by running `cargo test` locally. | ||
- [ ] Add new tests for any new feature or regression tests for bugfixes. | ||
- [ ] Install [Clippy](https://github.com/Manishearth/rust-clippy) and run `rustup run nightly cargo clippy` to catch common mistakes (will be checked by Travis) | ||
- [ ] Install [Rustfmt](https://github.com/rust-lang-nursery/rustfmt) and run `cargo fmt` to format your code (will also be checked by Travis) | ||
|
||
If you need assistance, you can join the `#cobalt` channel on `irc.mozilla.org` or the Gitter chat [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/cobalt-org/cobalt.rs) | ||
For new tags or filters, we recommend | ||
- Open an RFC Issue for discussing what the API should be. We'd like to avoid disrupting people once they start using a feature. | ||
- Consider incubating it in your code first to so it can be iterated on to find what works well. | ||
- Checkout prior art with [https://help.shopify.com/themes/liquid](Shopify's proprietary extensions) or [https://jekyllrb.com/docs/templates/](Jekyll's extensions). | ||
|
||
We want you to feel safe and welcome and will enforce the **[The Rust Code of Conduct](https://www.rust-lang.org/conduct.html)** on all communication platforms of this project. | ||
Please contact [@johannhof](https://github.com/johannhof) for questions or in cases of violation. | ||
If you're interested in benchmarking your changes | ||
- Be sure to get some before and afters on the same machine | ||
- Rust nightly is required. You'll need to run `rustup run nightly -- cargo bench` | ||
|
||
Hopefully we get this integrated into your CI process. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#![feature(test)] | ||
|
||
extern crate test; | ||
extern crate serde; | ||
extern crate serde_yaml; | ||
|
||
extern crate liquid; | ||
|
||
use liquid::Renderable; | ||
|
||
static TEXT_ONLY: &'static str = "Hello World"; | ||
|
||
#[bench] | ||
fn bench_parse_text(b: &mut test::Bencher) { | ||
b.iter(|| { | ||
let options = liquid::LiquidOptions::with_known_blocks(); | ||
liquid::parse(TEXT_ONLY, options) | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn bench_render_text(b: &mut test::Bencher) { | ||
let options = liquid::LiquidOptions::with_known_blocks(); | ||
let template = liquid::parse(TEXT_ONLY, options).expect("Benchmark template parsing failed"); | ||
|
||
let data = liquid::Object::new(); | ||
|
||
b.iter(|| { | ||
let mut context = liquid::Context::with_values(data.clone()); | ||
template.render(&mut context) | ||
}); | ||
} | ||
|
||
// Mirrors tera's VARIABLE_ONLY benchmark | ||
static VARIABLE_ONLY: &'static str = "{{product.name}}"; | ||
static VARIABLE_ONLY_OBJECT: &'static str = " | ||
username: bob | ||
product: | ||
- name: Moto G | ||
- manufacturer: Motorola | ||
- summary: A phone | ||
- price: 100 | ||
"; | ||
|
||
#[bench] | ||
fn bench_parse_variable(b: &mut test::Bencher) { | ||
b.iter(|| { | ||
let options = liquid::LiquidOptions::with_known_blocks(); | ||
liquid::parse(VARIABLE_ONLY, options) | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn bench_render_variable(b: &mut test::Bencher) { | ||
let options = liquid::LiquidOptions::with_known_blocks(); | ||
let template = | ||
liquid::parse(VARIABLE_ONLY, options).expect("Benchmark template parsing failed"); | ||
|
||
let data: liquid::Object = | ||
serde_yaml::from_str(VARIABLE_ONLY_OBJECT).expect("Benchmark object parsing failed"); | ||
|
||
b.iter(|| { | ||
let mut context = liquid::Context::with_values(data.clone()); | ||
template.render(&mut context) | ||
}); | ||
} | ||
|
||
// Mirrors handlebars' benchmark | ||
static ITERATE: &'static str = "<html> | ||
<head> | ||
<title>{{year}}</title> | ||
</head> | ||
<body> | ||
<h1>CSL {{year}}</h1> | ||
<ul> | ||
{% for team in teams %} | ||
<li class=\"champion\"> | ||
<b>{{team.name}}</b>: {{team.score}} | ||
</li> | ||
{{/each}} | ||
</ul> | ||
</body> | ||
</html>"; | ||
static ITERATE_OBJECT: &'static str = " | ||
year: 2015 | ||
teams: | ||
- name: Jiangsu | ||
score: 43 | ||
- name: Beijing | ||
score: 27 | ||
- name: Guangzhou | ||
score: 22 | ||
- name: Shandong | ||
score: 12 | ||
"; | ||
|
||
#[bench] | ||
fn bench_parse_template(b: &mut test::Bencher) { | ||
b.iter(|| { | ||
let options = liquid::LiquidOptions::with_known_blocks(); | ||
liquid::parse(ITERATE, options) | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn bench_render_template(b: &mut test::Bencher) { | ||
let options = liquid::LiquidOptions::with_known_blocks(); | ||
let template = liquid::parse(ITERATE, options).expect("Benchmark template parsing failed"); | ||
|
||
let data: liquid::Object = | ||
serde_yaml::from_str(ITERATE_OBJECT).expect("Benchmark object parsing failed"); | ||
|
||
b.iter(|| { | ||
let mut context = liquid::Context::with_values(data.clone()); | ||
template.render(&mut context) | ||
}); | ||
} |