Skip to content

Commit

Permalink
Merge branch 'gkellogg-feature/rdfa-lite' into develop
Browse files Browse the repository at this point in the history
Conflicts:
	js/core/rdfa.js

Needed to resolve conflicts with the changes from #371.
There was also a logic flaw that caused the RDFa annotations to be
applied to child elements of a section element even if they were not
headings.  Finally, a change from #371 was generating funny looking
IDs for headers on notes and issues.
  • Loading branch information
halindrome committed Dec 17, 2014
2 parents 050c01f + 8126bb9 commit 903b6b8
Show file tree
Hide file tree
Showing 15 changed files with 199 additions and 146 deletions.
10 changes: 5 additions & 5 deletions js/core/biblio.js
Expand Up @@ -78,7 +78,7 @@ define(
$sec.makeID(null, type + " references");
refs.sort();
var $dl = $("<dl class='bibliography'></dl>").appendTo($sec);
if (conf.doRDFa !== false) $dl.attr("about", "");
if (conf.doRDFa) $dl.attr("resource", "");
for (var j = 0; j < refs.length; j++) {
var ref = refs[j];
$("<dt></dt>")
Expand All @@ -87,10 +87,6 @@ define(
.appendTo($dl)
;
var $dd = $("<dd></dd>").appendTo($dl);
if (this.doRDFa !== false) {
if (type === "Normative") $dd.attr("rel", "dcterms:requires");
else $dd.attr("rel", "dcterms:references");
}
var refcontent = conf.biblio[ref]
, circular = {}
, key = ref;
Expand All @@ -110,6 +106,10 @@ define(
if (aliases[key].indexOf(ref) < 0) aliases[key].push(ref);
if (refcontent) {
$dd.html(stringifyRef(refcontent) + "\n");
if (conf.doRDFa) {
$a = $dd.children("a");
$a.attr("property", type === "Normative" ? "dc:requires" : "dc:references");
}
}
else {
if (!badrefs[ref]) badrefs[ref] = 0;
Expand Down
50 changes: 24 additions & 26 deletions js/core/rdfa.js
Expand Up @@ -10,50 +10,48 @@ define(
return {
run: function (conf, doc, cb, msg) {
msg.pub("start", "core/rdfa");
if (conf.doRDFa !== false) {
if (conf.doRDFa) {
$("section").each(function () {
var $sec = $(this)
, about = ""
, $fc = $sec.children("*").first()
, resource = ""
, $fc = $sec.children("h1,h2,h3,h4,h5,h6").first()
, ref = $sec.attr("id")
, fcref = null
;
if (ref) {
about = "#" + ref;
resource = "#" + ref;
}
else if ($fc.length) {
ref = $fc.attr("id");
if (ref) {
about = "#" + ref;
resource = "#" + ref;
fcref = ref;
}
}
if (about !== "") {
var property = "bibo:hasPart";
// Headings on everything but boilerplate
if (!resource.match(/#(abstract|sotd|toc)$/)) {
$sec.attr({
"typeof": "bibo:Chapter"
, resource: about
, rel: "bibo:Chapter"
, resource: resource
, property: property
});
// create a heading triple too, as per the role spec
// since we should not be putting an @role on
// h* elements with a value of heading, but we
// still want the semantic markup
if ($fc.length) {
if (!fcref) {
// there is no ID on the heading itself. Add one
fcref = $fc.makeID("h", ref) ;
}
$fc.attr({
about: "#" + fcref
, property: "xhv:role"
, resource: "xhv:heading"
});
}
// create a heading triple too, as per the role spec
// since we should not be putting an @role on
// h* elements with a value of heading, but we
// still want the semantic markup
if ($fc.length) {
if (!fcref) {
// if there is no ID on the heading itself. Add one
fcref = $fc.makeID("h", ref) ;
}
// set the subject to the ID of the heading
$fc.attr({ resource: "#" + fcref }) ;
// nest the contents in a span so we can set the predicate
// and object
$fc.wrapInner( "<span property='xhv:role' resource='xhv:heading'></span>" );
}
// annotate the child h* element



});
}
msg.pub("end", "core/rdfa");
Expand Down
2 changes: 1 addition & 1 deletion js/profile-w3c-common.js
Expand Up @@ -42,10 +42,10 @@ define([
, "core/dfn"
, "core/fix-headers"
, "core/structure"
, "core/rdfa"
, "w3c/informative"
, "w3c/permalinks"
, "core/id-headers"
, "core/rdfa"
, "w3c/aria"
, "core/shiv"
, "core/remove-respec"
Expand Down
18 changes: 4 additions & 14 deletions js/ui/save-html.js
Expand Up @@ -82,15 +82,10 @@ define(
, dt = doc.doctype;
if (dt && dt.publicId) str += " PUBLIC '" + dt.publicId + "' '" + dt.systemId + "'";
str += ">\n<html";
var ats = doc.documentElement.attributes
, prefixAtr = "";
var ats = doc.documentElement.attributes;
for (var i = 0; i < ats.length; i++) {
var an = ats[i].name;
if (an === "xmlns" || an === "xml:lang") continue;
if (an === "prefix") {
prefixAtr = ats[i].value;
continue;
}
str += " " + an + "=\"" + utils.xmlEscape(ats[i].value) + "\"";
}
str += ">\n";
Expand Down Expand Up @@ -121,14 +116,9 @@ define(
if (dt && dt.publicId) str += " PUBLIC '" + dt.publicId + "' '" + dt.systemId + "'";
else if (mode !== 5) {
if (conf.doRDFa) {
if (conf.doRDFa === "1.1") { // use the standard RDFa 1.1 doctype
str += " PUBLIC '-//W3C//DTD XHTML+RDFa 1.1//EN' 'http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd'";
}
else { // use the standard RDFa doctype
str += " PUBLIC '-//W3C//DTD XHTML+RDFa 1.0//EN' 'http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd'";
}
}
else {
// use the standard RDFa 1.1 doctype
str += " PUBLIC '-//W3C//DTD XHTML+RDFa 1.1//EN' 'http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd'";
} else {
str += " PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'";
}
}
Expand Down
5 changes: 2 additions & 3 deletions js/w3c/abstract.js
Expand Up @@ -13,13 +13,12 @@ define(
if ($abs.find("p").length === 0) $abs.contents().wrapAll($("<p></p>"));
$abs.prepend("<h2>Abstract</h2>");
$abs.addClass("introductory");
if (conf.doRDFa !== false) {
var rel = "dcterms:abstract"
if (conf.doRDFa) {
var rel = "dc:abstract"
, ref = $abs.attr("property");
if (ref) rel = ref + " " + rel;
$abs.attr({
"property": rel
, "datatype": ""
});
}
}
Expand Down
12 changes: 6 additions & 6 deletions js/w3c/aria.js
Expand Up @@ -23,20 +23,20 @@ define(
}
}
// mark issues and notes with heading
var noteNum = 0, issueNum = 0;
var noteCount = 0 ; var issueCount = 0 ;
$(".note-title, .issue-title", doc).each(function (i, item) {
var $item = $(item)
, isIssue = $item.hasClass("issue-title")
, level = $item.parents("section").length+2 ;

$item.attr('aria-level', level);
$item.attr('aria-level', level) ;
$item.attr('role', 'heading') ;
if (isIssue) {
issueNum++;
$item.attr('id', 'h_issue_'+issueNum);
issueCount++;
$item.makeID('h', "issue" + issueCount) ;
} else {
noteNum++;
$item.attr('id', 'h_note_'+noteNum);
noteCount++;
$item.makeID('h', "note" + noteCount) ;
}
});
msg.pub("end", "w3c/aria");
Expand Down
54 changes: 28 additions & 26 deletions js/w3c/headers.js
Expand Up @@ -97,29 +97,37 @@ define(
function (hb, utils, headersTmpl, sotdTmpl, cgbgHeadersTmpl, cgbgSotdTmpl) {
Handlebars.registerHelper("showPeople", function (name, items) {
// stuff to handle RDFa
var re = "", rp = "", rm = "", rn = "", rwu = "", rpu = "";
if (this.doRDFa !== false) {
var re = "", rp = "", rm = "", rn = "", rwu = "", rpu = "", bn = "";
if (this.doRDFa) {
if (name === "Editor") {
re = " rel='bibo:editor'";
if (this.doRDFa !== "1.0") re += " inlist=''";
bn = "_:editor0";
re = " property='bibo:editor' resource='" + bn + "'";
rp = " property='rdf:first' typeof='foaf:Person'";
}
else if (name === "Author") {
re = " rel='dcterms:contributor'";
rp = " property='dc:contributor' typeof='foaf:Person'";
}
rn = " property='foaf:name'";
rm = " rel='foaf:mbox'";
rp = " typeof='foaf:Person'";
rwu = " rel='foaf:workplaceHomepage'";
rpu = " rel='foaf:homepage'";
rm = " property='foaf:mbox'";
rwu = " property='foaf:workplaceHomepage'";
rpu = " property='foaf:homepage'";
}
var ret = "";
for (var i = 0, n = items.length; i < n; i++) {
var p = items[i];
if (this.doRDFa !== false ) ret += "<dd class='p-author h-card vcard' " + re +"><span" + rp + ">";
else ret += "<dd class='p-author h-card vcard'>";
if (this.doRDFa) {
ret += "<dd class='p-author h-card vcard' " + re + "><span" + rp + ">";
if (name === "Editor") {
// Update to next sequence in rdf:List
bn = (i < n - 1) ? ("_:editor" + (i + 1)) : "rdf:nil";
re = " resource='" + bn + "'";
}
} else {
ret += "<dd class='p-author h-card vcard'>";
}
if (p.url) {
if (this.doRDFa !== false ) {
ret += "<a class='u-url url p-name fn' " + rpu + rn + " content='" + p.name + "' href='" + p.url + "'>" + p.name + "</a>";
if (this.doRDFa) {
ret += "<meta" + rn + " content='" + p.name + "' /><a class='u-url url p-name fn' " + rpu + " href='" + p.url + "'>"+ p.name + "</a>";
}
else {
ret += "<a class='u-url url p-name fn' href='" + p.url + "'>"+ p.name + "</a>";
Expand All @@ -137,7 +145,10 @@ define(
ret += ", <span class='ed_mailto'><a class='u-email email' " + rm + " href='mailto:" + p.mailto + "'>" + p.mailto + "</a></span>";
}
if (p.note) ret += " (" + p.note + ")";
if (this.doRDFa !== false ) ret += "</span>\n";
if (this.doRDFa) {
ret += "</span>\n";
if (name === "Editor") ret += "<span property='rdf:rest' resource='" + bn + "'></span>\n";
}
ret += "</dd>\n";
}
return new Handlebars.SafeString(ret);
Expand Down Expand Up @@ -233,11 +244,8 @@ define(
, run: function (conf, doc, cb, msg) {
msg.pub("start", "w3c/headers");

if (conf.doRDFa !== false) {
if (conf.doRDFa === undefined) {
conf.doRDFa = '1.1';
}
}
// Default include RDFa document metadata
if (conf.doRDFa === undefined) conf.doRDFa = true;
// validate configuration and derive new configuration values
if (!conf.license) conf.license = "w3c";
// NOTE: this is currently only available to the HTML WG
Expand Down Expand Up @@ -378,15 +386,9 @@ define(
} else {
$("html").attr("typeof", "bibo:Document ") ;
}
$("html").attr("about", "") ;
$("html").attr("property", "dcterms:language") ;
$("html").attr("content", "en") ;
var prefixes = "bibo: http://purl.org/ontology/bibo/ w3p: http://www.w3.org/2001/02pd/rec54#";
if (conf.doRDFa != '1.1') {
$("html").attr("version", "XHTML+RDFa 1.0") ;
prefixes += " dcterms: http://purl.org/dc/terms/ foaf: http://xmlns.com/foaf/0.1/ xsd: http://www.w3.org/2001/XMLSchema#";
}
$("html").attr("prefix", prefixes);
$("html>head").prepend($("<meta lang='' property='dc:language' content='en' />"))
}
// insert into document and mark with microformat
$("body", doc).prepend($(conf.isCGBG ? cgbgHeadersTmpl(conf) : headersTmpl(conf)))
Expand Down
4 changes: 2 additions & 2 deletions js/w3c/templates/cgbg-headers.html
Expand Up @@ -2,11 +2,11 @@
<p>
<a href='http://www.w3.org/'><img width='72' height='48' src='https://www.w3.org/Icons/w3c_home' alt='W3C'/></a>
</p>
<h1 class='title p-name' id='title'{{#if doRDFa}} property='dcterms:title'{{/if}}>{{title}}</h1>
<h1 class='title p-name' id='title'{{#if doRDFa}} property='dc:title'{{/if}}>{{title}}</h1>
{{#if subtitle}}
<h2 {{#if doRDFa}}property='bibo:subtitle' {{/if}}id='subtitle'>{{subtitle}}</h2>
{{/if}}
<h2 {{#if doRDFa}}property="dcterms:issued" datatype="xsd:dateTime" content="{{publishISODate}}"{{/if}}>{{longStatus}} <time class='dt-published' datetime='{{dashDate}}'>{{publishHumanDate}}</time></h2>
<h2>{{longStatus}} <time {{#if doRDFa}}property="dc:issued"{{/if}}class='dt-published' datetime='{{dashDate}}'>{{publishHumanDate}}</time></h2>
<dl>
{{#if thisVersion}}
<dt>This version:</dt>
Expand Down
2 changes: 1 addition & 1 deletion js/w3c/templates/headers.html
Expand Up @@ -12,7 +12,7 @@ <h1 class='title p-name' id='title'{{#if doRDFa}} property='dcterms:title'{{/if}
{{#if subtitle}}
<h2 {{#if doRDFa}}property='bibo:subtitle' {{/if}}id='subtitle'>{{subtitle}}</h2>
{{/if}}
<h2 {{#if doRDFa}}property="dcterms:issued" datatype="xsd:dateTime" content="{{publishISODate}}"{{/if}}>{{#if prependW3C}}W3C {{/if}}{{textStatus}} <time class='dt-published' datetime='{{dashDate}}'>{{publishHumanDate}}</time></h2>
<h2>{{#if prependW3C}}W3C {{/if}}{{textStatus}} <time {{#if doRDFa}}property="dcterms:issued"{{/if}}class='dt-published' datetime='{{dashDate}}'>{{publishHumanDate}}</time></h2>
<dl>
{{#unless isNoTrack}}
<dt>This version:</dt>
Expand Down
2 changes: 1 addition & 1 deletion js/w3c/templates/sotd.html
Expand Up @@ -111,7 +111,7 @@
<p>
{{#unless isIGNote}}
This document was produced by a group operating under the
<a{{#if doRDFa}} id="sotd_patent" about='' rel='w3p:patentRules'{{/if}}
<a{{#if doRDFa}} id="sotd_patent" property='w3p:patentRules'{{/if}}
href='http://www.w3.org/Consortium/Patent-Policy-20040205/'>5 February 2004 W3C Patent
Policy</a>.
{{/unless}}
Expand Down
4 changes: 2 additions & 2 deletions tests/spec/core/fix-headers-spec.js
Expand Up @@ -18,8 +18,8 @@ describe("Core - Fix headers", function () {
expect($s.find("h1").length).toEqual(0);
expect($s.find("h2").length).toEqual(1);
expect($s.find("h2").text()).toMatch(/ONE/);
expect($s.find("h2").attr('resource')).toEqual('xhv:heading');
expect($s.find("h2").attr('property')).toEqual('xhv:role');
expect($s.find("h2 > span").attr('resource')).toEqual('xhv:heading');
expect($s.find("h2 > span").attr('property')).toEqual('xhv:role');
expect($s.find("h3").length).toEqual(1);
expect($s.find("h3").text()).toMatch(/TWO/);
expect($s.find("h4").length).toEqual(1);
Expand Down
1 change: 1 addition & 0 deletions tests/spec/core/issues-notes-spec.js
Expand Up @@ -77,6 +77,7 @@ describe("Core — Issues and Notes", function () {
, $i11 = $("#i11", doc).parent('div')
, $ixx = $("#ixx", doc).parent('div')
;
console.log($i10.innerHTML) ;

expect($i10.find("div.issue-title").length).toEqual(1);
expect($i10.find("div.issue-title").text()).toEqual("Issue 10");
Expand Down
4 changes: 2 additions & 2 deletions tests/spec/core/structure-spec.js
Expand Up @@ -23,8 +23,8 @@ describe("Core - Structure", function () {
var $toc = $("#toc", doc)
;
expect($toc.find("h2").text()).toEqual("Table of Contents");
expect($toc.find("h2").attr('resource')).toEqual('xhv:heading');
expect($toc.find("h2").attr('property')).toEqual('xhv:role');
expect($toc.find("h2 span").attr('resource')).toEqual('xhv:heading');
expect($toc.find("h2 span").attr('property')).toEqual('xhv:role');
expect($toc.find("ul:first").attr('role')).toEqual('directory');
expect($toc.find("> ul > li").length).toEqual(3);
expect($toc.find("li").length).toEqual(15);
Expand Down
4 changes: 2 additions & 2 deletions tests/spec/w3c/abstract-spec.js
Expand Up @@ -14,8 +14,8 @@ describe("W3C — Abstract", function () {
var $abs = $("#abstract", doc);
expect($abs.find("h2").length).toBeTruthy();
expect($abs.find("h2").text()).toEqual("Abstract");
expect($abs.find("h2").attr('resource')).toEqual('xhv:heading');
expect($abs.find("h2").attr('property')).toEqual('xhv:role');
expect($abs.find("h2 span").attr('resource')).toEqual('xhv:heading');
expect($abs.find("h2 span").attr('property')).toEqual('xhv:role');
expect($abs.hasClass("introductory")).toBeTruthy();
expect($abs.find("p").length).toBeTruthy();
flushIframes();
Expand Down

0 comments on commit 903b6b8

Please sign in to comment.