Skip to content
Snippets Groups Projects
Unverified Commit 63b44c8a authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

hal with citation

parent 921b0c9d
No related branches found
No related tags found
No related merge requests found
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
......@@ -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)
......
......@@ -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|
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment