Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a core/requirements module. #88

Merged
merged 1 commit into from Oct 17, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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