Skip to content

Commit

Permalink
add build script
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed Sep 15, 2019
1 parent b9439d4 commit 8845abf
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
**/*.rs.bk
.idea
Cargo.lock
themes/
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "illumination"
version = "0.2.0"
authors = ["okno <paul.delafosse@protonmail.com>"]
edition = "2018"
build = "build/build.rs"

[dependencies]
neovim-lib = "0.6"
Expand All @@ -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"
Expand Down
26 changes: 26 additions & 0 deletions build/build.rs
Original file line number Diff line number Diff line change
@@ -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");
}
8 changes: 8 additions & 0 deletions build/themes.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
theme = "github"
theme = "default"
note-directory = "/home/okno/_Workshop/Notes"
File renamed without changes.
26 changes: 26 additions & 0 deletions src/html/theme.rs
Original file line number Diff line number Diff line change
@@ -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());

}
}
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern crate log;
extern crate lazy_static;

extern crate config;
extern crate dirs;

mod nvim;
mod preview;
Expand Down
5 changes: 2 additions & 3 deletions src/preview.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
Expand Down
33 changes: 25 additions & 8 deletions src/settings.rs
Original file line number Diff line number Diff line change
@@ -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<Config> = RwLock::new({
Expand All @@ -17,24 +17,41 @@ 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");
contents
};

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
Expand Down

0 comments on commit 8845abf

Please sign in to comment.