Skip to content

Commit

Permalink
refactor(citation): revise model
Browse files Browse the repository at this point in the history
This more closely aligns the model with the haskell citeproc
implementation.

Signed-off-by: Bruce D'Arcus <bdarcus@gmail.com>
  • Loading branch information
bdarcus committed Oct 11, 2023
1 parent da8eced commit 96cd8d2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
25 changes: 22 additions & 3 deletions csln/src/citation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,33 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Default, Serialize, Deserialize, JsonSchema)]
pub struct CitationList(pub Vec<Citation>);

/* data Citation a =
Citation { citationId :: Maybe Text
, citationNoteNumber :: Maybe Int
, citationItems :: [CitationItem a] }
data CitationItem a =
CitationItem
{ citationItemId :: ItemId
, citationItemLabel :: Maybe Text
, citationItemLocator :: Maybe Text
, citationItemType :: CitationItemType
, citationItemPrefix :: Maybe a
, citationItemSuffix :: Maybe a
, citationItemData :: Maybe (Reference a)
} */

#[derive(Debug, Default, Serialize, Deserialize, JsonSchema)]
pub struct Citation {
pub note_number: Option<i32>,
pub id: Option<String>,
/// Local citation rendering option; aka command or style.
/// Both are more general than author-date styles, and can apply to any citation style.
pub mode: CitationModeType,
/// The string that prefaces a list of citation references.
pub prefix: Option<String>,
/// A vector of CitatoinReference objects.
pub references: Vec<CitationReference>,
/// A vector of CitationItem objects.
pub citation_items: Vec<CitationItem>,
/// A string that follows a list of citation references.
pub suffix: Option<String>,
}
Expand All @@ -31,7 +49,8 @@ pub enum CitationModeType {

#[derive(Debug, Default, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct CitationReference {
pub struct CitationItem {
pub label: Option<String>,
/// A string that prefaces the citation reference.
pub prefix: Option<String>,
/// The unique identifier token for the citation reference.
Expand Down
6 changes: 3 additions & 3 deletions processor/examples/citation.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
- mode: non-integral
references:
citation_items:
- refId: "doe1"
- refId: "doe2"
- mode: integral
references:
citation_items:
- refId: "doe2"
suffix: ["page 42"]
- mode: non-integral
prefix: "see "
references:
citation_items:
- refId: "doe3"
3 changes: 2 additions & 1 deletion processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ impl ComponentValues for TemplateContributor {
role_form,
editor_length,
)
// FIXME
.unwrap()
});
let suffix_padded = suffix.and_then(|s| {
Expand Down Expand Up @@ -739,7 +740,7 @@ impl Processor {
self.citations
.iter()
.flat_map(|c| {
c.references
c.citation_items
.iter()
.map(|cr| cr.ref_id.clone())
.collect::<Vec<String>>()
Expand Down

0 comments on commit 96cd8d2

Please sign in to comment.