Skip to content

Commit

Permalink
feat(proc): author substitution
Browse files Browse the repository at this point in the history
Miscellaneous refactoring and new methods to implement.

Closes: #23

Signed-off-by: Bruce D'Arcus <bdarcus@gmail.com>
  • Loading branch information
bdarcus committed Jul 23, 2023
1 parent 6e3992c commit a6bf2b8
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 51 deletions.
3 changes: 2 additions & 1 deletion csln/src/bibliography/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ impl InputReference {
// REVIEW: return string instead?
InputReference::Monograph(r) => r.publisher.clone(),
InputReference::MonographComponent(r) => r.parent.publisher.clone(),
InputReference::Collection(r) => r.publisher.clone(),
_ => None,
}
}
Expand Down Expand Up @@ -201,7 +202,7 @@ pub struct Collection {
pub url: Option<Url>,
pub accessed: Option<EdtfString>,
pub note: Option<String>,
pub issn: Option<String>,
pub isbn: Option<String>,
}

#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema, PartialEq)]
Expand Down
42 changes: 25 additions & 17 deletions csln/src/style/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum WrapPunctuation {
}

/// The Template component model. Each item is for a specific datatype.
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema)]
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema, PartialEq)]
#[serde(untagged)]
#[non_exhaustive]
pub enum TemplateComponent {
Expand All @@ -46,16 +46,24 @@ impl TemplateComponent {
TemplateComponent::SimpleString(s) => s.rendering.clone(),
}
}

// TODO do I need this?
pub fn is_author(&self) -> bool {
match self {
TemplateComponent::Contributor(c) => c.contributor == ContributorRole::Author,
_ => false,
}
}
}

/// A simple string component, to render a string variable.
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema)]
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema, PartialEq)]
pub struct TemplateSimpleString {
pub variable: Variables,
pub rendering: Option<Rendering>,
}

#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema)]
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum Variables {
// TODO: add more variables
Expand All @@ -65,22 +73,22 @@ pub enum Variables {
}

/// A number component, to render a number.
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema)]
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema, PartialEq)]
pub struct TemplateNumber {
pub number: Numbers,
pub form: Option<NumberForm>,
pub rendering: Option<Rendering>,
}

#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema)]
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum Numbers {
Volume,
Issue,
Pages,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone, JsonSchema)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, JsonSchema, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum NumberForm {
#[default]
Expand All @@ -89,7 +97,7 @@ pub enum NumberForm {
}

/// To render is a list of more than one item; primarily to enable use of a delimiter to join the items.
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema)]
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema, PartialEq)]
pub struct TemplateList {
pub delimiter: Option<DelimiterPunctuation>,
pub prefix: Option<String>,
Expand All @@ -99,7 +107,7 @@ pub struct TemplateList {
}

/// The punctuation to use as a delimiter between items in a list.
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema)]
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub enum DelimiterPunctuation {
Comma,
Expand All @@ -116,21 +124,21 @@ pub enum DelimiterPunctuation {

/// A contributor component, to render a list of contributors.
// TODO incomplete
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema)]
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema, PartialEq)]
pub struct TemplateContributor {
pub contributor: ContributorRole,
pub form: ContributorForm,
pub rendering: Option<Rendering>,
}

#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema)]
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema, PartialEq)]
#[serde(rename_all = "camelCase")]
pub enum ContributorForm {
Long,
Short,
}

#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema)]
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema, PartialEq)]
#[serde(rename_all = "camelCase")]
pub enum ContributorRole {
Author,
Expand All @@ -147,22 +155,22 @@ pub enum ContributorRole {
}

/// A date component, to render a date.
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema)]
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema, PartialEq)]
pub struct TemplateDate {
pub date: Dates,
pub form: DateForm,
pub rendering: Option<Rendering>,
}

#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema)]
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub enum Dates {
Issued,
Accessed,
OriginalPublished,
}

#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema)]
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub enum DateForm {
Year,
Expand All @@ -172,14 +180,14 @@ pub enum DateForm {
}

/// A title component, to render a title.
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema)]
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema, PartialEq)]
pub struct TemplateTitle {
pub title: Titles,
pub form: Option<TitleForm>,
pub rendering: Option<Rendering>,
}

#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema)]
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema, PartialEq)]
#[serde(rename_all = "kebab-case")]
#[non_exhaustive]
pub enum Titles {
Expand All @@ -191,7 +199,7 @@ pub enum Titles {
ParentSerial,
}

#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema)]
#[derive(Debug, Deserialize, Serialize, Clone, JsonSchema, PartialEq)]
#[serde(rename_all = "camelCase")]
pub enum TitleForm {
Short,
Expand Down
2 changes: 1 addition & 1 deletion processor/examples/chicago.bib.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ lamp:
issue: 3
pages: 263-269
daum:
type: book
type: edited-book
editor:
family: Daum
given: Meghan
Expand Down
4 changes: 3 additions & 1 deletion processor/examples/style.csl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ bibliography:
rendering: # not a fan of this
wrap: parentheses
- title: primary
- contributor: editor
form: long
- title: parent-monograph
prefix: In
emph: true
Expand All @@ -47,6 +49,6 @@ bibliography:
form: month-day
- number: volume
- variable: doi
- contributor: publisher
- contributor: publisher # location?
form: long # make optional, with default?
delimiter: colon # scope? delimiter vs item-delimiter?
Loading

0 comments on commit a6bf2b8

Please sign in to comment.