Skip to content

Commit

Permalink
Merge pull request #88 from tobie/req
Browse files Browse the repository at this point in the history
Add a core/requirements module.
  • Loading branch information
darobin committed Oct 17, 2012
2 parents 6b3f312 + 939841f commit 7cc8574
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
57 changes: 57 additions & 0 deletions js/core/requirements.js
@@ -0,0 +1,57 @@
// Module core/requirements
// This module does two things:
//
// 1. It finds and marks all requirements. These are elements with class "req".
// When a requirement is found, it is reported using the "req" event. This
// can be used by a containing shell to extract them.
// Requirements are automatically numbered.
//
// 2. It allows referencing requirements by their ID simply using an empty <a>
// element with its href pointing to the requirement it should be referencing
// and a class of "reqRef".

define(
[],
function () {
return {
run: function (conf, doc, cb, msg) {
msg.pub("start", "core/requirements");

$("*.req").each(function (i) {
i++;
var $req = $(this)
, title = "Req. " + i
;
msg.pub("req", {
type: "req",
number: i,
content: $req.html(),
title: title
});
$req.prepend("<a href='#" + $req.attr("id") + "'>" + title + "</a>: ");
});

$("a.reqRef").each(function () {
var $ref = $(this)
, href = $ref.attr("href")
, id
, $req
, txt
;
if (!href) return;
id = href.substring(1);
$req = $("#" + id);
if ($req.length) {
txt = $req.find("> a").text();
} else {
txt = "Req. not found '" + id + "'";
}
$ref.text(txt);
});

msg.pub("end", "core/requirements");
cb();
}
};
}
);
1 change: 1 addition & 0 deletions js/profile-w3c-common.js
Expand Up @@ -15,6 +15,7 @@ define([
, "core/dfn"
, "core/examples"
, "core/issues-notes"
, "core/requirements"
, "core/highlight"
, "core/best-practices"
, "core/figures"
Expand Down

0 comments on commit 7cc8574

Please sign in to comment.