lexi 0.3.0

Renders a YAML lexicon file into dictionary files.
Documentation
use serde::{Deserialize, Serialize};

/// Formatting settings for all documents.
#[derive(Serialize, Deserialize)]
pub struct Format {
	#[serde(default)]
	pub native: Native,
	#[serde(default)]
	pub native_foreign: TranslationDictionary,
	#[serde(default)]
	pub foreign_native: TranslationDictionary,
	#[serde(default = "default_indent")]
	pub indent: String,
}

impl Default for Format {
	fn default() -> Self {
		Self {
			native: Default::default(),
			native_foreign: Default::default(),
			foreign_native: Default::default(),
			indent: default_indent(),
		}
	}
}

fn default_indent() -> String {
	"20px".into()
}

/// Formatting settings for the monolingual native dictionary and for native
/// text in all documents.
#[derive(Serialize, Deserialize, Default)]
pub struct Native {
	/// Title of the monolingual native dictionary.
	#[serde(default)]
	pub title: String,
	/// Optional override of the standard lexicographical sort for native text,
	/// specified as an ascending list of graphemes.
	pub sort: Option<Vec<String>>,
	/// Preceeds every block of native text.
	#[serde(default)]
	pub prefix: String,
	/// Follows every block of native text.
	#[serde(default)]
	pub suffix: String,
}

/// Formatting settings for the native-foreign translation dictionary.
#[derive(Serialize, Deserialize)]
pub struct TranslationDictionary {
	#[serde(default)]
	pub title: String,
	/// Delimiter between the lemma and its list of glosses.
	#[serde(default = "default_delimiter")]
	pub delimiter: String,
	/// Delimiter between glosses.
	#[serde(default = "default_gloss_delimiter")]
	pub gloss_delimiter: String,
}

impl Default for TranslationDictionary {
	fn default() -> Self {
		Self {
			title: Default::default(),
			delimiter: default_delimiter(),
			gloss_delimiter: default_gloss_delimiter(),
		}
	}
}

fn default_delimiter() -> String {
	" ยท ".into()
}

fn default_gloss_delimiter() -> String {
	"; ".into()
}