From 9d0ca63aa9a4a27c1549a1273bc754ce2e8b2d63 Mon Sep 17 00:00:00 2001 From: Magnus Hoff Date: Thu, 21 Sep 2017 11:42:09 +0200 Subject: [PATCH] When inventing a title from a slug, add some capitalization --- Cargo.lock | 11 +++++++++++ Cargo.toml | 1 + src/main.rs | 1 + src/new_article_resource.rs | 2 +- 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 7781619..2181ba5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -591,6 +591,7 @@ dependencies = [ "serde_urlencoded 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "slug 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "static_resource_derive 0.1.0", + "titlecase 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-proto 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-service 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -767,6 +768,15 @@ dependencies = [ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "titlecase" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "tokio-core" version = "0.1.9" @@ -1019,6 +1029,7 @@ dependencies = [ "checksum textwrap 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df8e08afc40ae3459e4838f303e465aa50d823df8d7f83ca88108f6d3afe7edd" "checksum thread_local 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1697c4b57aeeb7a536b647165a2825faddffb1d3bad386d507709bd51a90bb14" "checksum time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d788d3aa77bc0ef3e9621256885555368b47bd495c13dd2e7413c89f845520" +"checksum titlecase 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0650399a761c61e9691ccc878bce2608291f7c18d8f84d188e6e11748a5316c8" "checksum tokio-core 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e85d419699ec4b71bfe35bbc25bb8771e52eff0471a7f75c853ad06e200b4f86" "checksum tokio-io 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b4ab83e7adb5677e42e405fa4ceff75659d93c4d7d7dd22f52fcec59ee9f02af" "checksum tokio-proto 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8fbb47ae81353c63c487030659494b295f6cb6576242f907f203473b191b0389" diff --git a/Cargo.toml b/Cargo.toml index 37c8c0f..9f66281 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ slug = "0.1" r2d2 = "0.7" r2d2-diesel = "0.16" regex = "0.2" +titlecase = "0.10" lazy_static = "0.2" chrono = "0.4" clap = "2.26" diff --git a/src/main.rs b/src/main.rs index 5a543c3..86544d2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,6 +18,7 @@ extern crate r2d2_diesel; extern crate serde_json; extern crate serde_urlencoded; extern crate slug; +extern crate titlecase; use std::net::SocketAddr; diff --git a/src/new_article_resource.rs b/src/new_article_resource.rs index 770d9b5..1f5fa09 100644 --- a/src/new_article_resource.rs +++ b/src/new_article_resource.rs @@ -21,7 +21,7 @@ edit-link below and saving a new article.

"; fn title_from_slug(slug: &str) -> String { - slug.replace('-', " ") + ::titlecase::titlecase(&slug.replace('-', " ")) } pub struct NewArticleResource {