mirror of
https://github.com/storytold/designcraft.git
synced 2026-11-11 02:50:22 -06:00
#403 added validate_char_fill with its own message; #520 added known_swatch for object fills and strokes, which also suggests the intended name. validate_char_fill now calls known_swatch with key "fill", so one error path covers both. #403's tests still pass (the message names the fill, swatch.create and the returned name).
This commit is contained in:
@@ -17,7 +17,7 @@ use crate::{Result, Session};
|
||||
|
||||
/// `name` must be a swatch of the document: an unknown name would paint nothing. The error names
|
||||
/// the swatch it was probably meant to be (`Paper` → `[Paper]`, a different case).
|
||||
fn known_swatch(doc: &designcraft_doc::Document, name: &str, cmd: &str, key: &str) -> Result<()> {
|
||||
pub(crate) fn known_swatch(doc: &designcraft_doc::Document, name: &str, cmd: &str, key: &str) -> Result<()> {
|
||||
if doc.swatch(name).is_some() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -1297,16 +1297,12 @@ fn ruby_cmd(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
format_chars(s, &Value::Object(body))
|
||||
}
|
||||
|
||||
/// A character fill must name a swatch of the document.
|
||||
pub(crate) fn validate_char_fill(document: &designcraft_doc::Document, attrs: &CharAttrs, command_id: &str) -> Result<()> {
|
||||
if let Some(fill) = &attrs.fill
|
||||
&& document.swatch(fill).is_none()
|
||||
{
|
||||
return Err(bad(
|
||||
command_id,
|
||||
format!("unknown character fill `{fill}`; create a swatch with `swatch.create` and use its returned name as `fill`"),
|
||||
));
|
||||
match &attrs.fill {
|
||||
Some(fill) => super::object::known_swatch(document, fill, command_id, "fill"),
|
||||
None => Ok(()),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn format_chars(s: &mut Session, attrs: &Value) -> Result<Value> {
|
||||
|
||||
Reference in New Issue
Block a user