Skip to content

Instantly share code, notes, and snippets.

@bdarcus

bdarcus/style.rs Secret

Last active May 6, 2023 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdarcus/fdba2f647b87b6124b9b62bfd16accf9 to your computer and use it in GitHub Desktop.
Save bdarcus/fdba2f647b87b6124b9b62bfd16accf9 to your computer and use it in GitHub Desktop.
Auto conversion result of CSL-Next JSON schema to Rust and Swift, via quicktype
use std::fs;
// Example code that reads a json style file, deserializes into a Rust Style, and prints the string from `style.title`.
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
/// use generated_module::Style;
fn main() {
let json = fs::read_to_string("src/style.csl.json")
.expect("Unable to read file");
let style: Style = serde_json::from_str(&json).unwrap();
println!("{}", serde_json::to_string(&style.title).unwrap());
}
use serde::{Serialize, Deserialize};
/// A CSL Style.
#[derive(Serialize, Deserialize)]
pub struct Style {
/// The bibliography specification.
pub bibliography: Option<Bibliography>,
/// The categories the style belongs to; for purposes of indexing.
pub categories: Option<Vec<CategoryType>>,
/// The citation specification.
pub citation: Option<Citation>,
/// The description of the style.
pub description: Option<String>,
/// The machine-readable token that uniquely identifies the style.
pub id: Option<String>,
/// Global parameter options.
pub options: Option<OptionGroup>,
/// The templates for rendering the bibliography and citations.
pub templates: Option<Vec<NamedTemplate>>,
/// The human-readable name of the style.
pub title: Option<String>,
}
/// The bibliography specification.
#[derive(Serialize, Deserialize)]
pub struct Bibliography {
pub bold: Option<bool>,
/// The string with which to join two or more rendering comnponents.
pub delimiter: Option<String>,
pub emph: Option<bool>,
/// The rendering instructions; either called template name, or inline instructions.
pub format: Option<BibliographyFormat>,
pub heading: Option<String>,
#[serde(rename = "listStyle")]
pub list_style: Option<String>,
pub options: Option<OptionGroup>,
/// The symbol pair to wrap around one or more rendering components.
/// Interaction with surrounding punctuation is localized.
pub wrap: Option<WrapType>,
}
#[derive(Serialize, Deserialize)]
pub struct Condition {
/// When a match, process these templates.
pub format: Vec<TemplateModel>,
/// Is the item variable a number?
#[serde(rename = "isNumber")]
pub is_number: Option<LocatorType>,
/// A list of reference item types; if one is true, then return true.
#[serde(rename = "match")]
pub condition_match: Option<MatchType>,
/// Does the date conform to EDTF?
#[serde(rename = "isEDTFDate")]
pub is_edtf_date: Option<DateType>,
/// Is the item reference type among the listed reference types?
#[serde(rename = "isRefType")]
pub is_ref_type: Option<Vec<RefType>>,
/// Does the item reference include one of the listed variables?
#[serde(rename = "hasVariable")]
pub has_variable: Option<Vec<VariableType>>,
/// The item reference locale; to allow multilingual output.
pub locale: Option<String>,
}
/// A template that is defined inline.
///
/// Integral citations are those where the author is printed inline in the text; aka "in
/// text" or "narrative" citations.
///
/// Non-integral citations are those where the author is incorporated in the citation, and
/// not printed inline in the text.
#[derive(Serialize, Deserialize)]
pub struct TemplateModel {
pub bold: Option<bool>,
/// The string with which to join two or more rendering comnponents.
pub delimiter: Option<String>,
pub emph: Option<bool>,
/// The rendering instructions; either called template name, or inline instructions.
pub format: Option<TemplateModelFormat>,
pub options: Option<OptionGroup>,
/// The symbol pair to wrap around one or more rendering components.
/// Interaction with surrounding punctuation is localized.
pub wrap: Option<WrapType>,
/// The template name to use for partial formatting.
pub template: Option<String>,
pub variable: Option<Type>,
/// When all of the when conditions are nil, format the children.
#[serde(rename = "else")]
pub template_model_else: Option<Vec<TemplateModel>>,
/// For the first condition that is non-nil, format the children.
pub when: Option<Vec<Condition>>,
}
/// Parameter groups.
///
/// Global parameter options.
#[derive(Serialize, Deserialize)]
pub struct OptionGroup {
/// Date formatting configuration.
#[serde(rename = "dateFormatting")]
pub date_formatting: Option<DateFormatting>,
/// Disambiguation configuration of rendererd group display names.
pub disambiguate: Option<Disambiguation>,
/// Grouping configuration.
pub group: Option<Vec<GroupSortType>>,
/// Localization configuration.
pub localization: Option<Localization>,
/// Sorting configuration.
pub sort: Option<Vec<Sort>>,
/// Substitution configuration.
pub substitute: Option<Substitution>,
}
/// Date formatting configuration.
#[derive(Serialize, Deserialize)]
pub struct DateFormatting {
pub date: Option<EStyle>,
pub month: Option<MonthStyle>,
pub time: Option<EStyle>,
pub year: Option<YearStyle>,
}
/// Disambiguation configuration of rendererd group display names.
///
/// Disambiguation of rendered group display name configuration.
#[derive(Serialize, Deserialize)]
pub struct Disambiguation {
#[serde(rename = "addNames")]
pub add_names: Option<AddNames>,
#[serde(rename = "addYearSuffix")]
pub add_year_suffix: Option<bool>,
}
/// Localization configuration.
///
/// Terms and data localization configuration.
#[derive(Serialize, Deserialize)]
pub struct Localization {
/// The scope to use for localization.
///
/// "per-item" uses the locale of the reference item, and "global" uses the target language
/// across all references.
pub scope: Option<Scope>,
}
/// Reference sorting configuration.
#[derive(Serialize, Deserialize)]
pub struct Sort {
pub key: GroupSortType,
pub order: Order,
}
/// Substitution configuration.
///
/// Substitution of variable configuration.
#[derive(Serialize, Deserialize)]
pub struct Substitution {
/// When author is nil, substitute the first non-nil listed variable.
/// Once a substitution is made, the substituted variable shall be set to nil for purposes of
/// later rendering.
pub author: Vec<SubstitutionType>,
}
/// The citation specification.
#[derive(Serialize, Deserialize)]
pub struct Citation {
pub bold: Option<bool>,
/// The string with which to join two or more rendering comnponents.
pub delimiter: Option<String>,
pub emph: Option<bool>,
/// The rendering instructions; either called template name, or inline instructions.
pub format: Option<BibliographyFormat>,
/// Integral citations are those where the author is printed inline in the text; aka "in
/// text" or "narrative" citations.
pub integral: Option<RenderList>,
/// Non-integral citations are those where the author is incorporated in the citation, and
/// not printed inline in the text.
#[serde(rename = "nonIntegral")]
pub non_integral: Option<RenderList>,
pub options: Option<OptionGroup>,
pub placement: Option<Placement>,
/// The symbol pair to wrap around one or more rendering components.
/// Interaction with surrounding punctuation is localized.
pub wrap: Option<WrapType>,
}
/// Integral citations are those where the author is printed inline in the text; aka "in
/// text" or "narrative" citations.
///
/// Non-integral citations are those where the author is incorporated in the citation, and
/// not printed inline in the text.
#[derive(Serialize, Deserialize)]
pub struct RenderList {
pub bold: Option<bool>,
/// The string with which to join two or more rendering comnponents.
pub delimiter: Option<String>,
pub emph: Option<bool>,
/// The rendering instructions; either called template name, or inline instructions.
pub format: Option<BibliographyFormat>,
pub options: Option<OptionGroup>,
/// The symbol pair to wrap around one or more rendering components.
/// Interaction with surrounding punctuation is localized.
pub wrap: Option<WrapType>,
}
#[derive(Serialize, Deserialize)]
pub struct NamedTemplate {
/// The name token for the template, for reference from other templates.
pub name: String,
pub options: Option<OptionGroup>,
pub template: Vec<TemplateModel>,
}
#[derive(Serialize, Deserialize)]
#[serde(untagged)]
pub enum BibliographyFormat {
String(String),
TemplateModelArray(Vec<TemplateModel>),
}
#[derive(Serialize, Deserialize)]
#[serde(untagged)]
pub enum TemplateModelFormat {
String(String),
TemplateModelArray(Vec<TemplateModel>),
}
/// A list of reference item types; if one is true, then return true.
#[derive(Serialize, Deserialize)]
pub enum MatchType {
#[serde(rename = "all")]
All,
#[serde(rename = "any")]
Any,
#[serde(rename = "none")]
None,
}
#[derive(Serialize, Deserialize)]
pub enum VariableType {
#[serde(rename = "article")]
Article,
#[serde(rename = "author")]
Author,
#[serde(rename = "book")]
Book,
#[serde(rename = "chapter")]
Chapter,
#[serde(rename = "container-title")]
ContainerTitle,
#[serde(rename = "editor")]
Editor,
#[serde(rename = "issue")]
Issue,
#[serde(rename = "issued")]
Issued,
#[serde(rename = "pages")]
Pages,
#[serde(rename = "publisher")]
Publisher,
#[serde(rename = "title")]
Title,
#[serde(rename = "volume")]
Volume,
}
/// Does the date conform to EDTF?
#[derive(Serialize, Deserialize)]
pub enum DateType {
#[serde(rename = "issued")]
Issued,
}
/// Is the item variable a number?
#[derive(Serialize, Deserialize)]
pub enum LocatorType {
#[serde(rename = "chapter")]
Chapter,
#[serde(rename = "page")]
Page,
}
#[derive(Serialize, Deserialize)]
pub enum RefType {
#[serde(rename = "article")]
Article,
#[serde(rename = "book")]
Book,
#[serde(rename = "chapter")]
Chapter,
}
#[derive(Serialize, Deserialize)]
pub enum EStyle {
#[serde(rename = "full")]
Full,
#[serde(rename = "long")]
Long,
#[serde(rename = "medium")]
Medium,
#[serde(rename = "short")]
Short,
}
#[derive(Serialize, Deserialize)]
pub enum MonthStyle {
#[serde(rename = "long")]
Long,
#[serde(rename = "narrow")]
Narrow,
#[serde(rename = "numeric")]
Numeric,
#[serde(rename = "short")]
Short,
#[serde(rename = "2-digit")]
The2Digit,
}
#[derive(Serialize, Deserialize)]
pub enum YearStyle {
#[serde(rename = "numeric")]
Numeric,
#[serde(rename = "2-digit")]
The2Digit,
}
#[derive(Serialize, Deserialize)]
pub enum AddNames {
#[serde(rename = "all")]
All,
#[serde(rename = "all-with-initials")]
AllWithInitials,
#[serde(rename = "by-cite")]
ByCite,
#[serde(rename = "primary")]
Primary,
#[serde(rename = "primary-with-initials")]
PrimaryWithInitials,
}
#[derive(Serialize, Deserialize)]
pub enum GroupSortType {
#[serde(rename = "as-cited")]
AsCited,
#[serde(rename = "author")]
Author,
#[serde(rename = "title")]
Title,
#[serde(rename = "year")]
Year,
}
/// The scope to use for localization.
///
/// "per-item" uses the locale of the reference item, and "global" uses the target language
/// across all references.
#[derive(Serialize, Deserialize)]
pub enum Scope {
#[serde(rename = "global")]
Global,
#[serde(rename = "per-item")]
PerItem,
}
#[derive(Serialize, Deserialize)]
pub enum Order {
#[serde(rename = "ascending")]
Ascending,
#[serde(rename = "descending")]
Descending,
}
#[derive(Serialize, Deserialize)]
pub enum SubstitutionType {
#[serde(rename = "editor")]
Editor,
#[serde(rename = "title")]
Title,
#[serde(rename = "translator")]
Translator,
}
/// Is the item variable a number?
///
/// Does the date conform to EDTF?
#[derive(Serialize, Deserialize)]
pub enum Type {
#[serde(rename = "author")]
Author,
#[serde(rename = "chapter")]
Chapter,
#[serde(rename = "container-title")]
ContainerTitle,
#[serde(rename = "editor")]
Editor,
#[serde(rename = "issue")]
Issue,
#[serde(rename = "issued")]
Issued,
#[serde(rename = "page")]
Page,
#[serde(rename = "pages")]
Pages,
#[serde(rename = "publisher")]
Publisher,
#[serde(rename = "title")]
Title,
#[serde(rename = "volume")]
Volume,
}
/// The symbol pair to wrap around one or more rendering components.
/// Interaction with surrounding punctuation is localized.
#[derive(Serialize, Deserialize)]
pub enum WrapType {
#[serde(rename = "brackets")]
Brackets,
#[serde(rename = "parentheses")]
Parentheses,
#[serde(rename = "quotes")]
Quotes,
}
#[derive(Serialize, Deserialize)]
pub enum CategoryType {
#[serde(rename = "biology")]
Biology,
#[serde(rename = "science")]
Science,
#[serde(rename = "social science")]
SocialScience,
}
#[derive(Serialize, Deserialize)]
pub enum Placement {
#[serde(rename = "inline")]
Inline,
#[serde(rename = "note")]
Note,
}
// This file was generated from JSON Schema using quicktype, do not modify it directly.
// To parse the JSON, add this file to your project and do:
//
// let style = try? JSONDecoder().decode(Style.self, from: jsonData)
import Foundation
/// A CSL Style.
// MARK: - Style
public struct Style: Codable {
/// The bibliography specification.
public let bibliography: Bibliography?
/// r
/// The categories the style belongs to; for purposes of indexing.
public let categories: [CategoryType]?
/// The citation specification.
public let citation: Citation?
/// The description of the style.
public let description: String?
/// The machine-readable token that uniquely identifies the style.
public let id: String?
/// Global parameter options.
public let options: OptionGroup?
/// The templates for rendering the bibliography and citations.
public let templates: [NamedTemplate]?
/// The human-readable name of the style.
public let title: String?
public init(bibliography: Bibliography?, categories: [CategoryType]?, citation: Citation?, description: String?, id: String?, options: OptionGroup?, templates: [NamedTemplate]?, title: String?) {
self.bibliography = bibliography
self.categories = categories
self.citation = citation
self.description = description
self.id = id
self.options = options
self.templates = templates
self.title = title
}
}
/// The bibliography specification.
// MARK: - Bibliography
public struct Bibliography: Codable {
public let bold: Bool?
/// The string with which to join two or more rendering comnponents.
public let delimiter: String?
public let emph: Bool?
/// The rendering instructions; either called template name, or inline instructions.
public let format: BibliographyFormat?
public let heading, listStyle: String?
public let options: OptionGroup?
/// The symbol pair to wrap around one or more rendering components.
/// Interaction with surrounding punctuation is localized.
public let wrap: WrapType?
public init(bold: Bool?, delimiter: String?, emph: Bool?, format: BibliographyFormat?, heading: String?, listStyle: String?, options: OptionGroup?, wrap: WrapType?) {
self.bold = bold
self.delimiter = delimiter
self.emph = emph
self.format = format
self.heading = heading
self.listStyle = listStyle
self.options = options
self.wrap = wrap
}
}
public enum BibliographyFormat: Codable {
case string(String)
case templateModelArray([TemplateModel])
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
if let x = try? container.decode([TemplateModel].self) {
self = .templateModelArray(x)
return
}
if let x = try? container.decode(String.self) {
self = .string(x)
return
}
throw DecodingError.typeMismatch(BibliographyFormat.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Wrong type for BibliographyFormat"))
}
public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
switch self {
case .string(let x):
try container.encode(x)
case .templateModelArray(let x):
try container.encode(x)
}
}
}
// MARK: - Condition
public struct Condition: Codable {
/// When a match, process these templates.
public let format: [TemplateModel]
/// Is the item variable a number?
public let isNumber: LocatorType?
/// A list of reference item types; if one is true, then return true.
public let match: MatchType?
/// Does the date conform to EDTF?
public let isEDTFDate: DateType?
/// Is the item reference type among the listed reference types?
public let isRefType: [RefType]?
/// Does the item reference include one of the listed variables?
public let hasVariable: [VariableType]?
/// The item reference locale; to allow multilingual output.
public let locale: String?
public init(format: [TemplateModel], isNumber: LocatorType?, match: MatchType?, isEDTFDate: DateType?, isRefType: [RefType]?, hasVariable: [VariableType]?, locale: String?) {
self.format = format
self.isNumber = isNumber
self.match = match
self.isEDTFDate = isEDTFDate
self.isRefType = isRefType
self.hasVariable = hasVariable
self.locale = locale
}
}
public enum TemplateModelFormat: Codable {
case string(String)
case templateModelArray([TemplateModel])
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
if let x = try? container.decode([TemplateModel].self) {
self = .templateModelArray(x)
return
}
if let x = try? container.decode(String.self) {
self = .string(x)
return
}
throw DecodingError.typeMismatch(TemplateModelFormat.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Wrong type for TemplateModelFormat"))
}
public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
switch self {
case .string(let x):
try container.encode(x)
case .templateModelArray(let x):
try container.encode(x)
}
}
}
/// A template that is defined inline.
///
/// Integral citations are those where the author is printed inline in the text; aka "in
/// text" or "narrative" citations.
///
/// Non-integral citations are those where the author is incorporated in the citation, and
/// not printed inline in the text.
// MARK: - TemplateModel
public struct TemplateModel: Codable {
public let bold: Bool?
/// The string with which to join two or more rendering comnponents.
public let delimiter: String?
public let emph: Bool?
/// The rendering instructions; either called template name, or inline instructions.
public let format: TemplateModelFormat?
public let options: OptionGroup?
/// The symbol pair to wrap around one or more rendering components.
/// Interaction with surrounding punctuation is localized.
public let wrap: WrapType?
/// The template name to use for partial formatting.
public let template: String?
public let variable: VariableEnum?
/// When all of the when conditions are nil, format the children.
public let templateModelElse: [TemplateModel]?
/// For the first condition that is non-nil, format the children.
public let when: [Condition]?
enum CodingKeys: String, CodingKey {
case bold, delimiter, emph, format, options, wrap, template, variable
case templateModelElse = "else"
case when
}
public init(bold: Bool?, delimiter: String?, emph: Bool?, format: TemplateModelFormat?, options: OptionGroup?, wrap: WrapType?, template: String?, variable: VariableEnum?, templateModelElse: [TemplateModel]?, when: [Condition]?) {
self.bold = bold
self.delimiter = delimiter
self.emph = emph
self.format = format
self.options = options
self.wrap = wrap
self.template = template
self.variable = variable
self.templateModelElse = templateModelElse
self.when = when
}
}
public enum VariableType: String, Codable {
case article = "article"
case author = "author"
case book = "book"
case chapter = "chapter"
case containerTitle = "container-title"
case editor = "editor"
case issue = "issue"
case issued = "issued"
case pages = "pages"
case publisher = "publisher"
case title = "title"
case volume = "volume"
}
/// Does the date conform to EDTF?
public enum DateType: String, Codable {
case issued = "issued"
}
/// Is the item variable a number?
public enum LocatorType: String, Codable {
case chapter = "chapter"
case page = "page"
}
public enum RefType: String, Codable {
case article = "article"
case book = "book"
case chapter = "chapter"
}
/// A list of reference item types; if one is true, then return true.
public enum MatchType: String, Codable {
case all = "all"
case any = "any"
case none = "none"
}
/// Parameter groups.
///
/// Global parameter options.
// MARK: - OptionGroup
public struct OptionGroup: Codable {
/// Date formatting configuration.
public let dateFormatting: DateFormatting?
/// Disambiguation configuration of rendererd group display names.
public let disambiguate: Disambiguation?
/// Grouping configuration.
public let group: [GroupSortType]?
/// Localization configuration.
public let localization: Localization?
/// Sorting configuration.
public let sort: [Sort]?
/// Substitution configuration.
public let substitute: Substitution?
public init(dateFormatting: DateFormatting?, disambiguate: Disambiguation?, group: [GroupSortType]?, localization: Localization?, sort: [Sort]?, substitute: Substitution?) {
self.dateFormatting = dateFormatting
self.disambiguate = disambiguate
self.group = group
self.localization = localization
self.sort = sort
self.substitute = substitute
}
}
/// Date formatting configuration.
// MARK: - DateFormatting
public struct DateFormatting: Codable {
public let date: EStyle?
public let month: MonthStyle?
public let time: EStyle?
public let year: YearStyle?
public init(date: EStyle?, month: MonthStyle?, time: EStyle?, year: YearStyle?) {
self.date = date
self.month = month
self.time = time
self.year = year
}
}
public enum EStyle: String, Codable {
case full = "full"
case long = "long"
case medium = "medium"
case short = "short"
}
public enum MonthStyle: String, Codable {
case long = "long"
case narrow = "narrow"
case numeric = "numeric"
case short = "short"
case the2Digit = "2-digit"
}
public enum YearStyle: String, Codable {
case numeric = "numeric"
case the2Digit = "2-digit"
}
/// Disambiguation configuration of rendererd group display names.
///
/// Disambiguation of rendered group display name configuration.
// MARK: - Disambiguation
public struct Disambiguation: Codable {
public let addNames: AddNames?
public let addYearSuffix: Bool?
public init(addNames: AddNames?, addYearSuffix: Bool?) {
self.addNames = addNames
self.addYearSuffix = addYearSuffix
}
}
public enum AddNames: String, Codable {
case all = "all"
case allWithInitials = "all-with-initials"
case byCite = "by-cite"
case primary = "primary"
case primaryWithInitials = "primary-with-initials"
}
public enum GroupSortType: String, Codable {
case asCited = "as-cited"
case author = "author"
case title = "title"
case year = "year"
}
/// Localization configuration.
///
/// Terms and data localization configuration.
// MARK: - Localization
public struct Localization: Codable {
/// The scope to use for localization.
///
/// "per-item" uses the locale of the reference item, and "global" uses the target language
/// across all references.
public let scope: Scope?
public init(scope: Scope?) {
self.scope = scope
}
}
/// The scope to use for localization.
///
/// "per-item" uses the locale of the reference item, and "global" uses the target language
/// across all references.
public enum Scope: String, Codable {
case global = "global"
case perItem = "per-item"
}
/// Reference sorting configuration.
// MARK: - Sort
public struct Sort: Codable {
public let key: GroupSortType
public let order: Order
public init(key: GroupSortType, order: Order) {
self.key = key
self.order = order
}
}
public enum Order: String, Codable {
case ascending = "ascending"
case descending = "descending"
}
/// Substitution configuration.
///
/// Substitution of variable configuration.
// MARK: - Substitution
public struct Substitution: Codable {
/// When author is nil, substitute the first non-nil listed variable.
/// Once a substitution is made, the substituted variable shall be set to nil for purposes of
/// later rendering.
public let author: [SubstitutionType]
public init(author: [SubstitutionType]) {
self.author = author
}
}
public enum SubstitutionType: String, Codable {
case editor = "editor"
case title = "title"
case translator = "translator"
}
/// Is the item variable a number?
///
/// Does the date conform to EDTF?
public enum VariableEnum: String, Codable {
case author = "author"
case chapter = "chapter"
case containerTitle = "container-title"
case editor = "editor"
case issue = "issue"
case issued = "issued"
case page = "page"
case pages = "pages"
case publisher = "publisher"
case title = "title"
case volume = "volume"
}
/// The symbol pair to wrap around one or more rendering components.
/// Interaction with surrounding punctuation is localized.
public enum WrapType: String, Codable {
case brackets = "brackets"
case parentheses = "parentheses"
case quotes = "quotes"
}
public enum CategoryType: String, Codable {
case biology = "biology"
case science = "science"
case socialScience = "social science"
}
/// The citation specification.
// MARK: - Citation
public struct Citation: Codable {
public let bold: Bool?
/// The string with which to join two or more rendering comnponents.
public let delimiter: String?
public let emph: Bool?
/// The rendering instructions; either called template name, or inline instructions.
public let format: BibliographyFormat?
/// Integral citations are those where the author is printed inline in the text; aka "in
/// text" or "narrative" citations.
public let integral: RenderList?
/// Non-integral citations are those where the author is incorporated in the citation, and
/// not printed inline in the text.
public let nonIntegral: RenderList?
public let options: OptionGroup?
public let placement: Placement?
/// The symbol pair to wrap around one or more rendering components.
/// Interaction with surrounding punctuation is localized.
public let wrap: WrapType?
public init(bold: Bool?, delimiter: String?, emph: Bool?, format: BibliographyFormat?, integral: RenderList?, nonIntegral: RenderList?, options: OptionGroup?, placement: Placement?, wrap: WrapType?) {
self.bold = bold
self.delimiter = delimiter
self.emph = emph
self.format = format
self.integral = integral
self.nonIntegral = nonIntegral
self.options = options
self.placement = placement
self.wrap = wrap
}
}
/// Integral citations are those where the author is printed inline in the text; aka "in
/// text" or "narrative" citations.
///
/// Non-integral citations are those where the author is incorporated in the citation, and
/// not printed inline in the text.
// MARK: - RenderList
public struct RenderList: Codable {
public let bold: Bool?
/// The string with which to join two or more rendering comnponents.
public let delimiter: String?
public let emph: Bool?
/// The rendering instructions; either called template name, or inline instructions.
public let format: BibliographyFormat?
public let options: OptionGroup?
/// The symbol pair to wrap around one or more rendering components.
/// Interaction with surrounding punctuation is localized.
public let wrap: WrapType?
public init(bold: Bool?, delimiter: String?, emph: Bool?, format: BibliographyFormat?, options: OptionGroup?, wrap: WrapType?) {
self.bold = bold
self.delimiter = delimiter
self.emph = emph
self.format = format
self.options = options
self.wrap = wrap
}
}
public enum Placement: String, Codable {
case inline = "inline"
case note = "note"
}
// MARK: - NamedTemplate
public struct NamedTemplate: Codable {
/// The name token for the template, for reference from other templates.
public let name: String
public let options: OptionGroup?
public let template: [TemplateModel]
public init(name: String, options: OptionGroup?, template: [TemplateModel]) {
self.name = name
self.options = options
self.template = template
}
}
/// this is directly converted from the typescript
/// it seems to get a bit confused on the entry point
/// should be Style
// Example code that deserializes and serializes the model.
// extern crate serde;
// #[macro_use]
// extern crate serde_derive;
// extern crate serde_json;
//
// use generated_module::TemplateFile;
//
// fn main() {
// let json = r#"{"answer": 42}"#;
// let model: TemplateFile = serde_json::from_str(&json).unwrap();
// }
use serde::{Serialize, Deserialize};
pub type CalledTemplate = String;
pub type InlineTemplate = Vec<TemplateModel>;
/// The CSL NEXT style model.
#[derive(Serialize, Deserialize)]
pub struct TemplateFile {
#[serde(rename = "description")]
description: Option<String>,
#[serde(rename = "templates")]
templates: Vec<NamedTemplate>,
#[serde(rename = "title")]
title: Option<String>,
}
#[derive(Serialize, Deserialize)]
pub struct NamedTemplate {
/// The name token for the template, for reference from other templates.
#[serde(rename = "name")]
name: String,
/// Parameter groups.
#[serde(rename = "options")]
options: Option<OptionGroup>,
/// A template that is defined inline.
#[serde(rename = "template")]
template: Vec<TemplateModel>,
}
/// Parameter groups.
///
/// Global parameter options.
#[derive(Serialize, Deserialize)]
pub struct OptionGroup {
/// Date formatting configuration.
#[serde(rename = "dateFormatting")]
date_formatting: Option<DateFormatting>,
/// Disambiguation configuration of rendererd group display names.
#[serde(rename = "disambiguate")]
disambiguate: Option<Disambiguation>,
/// Grouping configuration.
#[serde(rename = "group")]
group: Option<Vec<GroupSortType>>,
/// Localization configuration.
#[serde(rename = "localization")]
localization: Option<Localization>,
/// Sorting configuration.
#[serde(rename = "sort")]
sort: Option<Vec<Sort>>,
/// Substitution configuration.
#[serde(rename = "substitute")]
substitute: Option<Substitution>,
}
/// Date formatting configuration.
#[derive(Serialize, Deserialize)]
pub struct DateFormatting {
#[serde(rename = "date")]
date: Option<TimeStyle>,
#[serde(rename = "month")]
month: Option<MonthStyle>,
#[serde(rename = "time")]
time: Option<TimeStyle>,
#[serde(rename = "year")]
year: Option<YearStyle>,
}
/// Disambiguation configuration of rendererd group display names.
///
/// Disambiguation of rendered group display name configuration.
#[derive(Serialize, Deserialize)]
pub struct Disambiguation {
#[serde(rename = "addNames")]
add_names: Option<AddNames>,
#[serde(rename = "addYearSuffix")]
add_year_suffix: Option<bool>,
}
/// Localization configuration.
///
/// Terms and data localization configuration.
#[derive(Serialize, Deserialize)]
pub struct Localization {
/// The scope to use for localization.
///
/// "per-item" uses the locale of the reference item, and "global" uses the target language
/// across all references.
#[serde(rename = "scope")]
scope: Option<Scope>,
}
/// Reference sorting configuration.
#[derive(Serialize, Deserialize)]
pub struct Sort {
#[serde(rename = "key")]
key: GroupSortType,
#[serde(rename = "order")]
order: Order,
}
/// Substitution configuration.
///
/// Substitution of variable configuration.
#[derive(Serialize, Deserialize)]
pub struct Substitution {
/// When author is nil, substitute the first non-nil listed variable.
/// Once a substitution is made, the substituted variable shall be set to nil for purposes of
/// later rendering.
#[serde(rename = "author")]
author: Vec<SubstitutionType>,
}
#[derive(Serialize, Deserialize)]
pub struct Condition {
/// When a match, process these templates.
#[serde(rename = "format")]
format: Vec<TemplateModel>,
/// Is the item variable a number?
#[serde(rename = "isNumber")]
is_number: Option<LocatorType>,
/// A list of reference item types; if one is true, then return true.
#[serde(rename = "match")]
condition_match: Option<MatchType>,
/// Does the date conform to EDTF?
#[serde(rename = "isEDTFDate")]
is_edtf_date: Option<DateType>,
/// Is the item reference type among the listed reference types?
#[serde(rename = "isRefType")]
is_ref_type: Option<Vec<RefType>>,
/// Does the item reference include one of the listed variables?
#[serde(rename = "hasVariable")]
has_variable: Option<Vec<VariableType>>,
/// The item reference locale; to allow multilingual output.
#[serde(rename = "locale")]
locale: Option<String>,
}
/// A template that is defined inline.
///
/// Integral citations are those where the author is printed inline in the text; aka "in
/// text" or "narrative" citations.
///
/// Non-integral citations are those where the author is incorporated in the citation, and
/// not printed inline in the text.
#[derive(Serialize, Deserialize)]
pub struct TemplateModel {
#[serde(rename = "bold")]
bold: Option<bool>,
/// The string with which to join two or more rendering comnponents.
#[serde(rename = "delimiter")]
delimiter: Option<String>,
#[serde(rename = "emph")]
emph: Option<bool>,
/// The rendering instructions; either called template name, or inline instructions.
#[serde(rename = "format")]
format: Option<TemplateModelFormat>,
/// Parameter groups.
#[serde(rename = "options")]
options: Option<OptionGroup>,
/// The symbol pair to wrap around one or more rendering components.
/// Interaction with surrounding punctuation is localized.
#[serde(rename = "wrap")]
wrap: Option<WrapType>,
/// The template name to use for partial formatting.
#[serde(rename = "template")]
template: Option<String>,
#[serde(rename = "variable")]
variable: Option<VariableEnum>,
/// A template that is defined inline.
#[serde(rename = "else")]
template_model_else: Option<Vec<TemplateModel>>,
/// For the first condition that is non-nil, format the children.
#[serde(rename = "when")]
when: Option<Vec<Condition>>,
}
#[derive(Serialize, Deserialize)]
pub struct HasFormatting {
#[serde(rename = "bold")]
bold: Option<bool>,
#[serde(rename = "emph")]
emph: Option<bool>,
/// The symbol pair to wrap around one or more rendering components.
/// Interaction with surrounding punctuation is localized.
#[serde(rename = "wrap")]
wrap: Option<WrapType>,
}
#[derive(Serialize, Deserialize)]
pub struct SortType {
#[serde(rename = "key")]
key: GroupSortType,
/// The order to sort the list.
#[serde(rename = "order")]
order: Order,
}
#[derive(Serialize, Deserialize)]
pub struct Cond {
/// A template that is defined inline.
#[serde(rename = "else")]
cond_else: Option<Vec<TemplateModel>>,
/// For the first condition that is non-nil, format the children.
#[serde(rename = "when")]
when: Option<Vec<Condition>>,
}
#[derive(Serialize, Deserialize)]
pub struct Match {
/// When a match, process these templates.
#[serde(rename = "format")]
format: Vec<TemplateModel>,
/// A list of reference item types; if one is true, then return true.
#[serde(rename = "match")]
match_match: Option<MatchType>,
}
#[derive(Serialize, Deserialize)]
pub struct IsNumber {
/// Is the item variable a number?
#[serde(rename = "isNumber")]
is_number: LocatorType,
}
#[derive(Serialize, Deserialize)]
pub struct IsEdtfDate {
/// Does the date conform to EDTF?
#[serde(rename = "isEDTFDate")]
is_edtf_date: DateType,
}
#[derive(Serialize, Deserialize)]
pub struct IsRefType {
/// Is the item reference type among the listed reference types?
#[serde(rename = "isRefType")]
is_ref_type: Vec<RefType>,
}
#[derive(Serialize, Deserialize)]
pub struct HasVariable {
/// Does the item reference include one of the listed variables?
#[serde(rename = "hasVariable")]
has_variable: Vec<VariableType>,
}
#[derive(Serialize, Deserialize)]
pub struct Locale {
/// The item reference locale; to allow multilingual output.
#[serde(rename = "locale")]
locale: String,
}
#[derive(Serialize, Deserialize)]
pub struct DataTypeMatch {
/// Is the item variable a number?
#[serde(rename = "isNumber")]
is_number: Option<LocatorType>,
/// Does the date conform to EDTF?
#[serde(rename = "isEDTFDate")]
is_edtf_date: Option<DateType>,
/// Is the item reference type among the listed reference types?
#[serde(rename = "isRefType")]
is_ref_type: Option<Vec<RefType>>,
/// Does the item reference include one of the listed variables?
#[serde(rename = "hasVariable")]
has_variable: Option<Vec<VariableType>>,
/// The item reference locale; to allow multilingual output.
#[serde(rename = "locale")]
locale: Option<String>,
}
#[derive(Serialize, Deserialize)]
pub struct SortGroup {
#[serde(rename = "key")]
key: GroupSortType,
}
/// Reference grouping of configuration.
#[derive(Serialize, Deserialize)]
pub struct Group {
/// The string with which to join two or more rendering comnponents.
#[serde(rename = "delimiter")]
delimiter: Option<String>,
#[serde(rename = "key")]
key: GroupSortType,
}
/// A CSL Style.
#[derive(Serialize, Deserialize)]
pub struct Style {
/// The bibliography specification.
#[serde(rename = "bibliography")]
bibliography: Option<Bibliography>,
/// r
/// The categories the style belongs to; for purposes of indexing.
#[serde(rename = "categories")]
categories: Option<Vec<CategoryType>>,
/// The citation specification.
#[serde(rename = "citation")]
citation: Option<Citation>,
/// The description of the style.
#[serde(rename = "description")]
description: Option<String>,
/// The machine-readable token that uniquely identifies the style.
#[serde(rename = "id")]
id: Option<String>,
/// Global parameter options.
#[serde(rename = "options")]
options: Option<OptionGroup>,
/// The templates for rendering the bibliography and citations.
#[serde(rename = "templates")]
templates: Option<Vec<NamedTemplate>>,
/// The human-readable name of the style.
#[serde(rename = "title")]
title: Option<String>,
}
/// The bibliography specification.
#[derive(Serialize, Deserialize)]
pub struct Bibliography {
#[serde(rename = "bold")]
bold: Option<bool>,
/// The string with which to join two or more rendering comnponents.
#[serde(rename = "delimiter")]
delimiter: Option<String>,
#[serde(rename = "emph")]
emph: Option<bool>,
/// The rendering instructions; either called template name, or inline instructions.
#[serde(rename = "format")]
format: Option<BibliographyFormat>,
#[serde(rename = "heading")]
heading: Option<String>,
#[serde(rename = "listStyle")]
list_style: Option<String>,
/// Parameter groups.
#[serde(rename = "options")]
options: Option<OptionGroup>,
/// The symbol pair to wrap around one or more rendering components.
/// Interaction with surrounding punctuation is localized.
#[serde(rename = "wrap")]
wrap: Option<WrapType>,
}
/// The citation specification.
#[derive(Serialize, Deserialize)]
pub struct Citation {
#[serde(rename = "bold")]
bold: Option<bool>,
/// The string with which to join two or more rendering comnponents.
#[serde(rename = "delimiter")]
delimiter: Option<String>,
#[serde(rename = "emph")]
emph: Option<bool>,
/// The rendering instructions; either called template name, or inline instructions.
#[serde(rename = "format")]
format: Option<BibliographyFormat>,
/// Integral citations are those where the author is printed inline in the text; aka "in
/// text" or "narrative" citations.
#[serde(rename = "integral")]
integral: Option<RenderList>,
/// Non-integral citations are those where the author is incorporated in the citation, and
/// not printed inline in the text.
#[serde(rename = "nonIntegral")]
non_integral: Option<RenderList>,
/// Parameter groups.
#[serde(rename = "options")]
options: Option<OptionGroup>,
#[serde(rename = "placement")]
placement: Option<Placement>,
/// The symbol pair to wrap around one or more rendering components.
/// Interaction with surrounding punctuation is localized.
#[serde(rename = "wrap")]
wrap: Option<WrapType>,
}
/// Integral citations are those where the author is printed inline in the text; aka "in
/// text" or "narrative" citations.
///
/// Non-integral citations are those where the author is incorporated in the citation, and
/// not printed inline in the text.
#[derive(Serialize, Deserialize)]
pub struct RenderList {
#[serde(rename = "bold")]
bold: Option<bool>,
/// The string with which to join two or more rendering comnponents.
#[serde(rename = "delimiter")]
delimiter: Option<String>,
#[serde(rename = "emph")]
emph: Option<bool>,
/// The rendering instructions; either called template name, or inline instructions.
#[serde(rename = "format")]
format: Option<BibliographyFormat>,
/// Parameter groups.
#[serde(rename = "options")]
options: Option<OptionGroup>,
/// The symbol pair to wrap around one or more rendering components.
/// Interaction with surrounding punctuation is localized.
#[serde(rename = "wrap")]
wrap: Option<WrapType>,
}
#[derive(Serialize, Deserialize)]
pub struct RenderItemTemplate {
#[serde(rename = "bold")]
bold: Option<bool>,
#[serde(rename = "emph")]
emph: Option<bool>,
/// The template name to use for partial formatting.
#[serde(rename = "template")]
template: String,
/// The symbol pair to wrap around one or more rendering components.
/// Interaction with surrounding punctuation is localized.
#[serde(rename = "wrap")]
wrap: Option<WrapType>,
}
#[derive(Serialize, Deserialize)]
pub struct RenderListBlock {
#[serde(rename = "bold")]
bold: Option<bool>,
/// The string with which to join two or more rendering comnponents.
#[serde(rename = "delimiter")]
delimiter: Option<String>,
#[serde(rename = "emph")]
emph: Option<bool>,
/// The rendering instructions; either called template name, or inline instructions.
#[serde(rename = "format")]
format: Option<BibliographyFormat>,
#[serde(rename = "listStyle")]
list_style: Option<String>,
/// Parameter groups.
#[serde(rename = "options")]
options: Option<OptionGroup>,
/// The symbol pair to wrap around one or more rendering components.
/// Interaction with surrounding punctuation is localized.
#[serde(rename = "wrap")]
wrap: Option<WrapType>,
}
#[derive(Serialize, Deserialize)]
pub struct RenderItemSimple {
#[serde(rename = "bold")]
bold: Option<bool>,
#[serde(rename = "emph")]
emph: Option<bool>,
#[serde(rename = "variable")]
variable: SimpleType,
/// The symbol pair to wrap around one or more rendering components.
/// Interaction with surrounding punctuation is localized.
#[serde(rename = "wrap")]
wrap: Option<WrapType>,
}
#[derive(Serialize, Deserialize)]
pub struct RenderItemDate {
#[serde(rename = "bold")]
bold: Option<bool>,
#[serde(rename = "emph")]
emph: Option<bool>,
#[serde(rename = "variable")]
variable: DateType,
/// The symbol pair to wrap around one or more rendering components.
/// Interaction with surrounding punctuation is localized.
#[serde(rename = "wrap")]
wrap: Option<WrapType>,
}
#[derive(Serialize, Deserialize)]
pub struct RenderTitle {
#[serde(rename = "bold")]
bold: Option<bool>,
#[serde(rename = "emph")]
emph: Option<bool>,
#[serde(rename = "variable")]
variable: TitleType,
/// The symbol pair to wrap around one or more rendering components.
/// Interaction with surrounding punctuation is localized.
#[serde(rename = "wrap")]
wrap: Option<WrapType>,
}
#[derive(Serialize, Deserialize)]
pub struct RenderContributors {
#[serde(rename = "bold")]
bold: Option<bool>,
/// The string with which to join two or more rendering comnponents.
#[serde(rename = "delimiter")]
delimiter: Option<String>,
#[serde(rename = "emph")]
emph: Option<bool>,
/// The rendering instructions; either called template name, or inline instructions.
#[serde(rename = "format")]
format: Option<BibliographyFormat>,
/// Parameter groups.
#[serde(rename = "options")]
options: Option<OptionGroup>,
#[serde(rename = "variable")]
variable: ContributorType,
/// The symbol pair to wrap around one or more rendering components.
/// Interaction with surrounding punctuation is localized.
#[serde(rename = "wrap")]
wrap: Option<WrapType>,
}
#[derive(Serialize, Deserialize)]
pub struct RenderLocators {
#[serde(rename = "bold")]
bold: Option<bool>,
/// The string with which to join two or more rendering comnponents.
#[serde(rename = "delimiter")]
delimiter: Option<String>,
#[serde(rename = "emph")]
emph: Option<bool>,
/// The rendering instructions; either called template name, or inline instructions.
#[serde(rename = "format")]
format: Option<BibliographyFormat>,
/// Parameter groups.
#[serde(rename = "options")]
options: Option<OptionGroup>,
#[serde(rename = "variable")]
variable: LocatorType,
/// The symbol pair to wrap around one or more rendering components.
/// Interaction with surrounding punctuation is localized.
#[serde(rename = "wrap")]
wrap: Option<WrapType>,
}
#[derive(Serialize, Deserialize)]
#[serde(untagged)]
pub enum TemplateModelFormat {
String(String),
TemplateModelArray(Vec<TemplateModel>),
}
#[derive(Serialize, Deserialize)]
#[serde(untagged)]
pub enum Template {
String(String),
TemplateModelArray(Vec<TemplateModel>),
}
#[derive(Serialize, Deserialize)]
#[serde(untagged)]
pub enum BibliographyFormat {
String(String),
TemplateModelArray(Vec<TemplateModel>),
}
#[derive(Serialize, Deserialize)]
pub enum TimeStyle {
#[serde(rename = "full")]
Full,
#[serde(rename = "long")]
Long,
#[serde(rename = "medium")]
Medium,
#[serde(rename = "short")]
Short,
}
#[derive(Serialize, Deserialize)]
pub enum MonthStyle {
#[serde(rename = "long")]
Long,
#[serde(rename = "narrow")]
Narrow,
#[serde(rename = "numeric")]
Numeric,
#[serde(rename = "short")]
Short,
#[serde(rename = "2-digit")]
The2Digit,
}
#[derive(Serialize, Deserialize)]
pub enum YearStyle {
#[serde(rename = "numeric")]
Numeric,
#[serde(rename = "2-digit")]
The2Digit,
}
#[derive(Serialize, Deserialize)]
pub enum AddNames {
#[serde(rename = "all")]
All,
#[serde(rename = "all-with-initials")]
AllWithInitials,
#[serde(rename = "by-cite")]
ByCite,
#[serde(rename = "primary")]
Primary,
#[serde(rename = "primary-with-initials")]
PrimaryWithInitials,
}
#[derive(Serialize, Deserialize)]
pub enum GroupSortType {
#[serde(rename = "as-cited")]
AsCited,
#[serde(rename = "author")]
Author,
#[serde(rename = "title")]
Title,
#[serde(rename = "year")]
Year,
}
/// The scope to use for localization.
///
/// "per-item" uses the locale of the reference item, and "global" uses the target language
/// across all references.
#[derive(Serialize, Deserialize)]
pub enum Scope {
#[serde(rename = "global")]
Global,
#[serde(rename = "per-item")]
PerItem,
}
/// The order to sort the list.
#[derive(Serialize, Deserialize)]
pub enum Order {
#[serde(rename = "ascending")]
Ascending,
#[serde(rename = "descending")]
Descending,
}
#[derive(Serialize, Deserialize)]
pub enum SubstitutionType {
#[serde(rename = "editor")]
Editor,
#[serde(rename = "title")]
Title,
#[serde(rename = "translator")]
Translator,
}
/// A list of reference item types; if one is true, then return true.
#[derive(Serialize, Deserialize)]
pub enum MatchType {
#[serde(rename = "all")]
All,
#[serde(rename = "any")]
Any,
#[serde(rename = "none")]
None,
}
#[derive(Serialize, Deserialize)]
pub enum VariableType {
#[serde(rename = "article")]
Article,
#[serde(rename = "author")]
Author,
#[serde(rename = "book")]
Book,
#[serde(rename = "chapter")]
Chapter,
#[serde(rename = "container-title")]
ContainerTitle,
#[serde(rename = "editor")]
Editor,
#[serde(rename = "issue")]
Issue,
#[serde(rename = "issued")]
Issued,
#[serde(rename = "pages")]
Pages,
#[serde(rename = "publisher")]
Publisher,
#[serde(rename = "title")]
Title,
#[serde(rename = "volume")]
Volume,
}
/// Does the date conform to EDTF?
#[derive(Serialize, Deserialize)]
pub enum DateType {
#[serde(rename = "issued")]
Issued,
}
/// Is the item variable a number?
#[derive(Serialize, Deserialize)]
pub enum LocatorType {
#[serde(rename = "chapter")]
Chapter,
#[serde(rename = "page")]
Page,
}
#[derive(Serialize, Deserialize)]
pub enum RefType {
#[serde(rename = "article")]
Article,
#[serde(rename = "book")]
Book,
#[serde(rename = "chapter")]
Chapter,
}
/// Is the item variable a number?
#[derive(Serialize, Deserialize)]
pub enum VariableEnum {
#[serde(rename = "author")]
Author,
#[serde(rename = "chapter")]
Chapter,
#[serde(rename = "container-title")]
ContainerTitle,
#[serde(rename = "editor")]
Editor,
#[serde(rename = "issue")]
Issue,
#[serde(rename = "issued")]
Issued,
#[serde(rename = "page")]
Page,
#[serde(rename = "pages")]
Pages,
#[serde(rename = "publisher")]
Publisher,
#[serde(rename = "title")]
Title,
#[serde(rename = "volume")]
Volume,
}
/// The symbol pair to wrap around one or more rendering components.
/// Interaction with surrounding punctuation is localized.
#[derive(Serialize, Deserialize)]
pub enum WrapType {
#[serde(rename = "brackets")]
Brackets,
#[serde(rename = "parentheses")]
Parentheses,
#[serde(rename = "quotes")]
Quotes,
}
#[derive(Serialize, Deserialize)]
pub enum CategoryType {
#[serde(rename = "biology")]
Biology,
#[serde(rename = "science")]
Science,
#[serde(rename = "social science")]
SocialScience,
}
#[derive(Serialize, Deserialize)]
pub enum Placement {
#[serde(rename = "inline")]
Inline,
#[serde(rename = "note")]
Note,
}
#[derive(Serialize, Deserialize)]
pub enum SimpleType {
#[serde(rename = "issue")]
Issue,
#[serde(rename = "pages")]
Pages,
#[serde(rename = "volume")]
Volume,
}
#[derive(Serialize, Deserialize)]
pub enum TitleType {
#[serde(rename = "container-title")]
ContainerTitle,
#[serde(rename = "title")]
Title,
}
#[derive(Serialize, Deserialize)]
pub enum ContributorType {
#[serde(rename = "author")]
Author,
#[serde(rename = "editor")]
Editor,
#[serde(rename = "publisher")]
Publisher,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment