From 8845abfe1e83e005830e5d375a9cbc4861a2bdb3 Mon Sep 17 00:00:00 2001 From: okno Date: Sun, 15 Sep 2019 15:36:01 +0200 Subject: [PATCH] add build script --- .gitignore | 1 + Cargo.toml | 7 ++++++ build/build.rs | 26 +++++++++++++++++++++++ build/themes.sh | 8 +++++++ config.toml | 2 +- {plugin => neovim}/illumination.vim | 0 src/html/theme.rs | 26 +++++++++++++++++++++++ src/main.rs | 1 + src/preview.rs | 5 ++--- src/settings.rs | 33 ++++++++++++++++++++++------- 10 files changed, 97 insertions(+), 12 deletions(-) create mode 100644 build/build.rs create mode 100755 build/themes.sh rename {plugin => neovim}/illumination.vim (100%) create mode 100644 src/html/theme.rs diff --git a/.gitignore b/.gitignore index bb421d2..b35d23e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ **/*.rs.bk .idea Cargo.lock +themes/ diff --git a/Cargo.toml b/Cargo.toml index 0cc0ef6..a00d9aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ name = "illumination" version = "0.2.0" authors = ["okno "] edition = "2018" +build = "build/build.rs" [dependencies] neovim-lib = "0.6" @@ -15,6 +16,12 @@ glib= "0.8" gio = "0.7" config = "0.9" lazy_static = "1.4.0" +dirs = "2.0" + + +[build-dependencies] +dirs = "2.0" + [dependencies.log] version = "0.4" diff --git a/build/build.rs b/build/build.rs new file mode 100644 index 0000000..c4caec6 --- /dev/null +++ b/build/build.rs @@ -0,0 +1,26 @@ +use dirs; +use std::fs; +use std::process::Command; + +fn main() { + println!("Starting to build Illumination."); + println!("Fetching default themes."); + + Command::new("sh") + .args(&["build/themes.sh"]) + .status() + .expect("Error fetching default themes"); + + let illumination_config_dir = format!( + "{}/illumination/", + dirs::config_dir().unwrap().to_str().unwrap() + ); + + println!("Copying themes to user config dir."); + fs::create_dir_all(&illumination_config_dir).unwrap(); + + Command::new("cp") + .args(&["-R", "themes", &illumination_config_dir]) + .status() + .expect("Error moving themes to user config dir"); +} diff --git a/build/themes.sh b/build/themes.sh new file mode 100755 index 0000000..4a014fa --- /dev/null +++ b/build/themes.sh @@ -0,0 +1,8 @@ +mkdir -p .local/share/nvim/site/plugin/ +mv neovim/illumination .local/share/nvim/site/plugin/illumination.vim +mkdir -p themes/default +curl -X GET https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.10/highlight.min.js > themes/default/hljs.min.js +curl -X GET https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/languages/rust.min.js > themes/default/hljs-rust.js +curl -X GET https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.10/styles/default.min.css > themes/default/hljs.min.css +curl -X GET https://gist.githubusercontent.com/ryangray/1882525/raw/2a6e53f645b960f0bed16d686ba3df36505f839f/buttondown.css > themes/default/style.css +curl -X GET https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css > themes/github.css \ No newline at end of file diff --git a/config.toml b/config.toml index 6fc853e..5d2bc75 100644 --- a/config.toml +++ b/config.toml @@ -1,2 +1,2 @@ -theme = "github" +theme = "default" note-directory = "/home/okno/_Workshop/Notes" \ No newline at end of file diff --git a/plugin/illumination.vim b/neovim/illumination.vim similarity index 100% rename from plugin/illumination.vim rename to neovim/illumination.vim diff --git a/src/html/theme.rs b/src/html/theme.rs new file mode 100644 index 0000000..4a7f5ef --- /dev/null +++ b/src/html/theme.rs @@ -0,0 +1,26 @@ +use std::path::Path; +use std::env; +use self::Theme::*; +use std::fs; +use dirs; + +pub enum Theme { + Bootstrap +} + +impl Theme { + fn path(self) -> String { + let home = env::var("HOME").unwrap_or_else(|_| panic!("Unable to locate home directory")); + match self { + Bootstrap => format!("{}/.config/illumination/themes/boostrap", home) + } + } + + pub fn rel_path(self) { + + let current = fs::canonicalize(Path::new("./")).expect("maeoimoireza"); + println!("{:?}", current); + let abs_path = Path::new(&self.path()); + + } +} diff --git a/src/main.rs b/src/main.rs index f5379a0..840ff65 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ extern crate log; extern crate lazy_static; extern crate config; +extern crate dirs; mod nvim; mod preview; diff --git a/src/preview.rs b/src/preview.rs index 1ec0cfa..5eee86f 100644 --- a/src/preview.rs +++ b/src/preview.rs @@ -1,8 +1,8 @@ +use crate::settings::JS; +use crate::settings::THEME; use horrorshow::helper::doctype; use horrorshow::Raw; use pulldown_cmark::{html, Options, Parser}; -use crate::settings::THEME; -use crate::settings::JS; /// In goes markdown text; out comes HTML text. fn mark_to_html(markdown: &str) -> String { @@ -19,7 +19,6 @@ fn mark_to_html(markdown: &str) -> String { /// In goes markdown text; out comes stylish HTML text. pub fn render(markdown: &str, scroll: i64) -> String { - let scroll = format!( "function scrollDown() {{ window.scrollTo(0, {}); }}; window.onload = scrollDown;", scroll diff --git a/src/settings.rs b/src/settings.rs index a297115..311fdd4 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -1,10 +1,10 @@ use config::{Config, File as ConfigFile}; +use dirs; use lazy_static; use std::collections::HashMap; -use std::sync::RwLock; use std::fs::File; use std::io::prelude::*; -use std::env; +use std::sync::RwLock; lazy_static! { static ref SETTINGS: RwLock = RwLock::new({ @@ -17,9 +17,13 @@ lazy_static! { // Unfortunatly is seems webkit does accept any href from the file system, to hack our way around this we just preload css and hljs // see : https://github.com/gtk-rs/webkit2gtk-rs/issues/56 pub static ref THEME: String = { - let home = env::var("HOME").unwrap_or_else(|_| panic!("Unable to locate home directory")); - let mut style = File::open(&format!("{}/.config/illumination/themes/default/style.css", home)).expect("Error opening default style.css"); - let mut hljs_css = File::open(&format!("{}/.config/illumination/themes/default/hljs.min.css", home)).expect("Error opening hljs.min.css"); + let config_dir = dirs::config_dir().unwrap(); + let config_dir = config_dir + .to_str() + .unwrap(); + + let mut style = File::open(&format!("{}/illumination/themes/default/style.css", config_dir)).expect("Error opening default style.css"); + let mut hljs_css = File::open(&format!("{}/illumination/themes/default/hljs.min.css", config_dir)).expect("Error opening hljs.min.css"); let mut contents = String::new(); style.read_to_string(&mut contents).expect("Unable to write css theme"); hljs_css.read_to_string(&mut contents).expect("Unable to write css theme"); @@ -27,14 +31,27 @@ lazy_static! { }; pub static ref JS: String = { - let home = env::var("HOME").unwrap_or_else(|_| panic!("Unable to locate home directory")); - let mut hljs = File::open(format!("{}/.config/illumination/themes/default/hljs.js", home)).expect("Error opening hljs.js"); - let mut hljs_rust = File::open(format!("{}/.config/illumination/themes/default/hljs-rust.js", home)).expect("Error opening rust hljs-rust.js"); + let config_dir = dirs::config_dir().unwrap(); + let config_dir = config_dir + .to_str() + .unwrap(); + + let mut hljs = File::open(format!("{}/illumination/themes/default/hljs.min.js", config_dir)).expect("Error opening hljs.min.js"); + let mut hljs_rust = File::open(format!("{}/illumination/themes/default/hljs-rust.js", config_dir)).expect("Error opening rust hljs-rust.js"); let mut contents = String::new(); hljs.read_to_string(&mut contents).expect("Unable to write hljs"); hljs_rust.read_to_string(&mut contents).expect("Unable to write hljs rust"); contents }; + + pub static ref THEME_DIR: String = { + + let config_dir = dirs::config_dir().unwrap(); + let config_dir = config_dir + .to_str() + .unwrap(); + format!("{}/themes", config_dir) + }; } // dump config.toml