Skip to content

Instantly share code, notes, and snippets.

@jweisman jweisman/bibcard.html.erb
Last active May 10, 2019

What would you like to do?
Linked Data example - Alma JSONLD and BibCard
<!doctype html>
<html lang="en">
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title><%= viewmodel[:title] %></title>
<div class="container">
<h1>Author Card for <%= viewmodel[:title] %></h1>
<div class="card" style="width: 18rem;">
<h5 class="card-header">Author</h5>
<img class="card-img-top" src="<%= viewmodel[:thumbnail] %>" alt="Card image cap">
<div class="card-body">
<h5 class="card-title"><%= viewmodel[:author_name] %></h5>
<h6 class="card-subtitle mb-2 text-muted"><%= viewmodel[:lifespan] %></h6>
<p class="card-text"><%= viewmodel[:desc] %></p>
<a href="<%= viewmodel[:url] %>" class="btn btn-primary" target="_new">More info</a>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
require 'bib_card'
require 'erb'
require 'rest-client'
abort 'Please provide MMS_ID' if !ARGV[0]
puts "Retrieving JSONLD for MMS_ID #{ARGV[0]}"
jsonld = JSON.parse(RestClient.get(JSONLD_URL + ARGV[0]), symbolize_names: true)
if jsonld[:creator].is_a?(Array)
creator = jsonld[:creator].find {|i| i[:@id].include?(LCNAF_PREFIX)}
creator = jsonld[:creator] if jsonld[:creator][:@id].include?(LCNAF_PREFIX)
if creator
lcnaf_uri = creator[:@id]
abort 'No LC Names URI found' if !lcnaf_uri
puts "Retrieving LC Names for #{lcnaf_uri}"
person = BibCard.person(lcnaf_uri)
viewmodel = {
title: jsonld[:title],
author_name:["en", "en-US"]),
lifespan: 'Born: ' + Date.parse(person.birth_date).strftime("%v") +
(person.death_date ? ', Deceased: ' + Date.parse(person.death_date).strftime("%v") : ''),
desc: person.wikidata_entity.description,
thumbnail: person.dbpedia_resource.thumbnail,
url: lcnaf_uri
filename = lcnaf_uri.split('/')[-1] + ".html"
puts "Writing author card file #{filename}"
renderer ="bibcard.html.erb")
File.write filename, renderer.result()
system("open #{filename}")

This comment has been minimized.

Copy link
Owner Author

jweisman commented Apr 26, 2018

This Gist uses the BibCard gem from UW Madison. Installation instructions are available at the repository readme.

Note that the demo there didn't work because of this error downstream in Spira:

ruby/gems/2.4.0/gems/spira-3.0.0/lib/spira/base.rb:288:in `reset_changes': undefined method `clear' for nil:NilClass (NoMethodError)

For now I commented out this line in base.rb in my local gem:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.