TPAC: Make RDFa Lite current with schema.org state user/dbs/rdfa_lite
authorDan Scott <dscott@laurentian.ca>
Sun, 7 Apr 2013 23:54:42 +0000 (19:54 -0400)
committerDan Scott <dscott@laurentian.ca>
Mon, 8 Apr 2013 00:23:28 +0000 (20:23 -0400)
Break out Organizations, Persons, and MusicGroups like we did with
schema.org.

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Open-ILS/src/templates_rdfa/opac/parts/record/authors.tt2
Open-ILS/src/templates_rdfa/opac/parts/record/body.tt2
Open-ILS/src/templates_rdfa/opac/parts/record/contents.tt2
Open-ILS/src/templates_rdfa/opac/parts/record/subjects.tt2
Open-ILS/src/templates_rdfa/opac/parts/record/summary.tt2

index 5969588..e8020ff 100644 (file)
@@ -28,6 +28,10 @@ BLOCK build_author_links;
         qterm = '';
         iprop = '';
         tlabel = '';
+        birthdate = '';
+        deathdate = '';
+        graphics = [];
+        tag = node.getAttribute('tag');
         FOR subfield IN node.childNodes;
             NEXT UNLESS subfield.nodeName == "subfield";
             code = subfield.getAttribute('code');
@@ -35,24 +39,69 @@ BLOCK build_author_links;
                 relcode = subfield.textContent.substr(0,3);
                 tlabel = relators.$relcode || label;
             END;
+            IF code == '6';
+               target_field = tag;
+               linked_fields = [subfield.textContent()];
+               get_linked_880s;
+            END;
             NEXT UNLESS code.match('[a-z]');
             sf = subfield.textContent | html;
-            term = term _ ' ' _ sf;
             IF code.match('[acdq]');
                 sf_raw = subfield.textContent.replace('[#"^$\+\-,\.:;&|\[\]()]', ' ');
                 qterm = qterm _ ' ' _ sf_raw;
             END;
+            # Only Persons have birth/death dates in schema.org
+            IF code.match('d') && tag.substr(1,2) == '00';
+                IF subfield.textContent.match('^\s*\d{4}');
+                    birthdate = subfield.textContent.replace('^\s*(\d{4}).*$', '$1');
+                END;
+                IF subfield.textContent.match('-\d{4}\s*$');
+                    deathdate = subfield.textContent.replace('^\s*.{4}\-(\d{4})\s*$', '$1');
+                END;
+            ELSE;
+                term = term _ ' ' _ sf;
+            END;
         END;
         url = mkurl(ctx.opac_root _ '/results', {query => qterm, qtype => 'author'}, ['page', 'expand']);
         author_type = (tlabel || label) | html;
         
         # schema.org changes
         IF type == 'author';
-            iprop = ' property="accountablePerson"';
+            IF args.schema.itemtype && args.schema.itemtype.match('MusicAlbum');
+                iprop = ' typeof="http://schema.org/MusicGroup" property="byArtist"';
+            ELSIF tag.substr(1,2) == '00';
+                iprop = ' typeof="http://schema.org/Person" property="author"';
+            ELSE;
+                iprop = ' typeof="http://schema.org/Organization" property="author"';
+            END;
         ELSIF type == 'added';
-            iprop = ' property="contributor"';
+            IF tag.substr(1,2) == '00';
+                iprop = ' typeof="http://schema.org/Person" property="contributor"';
+            ELSE;
+                iprop = ' typeof="http://schema.org/Organization" property="contributor"';
+            END;
+        END;
+        '<a href="' _ url _ '"' _ iprop _ '>';
+        IF iprop; '<span property="name">'; END;
+        term.replace('^\s+', '');
+        IF iprop; '</span>'; END;
+        IF birthdate;
+            ' <span property="birthDate">' _ birthdate _ '</span>-';
+        END;
+        IF deathdate;
+            '<span property="deathDate">' _ deathdate _ '</span>';
+        END;
+        '</a>';
+        FOREACH link880 IN graphics;
+            diratt = '';
+            IF link880.dir;
+                diratt = ' dir="' _ link880.dir _ '"';
+            END;
+            ' <span class="graphic880"' _ diratt _ '>';
+            link880.value | html;
+            '</span>';
         END;
-        '<a href="' _ url _ '"' _ iprop _ '>' _ term.replace('^\s+', '') _ '</a> (' _ author_type _ '). ';
+        ' (' _ author_type _ '). ';
     END;
 END;
 %]
