mirror of
https://github.com/typst/typst
synced 2025-07-27 14:27:56 +08:00
Merge 8d4706b4f5fc4fabe34e308b08c990407e9203ea into e9f1b5825a9d37ca0c173a7b2830ba36a27ca9e0
This commit is contained in:
commit
b4059264ae
@ -143,6 +143,16 @@ pub struct PackageInfo {
|
||||
}
|
||||
|
||||
impl PackageManifest {
|
||||
/// Create a new package manifest with the given package info.
|
||||
pub fn new(package: PackageInfo) -> Self {
|
||||
PackageManifest {
|
||||
package,
|
||||
template: None,
|
||||
tool: ToolInfo::default(),
|
||||
unknown_fields: UnknownFields::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Ensure that this manifest is indeed for the specified package.
|
||||
pub fn validate(&self, spec: &PackageSpec) -> Result<(), EcoString> {
|
||||
if self.package.name != spec.name {
|
||||
@ -173,6 +183,44 @@ impl PackageManifest {
|
||||
}
|
||||
}
|
||||
|
||||
impl TemplateInfo {
|
||||
/// Create a new template info with only required fields.
|
||||
pub fn new(path: impl Into<EcoString>, entrypoint: impl Into<EcoString>) -> Self {
|
||||
TemplateInfo {
|
||||
path: path.into(),
|
||||
entrypoint: entrypoint.into(),
|
||||
thumbnail: None,
|
||||
unknown_fields: UnknownFields::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PackageInfo {
|
||||
/// Create a new package info with only required fields.
|
||||
pub fn new(
|
||||
name: impl Into<EcoString>,
|
||||
version: PackageVersion,
|
||||
entrypoint: impl Into<EcoString>,
|
||||
) -> Self {
|
||||
PackageInfo {
|
||||
name: name.into(),
|
||||
version,
|
||||
entrypoint: entrypoint.into(),
|
||||
authors: vec![],
|
||||
categories: vec![],
|
||||
compiler: None,
|
||||
description: None,
|
||||
disciplines: vec![],
|
||||
exclude: vec![],
|
||||
homepage: None,
|
||||
keywords: vec![],
|
||||
license: None,
|
||||
repository: None,
|
||||
unknown_fields: BTreeMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Identifies a package.
|
||||
#[derive(Clone, Eq, PartialEq, Hash)]
|
||||
pub struct PackageSpec {
|
||||
@ -535,22 +583,11 @@ mod tests {
|
||||
"#
|
||||
),
|
||||
Ok(PackageManifest {
|
||||
package: PackageInfo {
|
||||
name: "package".into(),
|
||||
version: PackageVersion { major: 0, minor: 1, patch: 0 },
|
||||
entrypoint: "src/lib.typ".into(),
|
||||
authors: vec![],
|
||||
license: None,
|
||||
description: None,
|
||||
homepage: None,
|
||||
repository: None,
|
||||
keywords: vec![],
|
||||
categories: vec![],
|
||||
disciplines: vec![],
|
||||
compiler: None,
|
||||
exclude: vec![],
|
||||
unknown_fields: BTreeMap::new(),
|
||||
},
|
||||
package: PackageInfo::new(
|
||||
"package",
|
||||
PackageVersion { major: 0, minor: 1, patch: 0 },
|
||||
"src/lib.typ"
|
||||
),
|
||||
template: None,
|
||||
tool: ToolInfo { sections: BTreeMap::new() },
|
||||
unknown_fields: BTreeMap::new(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user