From d78477b61951e86d10ca5e9349c0c229b5d76fdf Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Thu, 6 Jul 2017 22:19:15 +0900 Subject: [PATCH] Add Sass support for *nix --- .gitignore | 2 +- CHANGELOG.md | 2 + Cargo.lock | 174 +++++++++++++++++++++++ components/config/src/lib.rs | 4 + components/site/Cargo.toml | 4 + components/site/src/lib.rs | 47 +++++- components/site/test_site/config.toml | 1 + components/site/test_site/sass/blog.scss | 7 + src/cmd/serve.rs | 16 ++- 9 files changed, 252 insertions(+), 5 deletions(-) create mode 100644 components/site/test_site/sass/blog.scss diff --git a/.gitignore b/.gitignore index 66e5644b..8ca1528d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ target .idea/ -test_site/public +components/site/test_site/public small-blog medium-blog diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e6f9d3f..51c1a598 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ the global function `get_section` if you need to get it - Remove index page getting all sections: use the `get_section` global fn instead to only get the ones you need - Remove pages from pagers in pagination: they were not supposed to be there +- Add built-in Sass compilation support (*nix only for now) + ## 0.0.7 (2017-06-19) diff --git a/Cargo.lock b/Cargo.lock index 076c1b81..0b8f0db3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,6 +19,14 @@ name = "ansi_term" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "aster" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "syntex_syntax 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "atty" version = "0.2.2" @@ -79,6 +87,26 @@ dependencies = [ "serde 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "bindgen" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "aster 0.41.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cexpr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "clang-sys 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", + "clap 2.25.0 (registry+https://github.com/rust-lang/crates.io-index)", + "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "quasi 0.32.0 (registry+https://github.com/rust-lang/crates.io-index)", + "quasi_codegen 0.32.0 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syntex_syntax 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "bitflags" version = "0.4.0" @@ -118,6 +146,14 @@ dependencies = [ "iovec 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "cexpr" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "cfg-if" version = "0.1.1" @@ -141,6 +177,17 @@ dependencies = [ "time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "clang-sys" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", + "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)", + "libloading 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "clap" version = "2.25.0" @@ -228,6 +275,15 @@ name = "either" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "env_logger" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "log 0.3.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 = "error" version = "0.1.9" @@ -454,6 +510,16 @@ name = "libc" version = "0.2.24" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "libloading" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "log" version = "0.3.8" @@ -578,6 +644,11 @@ dependencies = [ "libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "nom" +version = "1.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "notify" version = "4.0.1" @@ -669,6 +740,11 @@ dependencies = [ "tera 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "percent-encoding" version = "1.0.0" @@ -713,6 +789,26 @@ dependencies = [ "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "quasi" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "syntex_errors 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)", + "syntex_syntax 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "quasi_codegen" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "aster 0.41.0 (registry+https://github.com/rust-lang/crates.io-index)", + "syntex 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)", + "syntex_errors 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)", + "syntex_syntax 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "quote" version = "0.3.15" @@ -811,6 +907,25 @@ dependencies = [ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "sass-rs" +version = "0.0.18" +source = "git+https://github.com/compass-rs/sass-rs#f871054f523b3baa287cb1719b9598d0d5e1c057" +dependencies = [ + "libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)", + "sass-sys 0.3.0 (git+https://github.com/compass-rs/sass-rs)", +] + +[[package]] +name = "sass-sys" +version = "0.3.0" +source = "git+https://github.com/compass-rs/sass-rs#f871054f523b3baa287cb1719b9598d0d5e1c057" +dependencies = [ + "bindgen 0.26.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "scopeguard" version = "0.3.2" @@ -872,6 +987,7 @@ dependencies = [ "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "pagination 0.1.0", "rayon 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", + "sass-rs 0.0.18 (git+https://github.com/compass-rs/sass-rs)", "serde 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", "taxonomies 0.1.0", @@ -954,6 +1070,48 @@ dependencies = [ "yaml-rust 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "syntex" +version = "0.58.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "syntex_errors 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)", + "syntex_syntax 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "syntex_errors" +version = "0.58.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", + "syntex_pos 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)", + "term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "syntex_pos" +version = "0.58.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "syntex_syntax" +version = "0.58.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", + "syntex_errors 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)", + "syntex_pos 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "taxonomies" version = "0.1.0" @@ -1246,12 +1404,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] "checksum aho-corasick 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "500909c4f87a9e52355b26626d890833e9e1d53ac566db76c36faa984b889699" "checksum ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ac7c30002a5accbf7e8987d0632fa6de155b7c3d39d0067317a391e00a2ef6" +"checksum aster 0.41.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4ccfdf7355d9db158df68f976ed030ab0f6578af811f5a7bb6dcf221ec24e0e0" "checksum atty 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d912da0db7fa85514874458ca3651fe2cddace8d0b0505571dbdcd41ab490159" "checksum backtrace 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "72f9b4182546f4b04ebc4ab7f84948953a118bd6021a1b6a6c909e3e94f6be76" "checksum backtrace-sys 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3a0d842ea781ce92be2bf78a9b38883948542749640b8378b3b2f03d1fd9f1ff" "checksum base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30e93c03064e7590d0466209155251b90c22e37fab1daf2771582598b5827557" "checksum base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96434f987501f0ed4eb336a411e0631ecd1afa11574fe148587adc4ff96143c9" "checksum bincode 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e103c8b299b28a9c6990458b7013dc4a8356a9b854c51b9883241f5866fac36e" +"checksum bindgen 0.26.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ac098a1ae2e8d2ba24f61d8a771c53c5135965709c46b76ccf06cf42b95313e6" "checksum bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dead7461c1127cf637931a1e50934eb6eee8bff2f74433ac7909e9afcee04a3" "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" "checksum bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1370e9fc2a6ae53aea8b7a5110edbd08836ed87c88736dfabccade1c2b44bff4" @@ -1259,9 +1419,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8" "checksum bytes 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c129aff112dcc562970abb69e2508b40850dd24c274761bb50fb8a0067ba6c27" "checksum bytes 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8b24f16593f445422331a5eed46b72f7f171f910fead4f2ea8f17e727e9c5c14" +"checksum cexpr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "393a5f0088efbe41f9d1fcd062f24e83c278608420e62109feb2c8abee07de7d" "checksum cfg-if 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c47d456a36ebf0536a6705c83c1cbbcb9255fbc1d905a6ded104f479268a29" "checksum chrono 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "158b0bd7d75cbb6bf9c25967a48a2e9f77da95876b858eadfabaa99cd069de6e" "checksum chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7c20ebe0b2b08b0aeddba49c609fe7957ba2e33449882cb186a180bc60682fa9" +"checksum clang-sys 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff7c2d1502c65748c7221f43ce670b3ba5c697acebfeb85a580827daca6975fc" "checksum clap 2.25.0 (registry+https://github.com/rust-lang/crates.io-index)" = "867a885995b4184be051b70a592d4d70e32d7a188db6e8dff626af286a962771" "checksum cmake 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)" = "b8ebbb35d3dc9cd09497168f33de1acb79b265d350ab0ac34133b98f8509af1f" "checksum coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c06169f5beb7e31c7c67ebf5540b8b472d23e3eade3b2ec7d1f5b504a85f91bd" @@ -1269,6 +1431,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850" "checksum dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "80c8b71fd71146990a9742fc06dcbbde19161a267e0ad4e572c35162f4578c90" "checksum either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18785c1ba806c258137c937e44ada9ee7e69a37e3c72077542cd2f069d78562a" +"checksum env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3ddf21e73e016298f5cb37d6ef8e8da8e39f91f9ec8b0df44b7deb16a9f8cd5b" "checksum error 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "a6e606f14042bb87cc02ef6a14db6c90ab92ed6f62d87e69377bc759fd7987cc" "checksum error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d9435d864e017c3c6afeac1654189b06cdb491cf2ff73dbf0d73b0f292f42ff8" "checksum filetime 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "5363ab8e4139b8568a6237db5248646e5a8a2f89bd5ccb02092182b11fd3e922" @@ -1293,6 +1456,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3b37545ab726dd833ec6420aaba8231c5b320814b9029ad585555d2a03e94fbf" "checksum lazycell 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ce12306c4739d86ee97c23139f3a34ddf0387bbf181bc7929d287025a8c3ef6b" "checksum libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)" = "38f5c2b18a287cf78b4097db62e20f43cace381dc76ae5c0a3073067f78b7ddc" +"checksum libloading 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "be99f814beb3e9503a786a592c909692bb6d4fc5a695f6ed7987223acfbd5194" "checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" "checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" "checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4" @@ -1306,6 +1470,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum mount 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "32245731923cd096899502fc4c4317cfd09f121e80e73f7f576cf3777a824256" "checksum net2 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)" = "bc01404e7568680f1259aa5729539f221cb1e6d047a0d9053cab4be8a73b5d67" "checksum nix 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bfb3ddedaa14746434a02041940495bf11325c22f6d36125d3bdd56090d50a79" +"checksum nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b8c256fd9471521bcb84c3cdba98921497f1a331cbc15b8030fc63b82050ce" "checksum notify 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "298d4401ff2c6cebb7f8944c90288647c89ce59029d43b439444cf1067df55e1" "checksum num 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "2c3a3dc9f30bf824141521b30c908a859ab190b76e20435fcd89f35eb6583887" "checksum num-integer 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)" = "ef1a4bf6f9174aa5783a9b4cc892cacd11aebad6c69ad027a0b65c6ca5f8aa37" @@ -1314,12 +1479,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aec53c34f2d0247c5ca5d32cca1478762f301740468ee9ee6dcb7a0dd7a0c584" "checksum onig 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee619da9cf707b167098e84fb00f10db61d5a662d1d29b59822bcac3a81553dd" "checksum onig_sys 63.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "531682ab45a2cd40eff91f29340dae975f25336d2b61e624adabed39e61d7fb3" +"checksum peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" "checksum percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de154f638187706bde41d9b4738748933d64e6b37bdbffc0b47a97d16a6ae356" "checksum pest 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3e2e823a5967bb4cdc6d3e46f47baaf4ecfeae44413a642b74ad44e59e49c7f6" "checksum pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3a8b4c6b8165cd1a1cd4b9b120978131389f64bdaf456435caa41e630edba903" "checksum plist 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1e2f7e9574aabcf57bc5e9f602caabdffffa8179b0c130a039f7895fea3dbdb5" "checksum plugin 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "1a6a0dc3910bc8db877ffed8e457763b317cf880df4ae19109b9f77d277cf6e0" "checksum pulldown-cmark 0.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "378e941dbd392c101f2cb88097fa4d7167bc421d4b88de3ff7dbee503bc3233b" +"checksum quasi 0.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18c45c4854d6d1cf5d531db97c75880feb91c958b0720f4ec1057135fec358b3" +"checksum quasi_codegen 0.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "51b9e25fa23c044c1803f43ca59c98dac608976dd04ce799411edd58ece776d4" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" "checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d" "checksum rayon 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b614fe08b6665cb9a231d07ac1364b0ef3cb3698f1239ee0c4c3a88a524f54c8" @@ -1331,6 +1499,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" "checksum same-file 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d931a44fdaa43b8637009e7632a02adc4f2b2e0733c08caa4cf00e8da4a117a7" +"checksum sass-rs 0.0.18 (git+https://github.com/compass-rs/sass-rs)" = "" +"checksum sass-sys 0.3.0 (git+https://github.com/compass-rs/sass-rs)" = "" "checksum scopeguard 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c79eb2c3ac4bc2507cda80e7f3ac5b88bd8eae4c0914d5663e6a8933994be918" "checksum sequence_trie 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c915714ca833b1d4d6b8f6a9d72a3ff632fe45b40a8d184ef79c81bec6327eed" "checksum serde 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "c2f530d36fb84ec48fb7146936881f026cdbf4892028835fd9398475f82c1bb4" @@ -1346,6 +1516,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" "checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" "checksum syntect 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2f75613d1df82e2f8020e86c260a46bdef180d16ac8d2febe43194037d6fe76" +"checksum syntex 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a8f5e3aaa79319573d19938ea38d068056b826db9883a5d47f86c1cecc688f0e" +"checksum syntex_errors 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)" = "867cc5c2d7140ae7eaad2ae9e8bf39cb18a67ca651b7834f88d46ca98faadb9c" +"checksum syntex_pos 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)" = "13ad4762fe52abc9f4008e85c4fb1b1fe3aa91ccb99ff4826a439c7c598e1047" +"checksum syntex_syntax 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6e0e4dbae163dd98989464c23dd503161b338790640e11537686f2ef0f25c791" "checksum tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "87974a6f5c1dfb344d733055601650059a3363de2a6104819293baff662132d6" "checksum tera 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)" = "62736a6d748fd2c5a8b4be21010e37d79f78aea3c2e07a9e13ff5c70864a3129" "checksum term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "fa63644f74ce96fbeb9b794f66aff2a52d601cbd5e80f4b97123e3899f4570f1" diff --git a/components/config/src/lib.rs b/components/config/src/lib.rs index 37b522c4..87b07a24 100644 --- a/components/config/src/lib.rs +++ b/components/config/src/lib.rs @@ -43,6 +43,8 @@ pub struct Config { /// The default template can be overridden by creating a `anchor-link.html` template and CSS will need to be /// written if you turn that on. pub insert_anchor_links: Option, + /// Whether to compile the `sass` directory and output the css files into the static folder + pub compile_sass: Option, /// All user params set in [extra] in the config pub extra: Option>, @@ -72,6 +74,7 @@ impl Config { set_default!(config.generate_tags_pages, false); set_default!(config.generate_categories_pages, false); set_default!(config.insert_anchor_links, false); + set_default!(config.compile_sass, false); match config.highlight_theme { Some(ref t) => { @@ -131,6 +134,7 @@ impl Default for Config { generate_tags_pages: Some(true), generate_categories_pages: Some(true), insert_anchor_links: Some(false), + compile_sass: Some(false), extra: None, } } diff --git a/components/site/Cargo.toml b/components/site/Cargo.toml index 5403d18a..ed4ff7e9 100644 --- a/components/site/Cargo.toml +++ b/components/site/Cargo.toml @@ -20,5 +20,9 @@ pagination = { path = "../pagination" } taxonomies = { path = "../taxonomies" } content = { path = "../content" } +[target.'cfg(not(target_os = "windows"))'.dependencies] +sass-rs = { git = "https://github.com/compass-rs/sass-rs.git" } + + [dev-dependencies] tempdir = "0.3" diff --git a/components/site/src/lib.rs b/components/site/src/lib.rs index 153c9f31..13a0f2b9 100644 --- a/components/site/src/lib.rs +++ b/components/site/src/lib.rs @@ -6,6 +6,10 @@ extern crate serde; #[macro_use] extern crate serde_derive; +#[cfg(not(target_os = "windows"))] +extern crate sass_rs; + +#[macro_use] extern crate errors; extern crate config; extern crate utils; @@ -27,9 +31,12 @@ use glob::glob; use tera::{Tera, Context}; use walkdir::WalkDir; +#[cfg(not(target_os = "windows"))] +use sass_rs::{Options, compile_string}; + use errors::{Result, ResultExt}; use config::{Config, get_config}; -use utils::fs::{create_file, create_directory, ensure_directory_exists}; +use utils::fs::{create_file, read_file, create_directory, ensure_directory_exists}; use content::{Page, Section, populate_previous_and_next_pages, sort_pages}; use templates::{GUTENBERG_TERA, global_fns, render_redirect_template}; use front_matter::{SortBy, InsertAnchor}; @@ -434,9 +441,45 @@ impl Site { self.render_categories()?; self.render_tags()?; + if self.config.compile_sass.unwrap() { + self.compile_sass()?; + } + self.copy_static_directory() } + #[cfg(not(target_os = "windows"))] + pub fn compile_sass(&self) -> Result<()> { + ensure_directory_exists(&self.output_path)?; + + let base_path = self.base_path.to_string_lossy().replace("\\", "/"); + let sass_glob = format!("{}/{}", base_path, "sass/**/*.scss"); + let files = glob(&sass_glob) + .unwrap() + .filter_map(|e| e.ok()) + .filter(|ref entry| !entry.as_path().file_name().unwrap().to_string_lossy().starts_with("_")) + .collect::>(); + + for file in files { + let name = file.as_path().file_stem().unwrap().to_string_lossy(); + let content = read_file(&file)?; + let css = match compile_string(&content, Options::default()) { + Ok(c) => c, + Err(e) => bail!(e) + }; + + create_file(&self.output_path.join(format!("{}.css", name)), &css)?; + } + + Ok(()) + } + + #[cfg(target_os = "windows")] + pub fn compile_sass(&self) -> Result<()> { + println!("Sass not supported on Windows yet."); + Ok(()) + } + pub fn render_aliases(&self) -> Result<()> { for page in self.pages.values() { if let Some(ref aliases) = page.meta.aliases { @@ -685,5 +728,3 @@ impl Site { .reduce(|| Ok(()), Result::and) } } - - diff --git a/components/site/test_site/config.toml b/components/site/test_site/config.toml index 4d058c3f..982d4f51 100644 --- a/components/site/test_site/config.toml +++ b/components/site/test_site/config.toml @@ -1,6 +1,7 @@ title = "My site" base_url = "https://replace-this-with-your-url.com" highlight_code = true +compile_sass = true [extra.author] name = "Vincent Prouillet" diff --git a/components/site/test_site/sass/blog.scss b/components/site/test_site/sass/blog.scss new file mode 100644 index 00000000..ec8af3eb --- /dev/null +++ b/components/site/test_site/sass/blog.scss @@ -0,0 +1,7 @@ +body { + background: red; + + .container { + background: blue; + } +} diff --git a/src/cmd/serve.rs b/src/cmd/serve.rs index 4404eaa7..18804e37 100644 --- a/src/cmd/serve.rs +++ b/src/cmd/serve.rs @@ -44,6 +44,7 @@ enum ChangeKind { Content, Templates, StaticFiles, + Sass, } // Uglified using uglifyjs @@ -105,6 +106,9 @@ pub fn serve(interface: &str, port: &str, config_file: &str) -> Result<()> { watcher.watch("templates/", RecursiveMode::Recursive) .chain_err(|| "Can't watch the `templates` folder. Does it exist?")?; + // Sass support is optional so don't make it an error to no have a sass folder + let _ = watcher.watch("sass/", RecursiveMode::Recursive); + let ws_address = format!("{}:{}", interface, "1112"); // Start a webserver that serves the `public` directory @@ -138,7 +142,11 @@ pub fn serve(interface: &str, port: &str, config_file: &str) -> Result<()> { let pwd = format!("{}", env::current_dir().unwrap().display()); - println!("Listening for changes in {}/{{content, static, templates}}", pwd); + if site.config.compile_sass.unwrap() { + println!("Listening for changes in {}/{{content, static, templates, sass}}", pwd); + } else { + println!("Listening for changes in {}/{{content, static, templates}}", pwd); + } println!("Web server is available at http://{}", address); println!("Press Ctrl+C to stop\n"); @@ -175,6 +183,10 @@ pub fn serve(interface: &str, port: &str, config_file: &str) -> Result<()> { rebuild_done_handling(&broadcaster, site.copy_static_file(&path), &p); } }, + (ChangeKind::Sass, p) => { + console::info(&format!("-> Sass file changed {}", path.display())); + rebuild_done_handling(&broadcaster, site.compile_sass(), &p); + }, }; console::report_elapsed_time(start); } @@ -226,6 +238,8 @@ fn detect_change_kind(pwd: &str, path: &Path) -> (ChangeKind, String) { ChangeKind::Content } else if path_str.starts_with("/static") { ChangeKind::StaticFiles + } else if path_str.starts_with("/sass") { + ChangeKind::Sass } else { unreachable!("Got a change in an unexpected path: {}", path_str); };