This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
forked from speced/respec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
requirements.js
59 lines (55 loc) · 1.98 KB
/
requirements.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// 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 + "'";
msg.pub("error", "Requirement not found in a.reqRef: " + id);
}
$ref.text(txt);
});
msg.pub("end", "core/requirements");
cb();
}
};
}
);