Updates coverage, adds doc and finishes testing
This commit is contained in:
parent
f62e5d7cc1
commit
2b47e0298c
|
|
@ -1,7 +1,7 @@
|
|||
[config]
|
||||
[info]
|
||||
name = "Cyberpunk"
|
||||
version = "v0.1"
|
||||
skills = "data/cyberpunk.toml"
|
||||
# skills = "data/cyberpunk.toml"
|
||||
|
||||
[data]
|
||||
head = """<head>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,108 @@
|
|||
[info]
|
||||
name = "cyberpunk_skills"
|
||||
version = "0.1"
|
||||
|
||||
[root]
|
||||
contentheader = ""
|
||||
content = ""
|
||||
contentfooter = "</div>\n"
|
||||
cssheader = "div.sheet-tab-content { display: none; }"
|
||||
csscontent ="\ninput.sheet-tab{node.number}:checked ~ div.sheet-tab{node.number},"
|
||||
cssfooter = "\n{\n display: block;\n}\n"
|
||||
|
||||
[section]
|
||||
contentheader = "<input type=\"radio\" name=\"attr_tab\" class=\"sheet-tab sheet-tab{self.number}\" value=\"{self.number}\" title=\"{self.name}\" {self.checked}/><span></span>\n"
|
||||
content = "<!-- {self.pname} -->\n<div class=\"sheet-tab-content sheet-tab{self.number}\">\n"
|
||||
contentfooter = ""
|
||||
cssheader = "\ninput.sheet-secondary_{node.pname}_tab{child.number}:checked ~ div.sheet-secondary_{node.pname}_tab{child.number},"
|
||||
csscontent = ""
|
||||
cssfooter = "\n{\n display: block;\n}"
|
||||
|
||||
[subsection]
|
||||
contentheader = """ <input type="radio" name="secondary_{self.parent.pname}_tab" class="small_tab secondary_{self.parent.pname}_tab{self.number}" value="{self.number}" {self.checked} title="{self.name}" />\n"""
|
||||
content = """<div class="sheet-tab-content sheet-secondary_{self.parent.pname}_tab{self.number}\">
|
||||
<!-- {self.name} -->\n <h3>{self.name}</h3>\n"."""
|
||||
contentfooter = " </div>\n"
|
||||
cssheader = ""
|
||||
csscontent = ""
|
||||
cssfooter = ""
|
||||
|
||||
[skill]
|
||||
contentheader = ""
|
||||
content = """ <!--{self.name} -->
|
||||
<input class="sheet-skill_name" style="margin-right: 4px;" type="text" name="attr_{self.parent.pname}_skill_{self.pname}" disabled="true" value="{self.name}" />
|
||||
<input class="sheet-skill_level" type="number" min="0" value="0" name="attr_{self.parent.pname}_skillcost_{self.pname}" title="Coût de la compétence" />
|
||||
<input class="sheet-skill_level" value="0" style="margin-right: 4px;" type="number" min="0" max="10" name="attr_{self.parent.pname}_skilllevel_{self.pname}" title="Niveau dans la compétence" />
|
||||
<select class="sheet-skill_select" style="margin-right:4px" name="attr_skill_{self.parent.pname}_attribute_select_{self.pname}">
|
||||
<option value="@{{base-Force}} + @{{exal-Force}}">For</option>
|
||||
<option value="@{{base-Agilite}} + @{{exal-Agilite}}">Agi</option>
|
||||
<option value="@{{base-Perception}} + @{{exal-Perception}}">Per</option>
|
||||
<option value="@{{base-Charisme}} + @{{exal-Charisme}}">Cha</option>
|
||||
<option value="@{{base-Intelligence}} + @{{exal-Intelligence}}">Int</option>
|
||||
<option value="@{{base-Perception}} + @{{exal-Perception}}">Per</option>
|
||||
<option value="@{{base-Volonte}} + @{{exal-Volonte}}">Vol</option>
|
||||
<option value="@{{base-Accred}} + @{{exal-Accred}}">Acc</option>
|
||||
<option value="@{{base-Chance}} + @{{exal-Chance}}">Chn</option>
|
||||
</select>
|
||||
<button type='roll' class="sheet-skillbutton" value="&{{template:d10skillcheck}} {{{{name=@{{character_name}}}}}} {{{{roll_name=@{{{self.parent.pname}_skill_{self.pname}}}}}}} {{{{dice_name=@{{dice}}}}}} {{{{result=[[@{{{self.parent.pname}_skilllevel_{self.pname}}}+(@{{skill_{self.parent.pname}_attribute_select_{self.pname}}})-d@{{dice}}cs1cf@{{dice}}]]}}}} {{{{threshold=[[@{{{self.parent.pname}_skilllevel_{self.pname}}}+(@{{skill_{self.parent.pname}_attribute_select_{self.pname}}})]]}}}}"></button>
|
||||
<br/>\n"""
|
||||
contentfooter = ""
|
||||
cssheader = ""
|
||||
csscontent = ""
|
||||
cssfooter = ""
|
||||
|
||||
[subskill]
|
||||
contentheader = ""
|
||||
content = """ <!--{self.name} -->
|
||||
<input class="sheet-skill_name" style="margin-right: 4px;" type="text" name="attr_{self.parent.pname}_skill_{self.pname}" disabled="true" value="{self.name}" />
|
||||
<input class="sheet-skill_level" type="number" min="0" value="0" name="attr_{self.parent.pname}_skillcost_{self.pname}" title="Coût de la compétence" />
|
||||
<input class="sheet-skill_level" value="0" style="margin-right: 4px;" type="number" min="0" max="10" name="attr_{self.parent.pname}_skilllevel_{self.pname}" title="Niveau dans la compétence" />
|
||||
<select class="sheet-skill_select" style="margin-right:4px" name="attr_skill_{self.parent.pname}_attribute_select_{self.pname}">
|
||||
<option value="@{{base-Force}} + @{{exal-Force}}">For</option>
|
||||
<option value="@{{base-Agilite}} + @{{exal-Agilite}}">Agi</option>
|
||||
<option value="@{{base-Perception}} + @{{exal-Perception}}">Per</option>
|
||||
<option value="@{{base-Charisme}} + @{{exal-Charisme}}">Cha</option>
|
||||
<option value="@{{base-Intelligence}} + @{{exal-Intelligence}}">Int</option>
|
||||
<option value="@{{base-Perception}} + @{{exal-Perception}}">Per</option>
|
||||
<option value="@{{base-Volonte}} + @{{exal-Volonte}}">Vol</option>
|
||||
<option value="@{{base-Accred}} + @{{exal-Accred}}">Acc</option>
|
||||
<option value="@{{base-Chance}} + @{{exal-Chance}}">Chn</option>
|
||||
</select>
|
||||
<button type='roll' class="sheet-skillbutton" value="&{{template:d10skillcheck}} {{{{name=@{{character_name}}}}}} {{{{roll_name=@{{{self.parent.pname}_skill_{self.pname}}}}}}} {{{{dice_name=@{{dice}}}}}} {{{{result=[[@{{{self.parent.pname}_skilllevel_{self.pname}}}+(@{{skill_{self.parent.pname}_attribute_select_{self.pname}}}+@{{{self.parent.pname}_skilllevel_{self.superskill.pname}}})-d@{{dice}}cs1cf@{{dice}}]]}}}} {{{{threshold=[[@{{{self.parent.pname}_skilllevel_{self.pname}}}+@{{{self.parent.pname}_skilllevel_{self.superskill.pname}}}+(@{{skill_{self.parent.pname}_attribute_select_{self.pname}}})]]}}}}"></button>
|
||||
<br/>\n"""
|
||||
contentfooter = ""
|
||||
cssheader = ""
|
||||
csscontent = ""
|
||||
cssfooter = ""
|
||||
|
||||
[repeating]
|
||||
contentheader = ""
|
||||
content = """ <!-- {node.pname} -->
|
||||
<fieldset class="repeating_{node.pname}-skills">
|
||||
<input class="sheet-skill_name" type="text" name="attr_{node.pname}_skillname" />
|
||||
<input type="number" name="attr_{node.pname}_skillcost" title="Coût de la compétence" />
|
||||
<input type="number" min="-10" max="10" name="attr_{node.pname}_skilllevel" title="Niveau dans la compétence" />
|
||||
<select class="sheet-skill_select" name="attr_{node.pname}_attribute_select">
|
||||
<option value="@{{base-Force}} + @{{exal-Force}}">For</option>
|
||||
<option value="@{{base-Agilite}} + @{{exal-Agilite}}">Agi</option>
|
||||
<option value="@{{base-Perception}} + @{{exal-Perception}}">Per</option>
|
||||
<option value="@{{base-Charisme}} + @{{exal-Charisme}}">Cha</option>
|
||||
<option value="@{{base-Intelligence}} + @{{exal-Intelligence}}">Int</option>
|
||||
<option value="@{{base-Perception}} + @{{exal-Perception}}">Per</option>
|
||||
<option value="@{{base-Volonte}} + @{{exal-Volonte}}">Vol</option>
|
||||
<option value="@{{base-Accred}} + @{{exal-Accred}}">Acc</option>
|
||||
<option value="@{{base-Chance}} + @{{exal-Chance}}">Chn</option>
|
||||
</select>
|
||||
<button type='roll' class="sheet-skillbutton" value="&{{template:d10skillcheck}}\
|
||||
{{{{name=@{{character_name}}}}}}\
|
||||
{{{{roll_name=@{{{node.pname}_skillname}}}}}}\
|
||||
{{{{dice_name=@{{dice}}}}}}\
|
||||
{{{{result=[[@{{{node.pname}_skilllevel}}+(@{{{node.pname}_attribute_select}})-d@{{dice}}cs1cf@{{dice}}]]}}}}\
|
||||
{{{{threshold=[[@{{{node.pname}_skilllevel}}+(@{{{node.pname}_attribute_select}})]]}}}}">\
|
||||
</button>
|
||||
</fieldset>
|
||||
<br/>\n"""
|
||||
contentfooter = ""
|
||||
cssheader = ""
|
||||
csscontent = ""
|
||||
cssfooter = ""
|
||||
|
|
@ -7,22 +7,22 @@ use serde::Deserialize;
|
|||
|
||||
#[derive(Deserialize, Debug)]
|
||||
/// The GlobalConfiguration, loads and holds all information needed to generate a character
|
||||
pub struct GlobalConfig {
|
||||
pub struct GlobalFormat {
|
||||
/// The config section, includes all important links to external skills/data
|
||||
config: Config,
|
||||
info: Info,
|
||||
/// The data needed to create a config
|
||||
data: Data,
|
||||
}
|
||||
|
||||
/// The config for the Character sheet, includes the links to the additional data that needs to be fetched
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Config {
|
||||
struct Info {
|
||||
/// The name of the CharacterSheet (Flavour only)
|
||||
name: String,
|
||||
/// The version of the CharacterSheet (Flavour only)
|
||||
version: String,
|
||||
/// The skills associated with the CharacterSheet (Can be overwriten)
|
||||
skills: String,
|
||||
// /// The default skills associated with the CharacterSheet (Can be overwriten)
|
||||
// skills: String,
|
||||
}
|
||||
|
||||
/// The data needed to generate a CharacterSheet this data is not implementation agnostic for now
|
||||
|
|
@ -40,43 +40,64 @@ pub struct Data {
|
|||
css_footer: String,
|
||||
}
|
||||
|
||||
/// Repeating skill data
|
||||
// / Repeating skill data
|
||||
|
||||
/// Skill generation data
|
||||
pub struct SkillGenerator {
|
||||
/// Content of a skill, to be formatted
|
||||
skill_content: String,
|
||||
/// Content of a subskill, to be formatted
|
||||
subskill_content: String,
|
||||
/// Filler of a subskill, added before each skill, to be formatted
|
||||
subskill_filler: String,
|
||||
// /// Skill generation data
|
||||
// pub struct SkillGenerator {
|
||||
// /// Content of a skill, to be formatted
|
||||
// skill_content: String,
|
||||
// /// Content of a subskill, to be formatted
|
||||
// subskill_content: String,
|
||||
// /// Filler of a subskill, added before each skill, to be formatted
|
||||
// subskill_filler: String,
|
||||
|
||||
/// Content of a section
|
||||
section_content: String,
|
||||
/// Header of a section
|
||||
section_header: String,
|
||||
/// Footer of a section
|
||||
section_footer: String,
|
||||
// /// Content of a section
|
||||
// section_content: String,
|
||||
// /// Header of a section
|
||||
// section_header: String,
|
||||
// /// Footer of a section
|
||||
// section_footer: String,
|
||||
|
||||
/// Content of a sub_section
|
||||
sub_section_content: String,
|
||||
/// Header of a sub_section
|
||||
sub_section_header: String,
|
||||
/// Footer of a sub_section
|
||||
sub_section_footer: String,
|
||||
// /// Content of a sub_section
|
||||
// sub_section_content: String,
|
||||
// /// Header of a sub_section
|
||||
// sub_section_header: String,
|
||||
// /// Footer of a sub_section
|
||||
// sub_section_footer: String,
|
||||
// }
|
||||
|
||||
/// All formater data for a sheet
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct SheetFormat {
|
||||
/// Generic information on the skill formatter
|
||||
info: Info,
|
||||
/// The root node formatter strings
|
||||
root: FullFormat,
|
||||
/// The section formatter strings
|
||||
section: FullFormat,
|
||||
/// The subsection formatter strings
|
||||
subsection: FullFormat,
|
||||
/// The skill formatter strings
|
||||
skill: FullFormat,
|
||||
/// The subskill formatter strings
|
||||
subskill: FullFormat,
|
||||
/// The repeating formatter strings
|
||||
repeating: FullFormat,
|
||||
}
|
||||
|
||||
// #[derive(Deserialize, Debug)]
|
||||
// pub struct SkillsData {
|
||||
// sections: ,
|
||||
// }
|
||||
|
||||
// #[cfg(test)]
|
||||
// mod tests {
|
||||
// use super::{Config, Data, GlobalConfig};
|
||||
|
||||
// #[test]
|
||||
// fn test_creation() {
|
||||
// // let (_,_,_) = GlobalConfig{}, Data{},Config{};
|
||||
// }
|
||||
// }
|
||||
/// The format strings to be used by every section
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct FullFormat {
|
||||
/// The format string to use before the content
|
||||
contentheader: String,
|
||||
/// The format string to apply to the content
|
||||
content: String,
|
||||
/// The format string to use for the content footer
|
||||
contentfooter: String,
|
||||
/// The format string used before the css
|
||||
cssheader: String,
|
||||
/// The format string used for the content
|
||||
csscontent: String,
|
||||
/// The format string at the end of the css
|
||||
cssfooter: String,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,3 +50,15 @@ pub fn to_skill_name(name: &str) -> String {
|
|||
name.replace(|c: char| !c.is_ascii_alphabetic(), "")
|
||||
.to_lowercase()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::generator::to_skill_name;
|
||||
|
||||
static U: &str = "Thïs ïs å råñdôm têšt wïth 1234 sÿmbøls ãñd chårãctêrs lïkê ¡@#$%^&*()_+={}[]:;'\"<>,.?/èéêëēęëēæœöôóøōõúüùûūų";
|
||||
static V: &str = "thssrdmttwthsmblsdchrctrslk";
|
||||
#[test]
|
||||
fn test_ascii() {
|
||||
assert_eq!(to_skill_name(U), V);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use std::{fs, io, path::Path};
|
||||
|
||||
use crate::data_structure::GlobalConfig;
|
||||
use crate::data_structure::{GlobalFormat, SheetFormat};
|
||||
|
||||
/// Represents an error during Loading
|
||||
#[derive(Debug)]
|
||||
|
|
@ -19,57 +19,52 @@ pub enum LoadError {
|
|||
#[derive(Debug)]
|
||||
pub struct SheetModel {
|
||||
/// The Config associated with a Model
|
||||
config: Option<GlobalConfig>,
|
||||
sheet_config: Option<GlobalFormat>,
|
||||
/// The sheet formatter associated with the Model
|
||||
skill_config: Option<SheetFormat>,
|
||||
}
|
||||
|
||||
impl SheetModel {
|
||||
/// Create a new SheetModel
|
||||
pub fn new() -> SheetModel {
|
||||
SheetModel { config: None }
|
||||
SheetModel {
|
||||
sheet_config: None,
|
||||
skill_config: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Loads a model file from the specified path.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `path` - A reference to the path of the model file to load.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// A Result asserting if the loading was sucessful or a LoadError if an error occurs.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use rust20_d10::loader::ModelLoader;
|
||||
///
|
||||
/// let loader = ModelLoader::new();
|
||||
/// match loader.load_model("path/to/model_file.txt") {
|
||||
/// Ok(model_data) => println!("Model loaded successfully: {:?}", model_data),
|
||||
/// Err(error) => eprintln!("Error loading model: {:?}", error),
|
||||
/// }
|
||||
/// ```
|
||||
pub fn load_model<P>(&mut self, path: P) -> Result<(), LoadError>
|
||||
pub fn load_global_model<P>(&mut self, path: P) -> Result<(), LoadError>
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
{
|
||||
// Attempt to read the file
|
||||
let file_content = fs::read_to_string(&path).map_err(LoadError::Io)?;
|
||||
|
||||
let model_data: GlobalConfig = toml::from_str(&file_content).unwrap(); //. .ok_or(LoadError::InvalidFormat);
|
||||
|
||||
self.config = Some(model_data);
|
||||
let model_data: GlobalFormat = toml::from_str(&file_content).unwrap(); //. .ok_or(LoadError::InvalidFormat);
|
||||
self.sheet_config = Some(model_data);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Load the skill formater
|
||||
fn load_skill_model<P>(&mut self, path_skills: P) -> Result<(), LoadError>
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
{
|
||||
let file_content = fs::read_to_string(&path_skills).map_err(LoadError::Io)?;
|
||||
let skill_data: SheetFormat = toml::from_str(&file_content).unwrap();
|
||||
self.skill_config = Some(skill_data);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Create a Model from a path (shortcut for creating and loading)
|
||||
pub fn from_file<P>(path: P) -> Result<Self, LoadError>
|
||||
pub fn model_from_files<P>(path_global: P, path_skills: P) -> Result<Self, LoadError>
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
{
|
||||
let mut modl = Self::new();
|
||||
modl.load_model(path)?;
|
||||
modl.load_global_model(path_global)?;
|
||||
modl.load_skill_model(path_skills)?;
|
||||
Ok(modl)
|
||||
}
|
||||
}
|
||||
|
|
@ -83,28 +78,33 @@ mod tests {
|
|||
#[test]
|
||||
fn test_creation() {
|
||||
let modl = SheetModel::new();
|
||||
assert!(modl.config.is_none())
|
||||
assert!(modl.sheet_config.is_none())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_load() {
|
||||
let mut modl = SheetModel::new();
|
||||
assert!(modl.load_model(Path::new("data/cyberpunk.toml")).is_ok());
|
||||
assert!(modl.config.is_some())
|
||||
assert!(modl
|
||||
.load_global_model(Path::new("data/cyberpunk.toml"))
|
||||
.is_ok());
|
||||
assert!(modl.sheet_config.is_some())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bad_load() {
|
||||
let mut modl = SheetModel::new();
|
||||
assert!(modl.load_model(Path::new("wrong_file")).is_err())
|
||||
assert!(modl.load_global_model(Path::new("wrong_file")).is_err())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_file() {
|
||||
let modl = SheetModel::from_file(Path::new("data/cyberpunk.toml"));
|
||||
let path_global = Path::new("data/cyberpunk.toml");
|
||||
let path_skills = Path::new("data/cyberpunk_skill_format.toml");
|
||||
let bad_path = Path::new("wrong_file");
|
||||
let modl = SheetModel::model_from_files(path_global, path_skills);
|
||||
assert!(modl.is_ok());
|
||||
assert!(modl.unwrap().config.is_some());
|
||||
let modl = SheetModel::from_file(Path::new("wrong_file"));
|
||||
assert!(modl.unwrap().sheet_config.is_some());
|
||||
let modl = SheetModel::model_from_files(bad_path, path_skills);
|
||||
assert!(modl.is_err());
|
||||
match modl.err().unwrap() {
|
||||
crate::loader::LoadError::Io(_e) => (),
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#![allow(dead_code)]
|
||||
#![warn(missing_docs)]
|
||||
#![warn(clippy::missing_docs_in_private_items)]
|
||||
|
||||
use loader::SheetModel;
|
||||
|
||||
mod data_structure;
|
||||
|
|
@ -12,7 +13,9 @@ mod generator;
|
|||
mod loader;
|
||||
mod skills_structures;
|
||||
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
fn main() {
|
||||
let modl = SheetModel::from_file("data/cyberpunk.toml");
|
||||
let modl =
|
||||
SheetModel::model_from_files("data/cyberpunk.toml", "data/cyberpunk_skill_format.toml");
|
||||
println!("{:?}", modl);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,10 @@
|
|||
//! The `skills` module provides data structures and methods for managing skills.
|
||||
//!
|
||||
//! Includes all Section/Subsection/Skill/Sub-skill and a skill-list parser
|
||||
// #![warn(dead_code)]
|
||||
use std::{collections::HashMap, str::FromStr};
|
||||
use strfmt::strfmt;
|
||||
|
||||
use crate::generator::to_skill_name;
|
||||
|
||||
/// Type sugarcoat of a replacement hashmap
|
||||
type HashReplace = HashMap<String, String>;
|
||||
|
|
@ -84,7 +86,8 @@ impl DataCell {
|
|||
/// Create a datacell from the given raw string
|
||||
pub fn new(raw_name: &str, id: usize, global_id: usize) -> Self {
|
||||
let name = String::from_str(raw_name).unwrap();
|
||||
let stripped_name = name.replace(|c: char| !c.is_ascii_alphabetic(), "");
|
||||
let stripped_name = to_skill_name(&name);
|
||||
// let stripped_name = name.replace(|c: char| !c.is_ascii_alphabetic(), "");
|
||||
DataCell {
|
||||
name,
|
||||
stripped_name,
|
||||
|
|
@ -101,28 +104,28 @@ impl DataCell {
|
|||
h.insert("id".to_string(), self.id.to_string());
|
||||
h.insert("global_id".to_string(), self.global_id.to_string());
|
||||
if self.id == 1 {
|
||||
h.insert("selected".to_string(), "true".to_owned());
|
||||
h.insert("selected".to_string(), "checked=\"checked\"".to_owned());
|
||||
} else {
|
||||
h.insert("selected".to_string(), "false".to_owned());
|
||||
h.insert("selected".to_string(), "".to_owned());
|
||||
}
|
||||
h
|
||||
}
|
||||
}
|
||||
|
||||
/// A CharacterSheet ready to be rendered
|
||||
/// A A skill that contains all information to be rendered by the external renderer
|
||||
trait Renderable {
|
||||
/// Create a new renderable
|
||||
fn new(name: &str, id: usize, global_id: usize, size_hint: usize) -> Self;
|
||||
/// Get the vars hashmap
|
||||
fn get_vars(&self) -> HashReplace;
|
||||
/// Render the element and all sub elements
|
||||
fn render(&self, model: &str) -> Result<String, ErrorSkills>;
|
||||
/// Render the element header
|
||||
fn header(&self, model: &str) -> Result<String, ErrorSkills>;
|
||||
/// Render the element content
|
||||
fn content(&self, model: &str) -> Result<String, ErrorSkills>;
|
||||
/// Render the element footer
|
||||
fn footer(&self, model: &str) -> Result<String, ErrorSkills>;
|
||||
// /// Render the element and all sub elements
|
||||
// fn render(&self, model: &str) -> Result<String, ErrorSkills>;
|
||||
// /// Render the element header
|
||||
// fn header(&self, model: &str) -> Result<String, ErrorSkills>;
|
||||
// /// Render the element content
|
||||
// fn content(&self, model: &str) -> Result<String, ErrorSkills>;
|
||||
// /// Render the element footer
|
||||
// fn footer(&self, model: &str) -> Result<String, ErrorSkills>;
|
||||
/// Get the underlying name of the skill
|
||||
fn get_name(&self) -> &str;
|
||||
/// Get the underlying short name
|
||||
|
|
@ -150,36 +153,36 @@ impl Renderable for Section {
|
|||
self.data.to_hashmap()
|
||||
}
|
||||
|
||||
/// A section cannot be rendered as a whole
|
||||
fn render(&self, _model: &str) -> Result<String, ErrorSkills> {
|
||||
Err(ErrorSkills::NonCallableMethod)
|
||||
}
|
||||
// /// A section cannot be rendered as a whole
|
||||
// fn render(&self, _model: &str) -> Result<String, ErrorSkills> {
|
||||
// Err(ErrorSkills::NonCallableMethod)
|
||||
// }
|
||||
|
||||
fn header(&self, model: &str) -> Result<String, ErrorSkills> {
|
||||
let mut vars = HashMap::new();
|
||||
vars.insert("number".to_string(), "0");
|
||||
vars.insert("name".to_string(), self.get_name());
|
||||
// fn header(&self, model: &str) -> Result<String, ErrorSkills> {
|
||||
// let mut vars = HashMap::new();
|
||||
// vars.insert("number".to_string(), "0");
|
||||
// vars.insert("name".to_string(), self.get_name());
|
||||
|
||||
match self.get_id() {
|
||||
0 => vars.insert("checked".to_string(), "checked=\"checked\""),
|
||||
_ => vars.insert("checked".to_string(), ""),
|
||||
};
|
||||
match strfmt(model, &vars) {
|
||||
Ok(res) => Ok(res),
|
||||
Err(e) => Err(ErrorSkills::FormatError(e)),
|
||||
}
|
||||
}
|
||||
// match self.get_id() {
|
||||
// 0 => vars.insert("checked".to_string(), "checked=\"checked\""),
|
||||
// _ => vars.insert("checked".to_string(), ""),
|
||||
// };
|
||||
// match strfmt(model, &vars) {
|
||||
// Ok(res) => Ok(res),
|
||||
// Err(e) => Err(ErrorSkills::FormatError(e)),
|
||||
// }
|
||||
// }
|
||||
|
||||
fn content(&self, model: &str) -> Result<String, ErrorSkills> {
|
||||
match strfmt(model, &self.get_vars()) {
|
||||
Ok(r) => Ok(r),
|
||||
Err(e) => Err(ErrorSkills::FormatError(e)),
|
||||
}
|
||||
}
|
||||
// fn content(&self, model: &str) -> Result<String, ErrorSkills> {
|
||||
// match strfmt(model, &self.get_vars()) {
|
||||
// Ok(r) => Ok(r),
|
||||
// Err(e) => Err(ErrorSkills::FormatError(e)),
|
||||
// }
|
||||
// }
|
||||
|
||||
fn footer(&self, _model: &str) -> Result<String, ErrorSkills> {
|
||||
Err(ErrorSkills::NonCallableMethod)
|
||||
}
|
||||
// fn footer(&self, _model: &str) -> Result<String, ErrorSkills> {
|
||||
// Err(ErrorSkills::NonCallableMethod)
|
||||
// }
|
||||
|
||||
fn new(name: &str, id: usize, global_id: usize, size_hint: usize) -> Self {
|
||||
Self {
|
||||
|
|
@ -190,6 +193,7 @@ impl Renderable for Section {
|
|||
}
|
||||
|
||||
/// All errors regarding the skill handling
|
||||
#[derive(Debug)]
|
||||
pub enum ErrorSkills {
|
||||
/// The formatting failed
|
||||
FormatError(strfmt::FmtError),
|
||||
|
|
@ -199,23 +203,48 @@ pub enum ErrorSkills {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::collections::HashMap;
|
||||
|
||||
use super::{DataCell, Renderable, Section};
|
||||
|
||||
static S1: &str =
|
||||
"This is a test sentence with some non-ASCII characters like café and résumé.";
|
||||
static S2: &str = "ThisisatestsentencewithsomenonASCIIcharacterslikecafandrsum";
|
||||
static S2: &str = "thisisatestsentencewithsomenonasciicharacterslikecafandrsum";
|
||||
static T1: &str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris in velit purus. Cras commodo, libero vel tempus facilisis, erat metus eleifend nulla, at dignissim nibh erat vel magna. Maecenas in augue eget tortor rhoncus venenatis. Fusce non odio vitae velit dictum ultricies eget a mauris. Nullam sodales nisi in enim pulvinar, ut eleifend ex feugiat. Integer tincidunt, metus et consectetur ultricies, magna dolor fringilla lorem, non ultricies ligula est quis justo. Quisque non diam at magna efficitur fermentum.";
|
||||
static T2: &str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris in velit purus. Cras commodo, libero vel tempus facilisis, erat metus eleifend nulla, at dignissim nibh erat vel magna. Maecenas in augue eget tortor rhoncus venenatis. Fusce non odio vitae velit dictum ultricies eget a mauris. Nullam sodales nisi in enim pulvinar, ut eleifend ex feugiat. Integer tincidunt, metus et consectetur ultricies, magna dolor fringilla lorem, non ultricies ligula est quis justo. Quisque non diam at magna efficitur fermentum.";
|
||||
static T2: &str = "lorem ipsum dolor sit amet, consectetur adipiscing elit. mauris in velit purus. cras commodo, libero vel tempus facilisis, erat metus eleifend nulla, at dignissim nibh erat vel magna. maecenas in augue eget tortor rhoncus venenatis. fusce non odio vitae velit dictum ultricies eget a mauris. nullam sodales nisi in enim pulvinar, ut eleifend ex feugiat. integer tincidunt, metus et consectetur ultricies, magna dolor fringilla lorem, non ultricies ligula est quis justo. quisque non diam at magna efficitur fermentum.";
|
||||
static U: &str = "Thïs ïs å råñdôm têšt wïth 1234 sÿmbøls ãñd chårãctêrs lïkê ¡@#$%^&*()_+={}[]:;'\"<>,.?/èéêëēęëēæœöôóøōõúüùûūų";
|
||||
static V: &str = "Testing special characters like ©, ®, ™, and emojis like 😊, 💻.";
|
||||
#[test]
|
||||
fn test_datacell() {
|
||||
let ds = DataCell::new(S1, 1, 1);
|
||||
let ds = DataCell::new(S1, 1, 2);
|
||||
let ds2 = DataCell::new(S1, 2, 2);
|
||||
assert_eq!(ds.name, S1);
|
||||
assert_eq!(ds.stripped_name, S2);
|
||||
|
||||
let mut map = HashMap::new();
|
||||
map.insert("name".to_string(), S1.to_string());
|
||||
map.insert("pname".to_string(), S2.to_string());
|
||||
map.insert("id".to_string(), "1".to_string());
|
||||
map.insert("global_id".to_string(), "2".to_string());
|
||||
map.insert("selected".to_string(), "checked=\"checked\"".to_string());
|
||||
assert_eq!(ds.to_hashmap(), map);
|
||||
map.insert("selected".to_string(), "".to_string());
|
||||
map.insert("id".to_string(), "2".to_string());
|
||||
assert_eq!(ds2.to_hashmap(), map);
|
||||
}
|
||||
#[test]
|
||||
fn test_section() {
|
||||
let _s1 = Section::new(T1, 0, 1, 30);
|
||||
let s1 = Section::new(S1, 1, 200, 30);
|
||||
assert_eq!(s1.get_name(), S1);
|
||||
assert_eq!(s1.get_stripped_name(), S2);
|
||||
assert_eq!(s1.get_id(), 1);
|
||||
assert_eq!(s1.get_global_id(), 200);
|
||||
let mut map = HashMap::new();
|
||||
map.insert("name".to_string(), S1.to_string());
|
||||
map.insert("pname".to_string(), S2.to_string());
|
||||
map.insert("id".to_string(), "1".to_string());
|
||||
map.insert("global_id".to_string(), "200".to_string());
|
||||
map.insert("selected".to_string(), "checked=\"checked\"".to_string());
|
||||
assert_eq!(s1.get_vars(), map);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Reference in New Issue