Last active
February 3, 2016 03:38
-
-
Save billdueber/913d18485d682605f8ba to your computer and use it in GitHub Desktop.
Simple render of a ruby MARC::Record with slim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: UTF-8 | |
require 'slim' | |
require 'marc' | |
# Get a record somehow. Here, I just nab the marc-in-json from the HT catalog and use that. | |
require 'json' | |
require 'open-uri' | |
rec = MARC::Record.new_from_hash(JSON.parse(open('http://catalog.hathitrust.org/Record/100113248.json').read)) | |
# Toggle between 'even' and 'odd' for striping of the lines | |
def neweo | |
%w[even odd].enum_for(:cycle) | |
end | |
SPACECHAR = "\u23B5".freeze | |
t = Slim::Template.new { DATA.read } | |
puts t.render(Object.new, title: rec['245'].value, r: rec) | |
__END__ | |
doctype 5 | |
html | |
head | |
title = title | |
meta charset="utf-8" | |
css: | |
.odd {background-color: #eee} | |
li {padding: 0pt} | |
ul.line {padding: 0.25em 0px 0px 0px; margin: 0em; height: auto;} | |
ul.line li, ul.subs, ul.subs li, ul.kv, ul.kv li { display: inline; font-family: courier;} | |
li.ind { margin-right: 0.75em; margin-left: 0.75em; font-family: courier;} | |
ul.kv {padding-left: 0.2em;} | |
ul.kv li.code {color: red; margin-left: 0.5em; } | |
ul.kv li.code:before { content: "\2021"; display: inline-block;} | |
body | |
h1 = r['245'].value | |
- eo = neweo | |
ul class=["line", eo.next] | |
li.tag LDR | |
li.ind = " " | |
li.value = r.leader.gsub(/\s/, SPACECHAR) | |
- for field in r | |
- if MARC::ControlField.control_tag?(field.tag) | |
ul class=["line", eo.next] | |
li.tag = field.tag | |
li.ind = " " | |
li.value = field.value.gsub(/\s/, SPACECHAR) | |
- else | |
ul class=["line", eo.next] | |
li.tag = field.tag | |
li.ind = "#{field.indicator1}#{field.indicator2}".gsub(/\s/, SPACECHAR) | |
li.subs | |
- for sf in field | |
ul.kv | |
li.code = sf.code | |
li.value = sf.value | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment