From c19e900becd53134ce34d3f5f1bde195c46a292f Mon Sep 17 00:00:00 2001 From: Geoff Shannon Date: Mon, 30 Oct 2017 13:55:14 -0700 Subject: [PATCH] Extract syntex highlighting module into a new component in workspace This removes the dependency cycle between config and rendering that causes 4 packages to be recompiled every time a change is made. I just want to code fast! --- Cargo.lock | 11 ++++++++++- Cargo.toml | 1 + components/config/Cargo.toml | 2 +- components/config/src/lib.rs | 4 ++-- components/errors/src/lib.rs | 3 ++- components/highlighting/Cargo.toml | 8 ++++++++ .../src/highlighting.rs | 0 components/highlighting/src/lib.rs | 19 +++++++++++++++++++ components/rendering/Cargo.toml | 1 + components/rendering/src/lib.rs | 2 +- 10 files changed, 45 insertions(+), 6 deletions(-) mode change 100644 => 100755 components/errors/src/lib.rs create mode 100644 components/highlighting/Cargo.toml rename components/{rendering => highlighting}/src/highlighting.rs (100%) create mode 100644 components/highlighting/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index aaed41b..d45f408 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -238,7 +238,7 @@ version = "0.1.0" dependencies = [ "chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "errors 0.1.0", - "rendering 0.1.0", + "highlighting 0.1.0", "serde 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -440,6 +440,14 @@ dependencies = [ "ws 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "highlighting" +version = "0.1.0" +dependencies = [ + "lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "syntect 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "httparse" version = "1.2.3" @@ -939,6 +947,7 @@ version = "0.1.0" dependencies = [ "errors 0.1.0", "front_matter 0.1.0", + "highlighting 0.1.0", "lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", "pulldown-cmark 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index b072f9d..8bc4e39 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,6 +42,7 @@ members = [ "components/content", "components/errors", "components/front_matter", + "components/highlighting", "components/pagination", "components/rendering", "components/site", diff --git a/components/config/Cargo.toml b/components/config/Cargo.toml index 207c411..62409f9 100644 --- a/components/config/Cargo.toml +++ b/components/config/Cargo.toml @@ -10,4 +10,4 @@ serde_derive = "1.0" chrono = "0.4" errors = { path = "../errors" } -rendering = { path = "../rendering" } +highlighting = { path = "../highlighting"} diff --git a/components/config/src/lib.rs b/components/config/src/lib.rs index 262848b..528a5f9 100644 --- a/components/config/src/lib.rs +++ b/components/config/src/lib.rs @@ -3,7 +3,7 @@ extern crate serde_derive; extern crate toml; #[macro_use] extern crate errors; -extern crate rendering; +extern crate highlighting; extern crate chrono; use std::collections::HashMap; @@ -15,7 +15,7 @@ use toml::{Value as Toml}; use chrono::Utc; use errors::{Result, ResultExt}; -use rendering::highlighting::THEME_SET; +use highlighting::THEME_SET; mod theme; diff --git a/components/errors/src/lib.rs b/components/errors/src/lib.rs old mode 100644 new mode 100755 index 1de8cfc..cc698c6 --- a/components/errors/src/lib.rs +++ b/components/errors/src/lib.rs @@ -1,3 +1,5 @@ +#![allow(unused_doc_comment)] + #[macro_use] extern crate error_chain; extern crate tera; @@ -26,4 +28,3 @@ macro_rules! bail { return Err(format!($fmt, $($arg)+).into()); }; } - diff --git a/components/highlighting/Cargo.toml b/components/highlighting/Cargo.toml new file mode 100644 index 0000000..018caa1 --- /dev/null +++ b/components/highlighting/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "highlighting" +version = "0.1.0" +authors = ["Vincent Prouillet "] + +[dependencies] +lazy_static = "0.2" +syntect = { version = "1", features = ["static-onig"] } diff --git a/components/rendering/src/highlighting.rs b/components/highlighting/src/highlighting.rs similarity index 100% rename from components/rendering/src/highlighting.rs rename to components/highlighting/src/highlighting.rs diff --git a/components/highlighting/src/lib.rs b/components/highlighting/src/lib.rs new file mode 100644 index 0000000..f0a80b8 --- /dev/null +++ b/components/highlighting/src/lib.rs @@ -0,0 +1,19 @@ +#[macro_use] +extern crate lazy_static; +extern crate syntect; + +use syntect::dumps::from_binary; +use syntect::parsing::SyntaxSet; +use syntect::highlighting::ThemeSet; + +thread_local!{ + pub static SYNTAX_SET: SyntaxSet = { + let mut ss: SyntaxSet = from_binary(include_bytes!("../../../sublime_syntaxes/newlines.packdump")); + ss.link_syntaxes(); + ss + }; +} + +lazy_static!{ + pub static ref THEME_SET: ThemeSet = from_binary(include_bytes!("../../../sublime_themes/all.themedump")); +} diff --git a/components/rendering/Cargo.toml b/components/rendering/Cargo.toml index 3a59740..66d6fb5 100644 --- a/components/rendering/Cargo.toml +++ b/components/rendering/Cargo.toml @@ -15,6 +15,7 @@ serde_derive = "1.0" errors = { path = "../errors" } front_matter = { path = "../front_matter" } +highlighting = { path = "../highlighting"} utils = { path = "../utils" } [dev-dependencies] diff --git a/components/rendering/src/lib.rs b/components/rendering/src/lib.rs index 1128bce..1dfd39b 100644 --- a/components/rendering/src/lib.rs +++ b/components/rendering/src/lib.rs @@ -11,13 +11,13 @@ extern crate serde; extern crate errors; extern crate front_matter; +extern crate highlighting; extern crate utils; #[cfg(test)] extern crate templates; mod context; -pub mod highlighting; mod markdown; mod short_code; mod table_of_contents;