index 5bf95a4..352c366 100644 (file)
@@ -1,7 +1,7 @@
 [%-  attrs = {marc_xml => ctx.marc_xml};
     PROCESS "opac/parts/misc_util.tt2";
     PROCESS get_marc_attrs args=attrs;
-    stop_parms = ['expand','cnoffset'];
+    stop_parms = ['expand','cnoffset','copy_offset','copy_limit'];
     ctx.record_attrs = attrs; # capture for JS
 %]
 <div id='canvas_main' class='canvas' vocab='http://schema.org/' typeof='[% args.schema.itemtype %]'>
index ff96d73..29fc33b 100644 (file)
@@ -157,15 +157,26 @@ BLOCK render_contents;
     xpath = xpath || '//*[starts-with(@tag,"5")]';
     FOR node IN ctx.marc_xml.findnodes(xpath);
         all_content = [];
+        graphics = [];
         FOR subfield IN node.childNodes;
             NEXT UNLESS subfield.nodeName == "subfield";
             code = subfield.getAttribute('code');
+            IF code == '6';
+               linked_fields = [subfield.textContent()];
+               target_field = node.getAttribute('tag');
+               get_linked_880s;
+            END;
             NEXT UNLESS code.match('[a-z]');
             all_content.push(subfield.textContent);
         END;
         total_contents = all_content.join(" ").replace('\s+$', '');
         %] [% total_contents;
         IF total_contents.size; "<br/>"; END;
+        FOREACH link880 IN graphics;
+            '<div class="graphic880"' _ link880.dir _ '>';
+            link880.value | html;
+            '</div>';
+        END;
     END;
 END 
 %]
index f070c64..5460f5c 100644 (file)
         xpath = xpath || '//*[starts-with(@tag,"6")]';
         FOR node IN ctx.marc_xml.findnodes(xpath);
             all_terms = [];
+            graphics = [];
             FOR subfield IN node.childNodes;
                 NEXT UNLESS subfield.nodeName == "subfield";
                 code = subfield.getAttribute('code');
+                IF code == '6';
+                   linked_fields = [subfield.textContent()];
+                   target_field = node.getAttribute('tag');
+                   get_linked_880s;
+                END;
                 NEXT UNLESS code.match('[a-z]');
                 IF code.match('[vxyz]'); " &gt; "; END;
                 # at this point, we actually have a partial term to use.
 <a href="[% mkurl(ctx.opac_root _ '/results', {qtype=>'subject', query=>total_term}, stop_parms); %]">[% single_term %]</a>
             [%- END;
             IF all_terms.size; "<br/>"; END;
+            FOREACH link880 IN graphics;
+                '<div class="graphic880"' _ link880.dir _ '>';
+                link880.value | html;
+                '</div>';
+            END;
         END;
     END 
 %]
index 0a0901d..96d5bfd 100644 (file)
@@ -146,6 +146,21 @@ IF num_uris > 0;
     <li id='rdetail_edition'>
         <strong class='rdetail_label'>[% l("Edition:") %]</strong>
         <span class='rdetail_value'>[% attrs.edition | html %]</span>
+        [%-
+        FOR entry IN attrs.graphic_editions;
+            FOR alt IN entry.graphic;
+                diratt = "";
+                IF alt.dir;
+                    diratt = ' dir="' _ alt.dir _ '"';
+                END;
+        -%]
+        <div class="graphic880 rdetail_value"[% diratt %]>
+            [% alt.value | html %]
+        </div>
+        [%-
+            END;
+        END;
+        -%]
     </li>
     [%- END %]
     [%- IF attrs.publisher %]
@@ -160,6 +175,23 @@ IF num_uris > 0;
         [%- IF attrs.pubdate; %]
             <span property="datePublished">[% attrs.pubdate | html; %]</span>
         [%- END; %]
+        [%-
+        IF attrs.graphic_pubinfos.size > 0;
+            FOR entry IN attrs.graphic_pubinfos;
+                FOR alt IN entry.graphic;
+                    diratt = "";
+                    IF alt.dir;
+                        diratt = ' dir="' _ alt.dir _ '"';
+                    END;
+        -%]
+        <div class="graphic880"[% diratt %]>
+            [% alt.value | html %]
+        </div>
+        [%-
+                END;
+            END;
+        END
+        -%]
     </li>
     [%- END %]
 </ul>