Skip to content

Bundle bulma CSS #1086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/bulma.min.css

Large diffs are not rendered by default.

41 changes: 25 additions & 16 deletions src/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ impl ConfigFile {
}
}

static BULMA_VERSION: &str = "0.9.1";

fn load_template(path: &str) -> String {
fs::read_to_string(path).unwrap()
}
Expand Down Expand Up @@ -260,14 +258,6 @@ fn get_dirs_result(global: Arc<Mutex<HtmlGlobalStats>>, rel_path: &Path, stats:

use tera::{Context, Tera};

fn make_context() -> Context {
let mut ctx = Context::new();
let ver = std::env::var("BULMA_VERSION").map_or(BULMA_VERSION.into(), |v| v);
ctx.insert("bulma_version", &ver);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd keep this and add an env var or a feature for the bundling.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the advantages of having this environment variable instead of always bundling the CSS?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some people would prefer not bundling it, I guess.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also if you want to go the extra mile, you may add a cli option to pass the css file.

@marco-c if you are fine with the idea of bundling I can accept this patch.


ctx
}

pub fn gen_index(
tera: &Tera,
global: &HtmlGlobalStats,
Expand All @@ -286,11 +276,12 @@ pub fn gen_index(
Ok(f) => f,
};

let mut ctx = make_context();
let mut ctx = Context::new();
let empty: &[&str] = &[];
ctx.insert("date", &conf.date);
ctx.insert("current", "top_level");
ctx.insert("parents", empty);
ctx.insert("bulma_path", "bulma.min.css");
ctx.insert("stats", &global.stats);
ctx.insert("precision", &precision);
ctx.insert("items", &global.dirs);
Expand All @@ -304,6 +295,22 @@ pub fn gen_index(
return;
}

let bulma_file = output.join("bulma.min.css");
let mut bulma_stream = match File::create(&bulma_file) {
Err(_) => {
eprintln!("Cannot create file {:?}", output_file);
return;
}
Ok(f) => f,
};
if bulma_stream
.write_all(include_bytes!("bulma.min.css"))
.is_err()
{
eprintln!("Cannot write the file {:?}", bulma_file);
return;
}

for (dir_name, dir_stats) in global.dirs.iter() {
gen_dir_index(
tera,
Expand All @@ -329,6 +336,7 @@ pub fn gen_dir_index(
let index = Path::new(dir_name).join("index.html");
let layers = index.components().count() - 1;
let prefix = "../".repeat(layers) + "index.html";
let bulma_path = "../".repeat(layers) + "bulma.min.css";
let output_file = output.join(index);
create_parent(&output_file);
let mut output = match File::create(&output_file) {
Expand All @@ -339,9 +347,9 @@ pub fn gen_dir_index(
Ok(f) => f,
};

let mut ctx = make_context();
let mut ctx = Context::new();
ctx.insert("date", &conf.date);
ctx.insert("bulma_version", BULMA_VERSION);
ctx.insert("bulma_path", &bulma_path);
ctx.insert("current", dir_name);
ctx.insert("parents", &[(prefix, "top_level")]);
ctx.insert("stats", &dir_stats.stats);
Expand Down Expand Up @@ -395,12 +403,13 @@ fn gen_html(
let base_url = get_base(rel_path);
let filename = rel_path.file_name().unwrap().to_str().unwrap();
let parent = rel_path.parent().unwrap().to_str().unwrap().to_string();
let bulma_path = format!("{base_url}bulma.min.css");
let mut index_url = base_url;
index_url.push_str("index.html");

let mut ctx = make_context();
let mut ctx = Context::new();
ctx.insert("date", &conf.date);
ctx.insert("bulma_version", BULMA_VERSION);
ctx.insert("bulma_path", &bulma_path);
ctx.insert("current", filename);
ctx.insert(
"parents",
Expand Down Expand Up @@ -540,7 +549,7 @@ pub fn gen_badge(tera: &Tera, stats: &HtmlStats, conf: &Config, output: &Path, s
Ok(f) => f,
};

let mut ctx = make_context();
let mut ctx = Context::new();
ctx.insert(
"current",
&(get_percentage_of_covered_lines(stats.covered_lines, stats.total_lines) as usize),
Expand Down
2 changes: 1 addition & 1 deletion src/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}{% endblock title %}</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@{{ bulma_version }}/css/bulma.min.css">
<link rel="stylesheet" href="{{ bulma_path }}">
{%- endblock head -%}
</head>
<body>
Expand Down