Skip to content

Commit

Permalink
Merge pull request #225 from w3c/denis/same-day-publication
Browse files Browse the repository at this point in the history
Same day publication
  • Loading branch information
tripu committed Aug 7, 2015
2 parents 306733d + 09524be commit 3a4cd34
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/l10n-en_GB.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ exports.messages = {
, "headers.dl.cant-retrieve": "Could not retrieve URI for previous version or for latest version."
, "headers.dl.latest-is-not-previous": "Retrieved \"previous\" and \"latest\" documents, but their contents don't match."
, "headers.dl.same-this-and-previous": "\"This\" version and \"previous\" version have the same URL."
, "headers.dl.same-day-publication": "The document was already published today."
// headers/errata
, "headers.errata.not-found": "Errata paragraph not found."
// headers/translations
Expand Down
1 change: 1 addition & 0 deletions lib/l10n-es_ES.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ exports.messages = {
, "headers.dl.cant-retrieve": "Could not retrieve URI for previous version or for latest version."
, "headers.dl.latest-is-not-previous": "Retrieved \"previous\" and \"latest\" documents, but their contents don't match."
, "headers.dl.same-this-and-previous": "\"This\" version and \"previous\" version have the same URL."
, "headers.dl.same-day-publication": "The document was already published today."
// headers/errata
, "headers.errata.not-found": "Errata paragraph not found."
// headers/translations
Expand Down
24 changes: 19 additions & 5 deletions lib/rules/headers/dl.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ exports.check = function (sr, done) {
, rescinds = sr.config.rescinds
, subType = sr.config.submissionType
, topLevel = "TR"
, dts = {}
, thisURI = ''
, previousURI = ''
, latestURI = ''
Expand All @@ -49,7 +48,9 @@ exports.check = function (sr, done) {
if (subType === "member") topLevel = "Submission";
else if (subType === "team") topLevel = "TeamSubmission";

$dl.find("dt").each(function (idx) {
var extractHeaders = function (dl) {
var dts = {};
dl.find("dt").each(function (idx) {
var $dt = sr.$(this)
, txt = sr.norm($dt.text())
.replace(":", "")
Expand All @@ -65,9 +66,11 @@ exports.check = function (sr, done) {
else if (/^rescinds this recommendation?$/.test(txt)) key = "Rescinds";
if (EDITORS_DRAFT.test(txt) && $dd.find('a')) sr.metadata('editorsDraft', $dd.find('a').attr('href'));
if (key) dts[key] = { pos: idx, el: $dt, dd: $dd };
});

});
return dts;
};

var dts = extractHeaders($dl);
if (!dts.This) err("this-version");
if (!dts.Latest) err("latest-version");
if (prevRequired && !dts.Previous) err("previous-version");
Expand Down Expand Up @@ -169,7 +172,18 @@ exports.check = function (sr, done) {
err('cant-retrieve');
}
else if (bodies[0] !== bodies[1]) {
err('latest-is-not-previous');
// check same day publication
var $ = require("whacko").load(bodies[1])
, $latestDl = $("body div.head dl").first()
, latestDts = extractHeaders($latestDl);
if (latestDts.This &&
latestDts.This.dd.find("a").first().attr("href") === thisURI &&
latestDts.Previous &&
latestDts.Previous.dd.find("a").first().attr("href") === previousURI) {
sr.warning(exports.name, 'same-day-publication');
} else {
err('latest-is-not-previous');
}
}
done();
}, function() {
Expand Down

0 comments on commit 3a4cd34

Please sign in to comment.