1use ramhorns::Content;
2
3use crate::config::{Core, Shell, Workspace};
4
5pub enum Context {
6 Core(CoreContext),
7 Shell(ShellContext),
8}
9
10#[derive(Content)]
11pub struct CoreContext {
12 pub workspace: String,
13 pub core_name: String,
14 pub core_name_dashes: String,
15}
16
17impl CoreContext {
18 pub fn new(workspace: &Workspace, core: &Core) -> CoreContext {
19 Self {
20 workspace: workspace.name.to_ascii_lowercase().replace(' ', "_"),
21 core_name: core.name.clone(),
22 core_name_dashes: core.name.replace('_', "-"),
23 }
24 }
25}
26
27#[derive(Content)]
28pub struct ShellContext {
29 pub workspace: String,
30 pub core_dir: String,
31 pub core_name: String,
32 pub type_gen: String,
33 pub shell_dir: String,
34 pub shell_name: String,
35 pub shell_name_dashes: String,
36}
37
38impl ShellContext {
39 pub fn new(workspace: &Workspace, core: &Core, shell: &Shell) -> ShellContext {
40 Self {
41 workspace: workspace.name.to_ascii_lowercase().replace(' ', "_"),
42 core_dir: core.source.to_string_lossy().to_string(),
43 core_name: core.name.replace('-', "_"),
44 type_gen: core
45 .type_gen
46 .as_ref()
47 .map(|x| x.to_string_lossy().to_string())
48 .unwrap_or_default(),
49 shell_dir: shell.source.to_string_lossy().to_string(),
50 shell_name: shell.name.replace('-', "_"),
51 shell_name_dashes: shell.name.replace('_', "-"),
52 }
53 }
54}