Skip to content

Commit

Permalink
fix: preventing html escaping + module renaming (#139)
Browse files Browse the repository at this point in the history
Closes #138
  • Loading branch information
vigenere23 committed Jan 19, 2024
1 parent dc2dc39 commit 2988c1e
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion disma-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ path = "src/main.rs"
[dependencies]
disma = { path = "../disma", version = "0.16.2" }
clap = { version = "4.4.16", features = ["derive"] }
handlebars = "4.3.3"
handlebars = "5.1.1"
serde = { version = "1.0.143", features = ["derive"] }
serde_json = "1.0.83"
serde_yaml = "0.9.9"
Expand Down
4 changes: 2 additions & 2 deletions disma-cli/src/actions.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::sync::Arc;

use super::{
injector::{Get, Injector},
services::{
commands::{
apply_changes::ApplyChanges, compile_config::CompileConfig, list_guilds::ListGuilds,
save_guild::SaveExistingGuild,
},
injector::{Get, Injector},
};

pub fn apply_changes(guild_id: &str, file_path: &str, dry_run: bool, force: bool) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,21 @@ pub struct CompileConfig {
}

impl CompileConfig {
const TEMPLATE_NAME: &'static str = "base";

pub fn new(deserializer: Arc<Deserializer>) -> Self {
Self { deserializer }
}

pub fn run(&self, template_file: &str, vars_file: &str, output_file: &str, force: bool) {
let template = fs::read_to_string(template_file).unwrap();
// TODO context should probably be a Hash instead or a serde_yaml::Value
// TODO context should probably be a Hash instead of a serde_yaml::Value
let context: Value = self.deserializer.deserialize(Path::new(vars_file));

println!();
println!("{}", "➜ ⚙️ Compiling guild config...".bold());
let mut renderer = Handlebars::new();
renderer
.register_template_string(Self::TEMPLATE_NAME, &template)
.unwrap();
renderer.register_escape_fn(|s| s.to_string()); // preventing default HTML escaping

let rendered = renderer.render(Self::TEMPLATE_NAME, &context).unwrap();
let rendered = renderer.render_template(&template, &context).unwrap();

let output_path = Path::new(output_file);
println!(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions disma-cli/src/injector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ use disma::{
};

use crate::{
commands::{
apply_changes::ApplyChanges, compile_config::CompileConfig, list_guilds::ListGuilds,
save_guild::SaveExistingGuild,
},
infra::diff::{
event::CliChangeEventListener,
formatter::{DiffFormater, DiffFormaterRef},
},
services::{
apply_changes::ApplyChanges, compile_config::CompileConfig, list_guilds::ListGuilds,
save_guild::SaveExistingGuild,
},
utils::{
env::required_env,
io::{Deserializer, Serializer},
Expand Down
2 changes: 1 addition & 1 deletion disma-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mod actions;
mod args;
mod commands;
mod infra;
mod injector;
mod services;
mod utils;

use clap::Parser;
Expand Down

0 comments on commit 2988c1e

Please sign in to comment.