diff --git a/app/models/concerns/with_citations.rb b/app/models/concerns/with_citations.rb index 2b7214615eaf610aabbc9b75f83a590ad7c523aa..3ebef124df61180c8e7a19030ce4a56cd220a773 100644 --- a/app/models/concerns/with_citations.rb +++ b/app/models/concerns/with_citations.rb @@ -1,28 +1,28 @@ module WithCitations extend ActiveSupport::Concern - def citation_apa(website) - citation_for(website, "apa") + def citation_apa(website: nil) + citation_for("apa", website: website) end - def citation_iso690(website) - citation_for(website, "iso690-author-date-fr-no-abstract") + def citation_iso690(website: nil) + citation_for("iso690-author-date-fr-no-abstract", website: website) end - def citation_mla(website) - citation_for(website, "modern-language-association") + def citation_mla(website: nil) + citation_for("modern-language-association", website: website) end protected - def citeproc_for_website(website) - raise NotImplementedError - end - - def citation_for(website, style) - citeproc = citeproc_for_website(website) + def citation_for(style, website: nil) + citeproc = to_citeproc(website: website) processor = CiteProc::Processor.new style: style, format: 'text' processor.import([citeproc]) processor.render(:bibliography, id: citeproc["id"]).first end + + def to_citeproc(website: nil) + raise NotImplementedError + end end \ No newline at end of file diff --git a/app/models/research/hal/publication.rb b/app/models/research/hal/publication.rb index c152537080bed4ec053e8371c8aa05e663c2ca1b..30bb0b72ff6f3d652e354b988280f874c02664e2 100644 --- a/app/models/research/hal/publication.rb +++ b/app/models/research/hal/publication.rb @@ -27,6 +27,7 @@ class Research::Hal::Publication < ApplicationRecord include AsIndirectObject include Sanitizable + include WithCitations include WithGitFiles include WithSlug @@ -108,6 +109,23 @@ class Research::Hal::Publication < ApplicationRecord protected + def to_citeproc(website: nil) + { + "title" => title, + "author" => authors.map { |author| + { "family" => author.last_name, "given" => author.first_name } + }, + "URL" => hal_url, + "container-title" => journal_title, + # "publisher" => university.name, + # "keywords" => keywords, + "pdf" => file, + "month-numeric" => publication_date.present? ? publication_date.month.to_s : nil, + "issued" => publication_date.present? ? { "date-parts" => [[publication_date.year, publication_date.month]] } : nil, + "id" => docid + } + end + def slug_unavailable?(slug) self.class.unscoped .where(slug: slug) diff --git a/app/models/research/journal/paper.rb b/app/models/research/journal/paper.rb index 793b684ea7e7bc798bbc51bc18e3b9cafee202b6..dacacb04f44ed567a57f5b7fd3b4b90b375c1bd7 100644 --- a/app/models/research/journal/paper.rb +++ b/app/models/research/journal/paper.rb @@ -106,7 +106,7 @@ class Research::Journal::Paper < ApplicationRecord protected - def citeproc_for_website(website) + def to_citeproc(website: nil) { "title" => title, "author" => people.map { |person|