From 3ae492644e4f9cd62ecf3a78cfdc9f944b98f086 Mon Sep 17 00:00:00 2001 From: Trinity Pointard Date: Sat, 15 Sep 2018 13:28:18 +0200 Subject: [PATCH 1/2] Add travis.yml --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..6a11075 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: rust +rust: + - nightly +cache: cargo From 74bf2141caa2dba3ba7faca324781c56921b506f Mon Sep 17 00:00:00 2001 From: Trinity Pointard Date: Sat, 15 Sep 2018 14:13:24 +0200 Subject: [PATCH 2/2] Fix tests Fix doc-tests Add dev-dependency to rocket_contrib Set some doc-tests to no_run as files are missing for theme to work Remove format!(gettext()) from docs as it won't compile Reexport gettextrs to match what the doc's says --- Cargo.toml | 5 +++++ src/lib.rs | 29 +++++++++++++++++------------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6a13f21..e2c9b25 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,3 +17,8 @@ tera = "0.11" [dependencies.rocket] git = "https://github.com/SergioBenitez/Rocket" rev = "55459db7732b9a240826a5c120c650f87e3372ce" + +[dev-dependencies.rocket_contrib] +features = ["tera_templates"] +git = "https://github.com/SergioBenitez/Rocket" +rev = "55459db7732b9a240826a5c120c650f87e3372ce" diff --git a/src/lib.rs b/src/lib.rs index 4b548ff..04345b6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,10 @@ //! //! Then, in your `main.rs`: //! -//! ```rust +//! ```rust,no_run +//! # //can't be run because 'po/LINGUAS' don't exist +//! # extern crate rocket; +//! # extern crate rocket_contrib; //! extern crate rocket_i18n; //! //! // ... @@ -34,7 +37,7 @@ //! // Eventually register the Tera filters (only works with the master branch of Rocket) //! .attach(rocket_contrib::Template::custom(|engines| { //! rocket_i18n::tera(&mut engines.tera); -//! })) +//! })); //! // Register routes, etc //! } //! ``` @@ -65,17 +68,13 @@ //! You can also use all the gettext functions in your Rust code. //! //! ```rust -//! use rocket_i18n; +//! # #![feature(custom_attribute)] +//! use rocket_i18n::gettext; //! //! #[get("/")] //! fn index() -> String { //! gettext("Hello, world!") //! } -//! -//! #[get("/")] -//! fn hello(name: String) -> String { -//! format!(gettext("Hello, {}!"), name) -//! } //! ``` //! //! ### Editing the POT @@ -102,7 +101,7 @@ extern crate rocket; extern crate serde_json; extern crate tera; -use gettextrs::*; +pub use gettextrs::*; use rocket::{Data, Request, Rocket, fairing::{Fairing, Info, Kind}}; use std::{ collections::HashMap, @@ -119,9 +118,12 @@ const ACCEPT_LANG: &'static str = "Accept-Language"; /// This is the main struct of this crate. You can register it on your Rocket instance as a /// fairing. /// -/// ```rust +/// ```rust,no_run +/// # //can't be run because 'po/LINGUAS' don't exist +/// # extern crate rocket; +/// # extern crate rocket_i18n; /// rocket::ignite() -/// .attach(I18n::new("app")) +/// .attach(rocket_i18n::I18n::new("app")); /// ``` /// /// The parameter you give to [`I18n::new`] is the gettext domain to use. It doesn't really matter what you choose, @@ -252,10 +254,13 @@ fn tera_ngettext(msg: serde_json::Value, ctx: HashMap /// Register translation filters on your Tera instance /// /// ```rust +/// # extern crate rocket; +/// # extern crate rocket_contrib; +/// # extern crate rocket_i18n; /// rocket::ignite() /// .attach(rocket_contrib::Template::custom(|engines| { /// rocket_i18n::tera(&mut engines.tera); -/// })) +/// })); /// ``` /// /// The two registered filters are `_` and `_n`. For example use, see the crate documentation,