summaryrefslogtreecommitdiffstats
path: root/src/doc/book/2018-edition/ferris.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/doc/book/2018-edition/ferris.js
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/doc/book/2018-edition/ferris.js')
-rw-r--r--src/doc/book/2018-edition/ferris.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/doc/book/2018-edition/ferris.js b/src/doc/book/2018-edition/ferris.js
new file mode 100644
index 000000000..5e79b3c71
--- /dev/null
+++ b/src/doc/book/2018-edition/ferris.js
@@ -0,0 +1,51 @@
+var ferrisTypes = [
+ {
+ attr: 'does_not_compile',
+ title: 'This code does not compile!'
+ },
+ {
+ attr: 'panics',
+ title: 'This code panics!'
+ },
+ {
+ attr: 'unsafe',
+ title: 'This code block contains unsafe code.'
+ },
+ {
+ attr: 'not_desired_behavior',
+ title: 'This code does not produce the desired behavior.'
+ }
+]
+
+document.addEventListener('DOMContentLoaded', () => {
+ for (var ferrisType of ferrisTypes) {
+ attachFerrises(ferrisType)
+ }
+})
+
+function attachFerrises (type) {
+ var elements = document.getElementsByClassName(type.attr)
+
+ for (var codeBlock of elements) {
+ var lines = codeBlock.textContent.split(/\r|\r\n|\n/).length - 1;
+
+ if (lines >= 4) {
+ attachFerris(codeBlock, type)
+ }
+ }
+}
+
+function attachFerris (element, type) {
+ var a = document.createElement('a')
+ a.setAttribute('href', 'ch00-00-introduction.html#ferris')
+ a.setAttribute('target', '_blank')
+
+ var img = document.createElement('img')
+ img.setAttribute('src', 'img/ferris/' + type.attr + '.svg')
+ img.setAttribute('title', type.title)
+ img.className = 'ferris'
+
+ a.appendChild(img)
+
+ element.parentElement.insertBefore(a, element)
+}