Skip to content
  • Sponsor Together-Java/ModernJava

  • Notifications You must be signed in to change notification settings
  • Fork 27

Commit 23fc7a5

Browse files
s-hassaninLeonardoA77
andauthoredNov 19, 2023
Add runnable code (#28)
* modified: out.json modified: src/SUMMARY.md * yep * buttons * Yes * Fix * Works * Remove play button works * no_run works * ferris added as button not as a pic * release 21 --------- Co-authored-by: LeonardoA77 <Lemniscate4356@Knights.ucf.edu>
1 parent f28b2ed commit 23fc7a5

12 files changed

+384
-34
lines changed
 

‎book.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ multilingual = false
99
git-repository-url = "https://github.com/Together-Java/ModernJava"
1010
edit-url-template = "https://github.com/Together-Java/ModernJava/edit/develop/{path}"
1111
mathjax-support = true
12+
additional-css = ["ferris.css"]
13+
additional-js = ["ferris.js"]
1214

1315
[output.html.fold]
1416
enable = true # whether or not to enable section folding
@@ -25,4 +27,5 @@ simple_io = false
2527
java_21 = false
2628

2729
[output.html.playground]
28-
editable = true
30+
editable = true
31+

‎ferris.css

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
body.light .does_not_compile,
2+
body.light .panics,
3+
body.light .not_desired_behavior,
4+
body.rust .does_not_compile,
5+
body.rust .panics,
6+
body.rust .not_desired_behavior {
7+
background: #fff1f1;
8+
}
9+
10+
body.coal .does_not_compile,
11+
body.coal .panics,
12+
body.coal .not_desired_behavior,
13+
body.navy .does_not_compile,
14+
body.navy .panics,
15+
body.navy .not_desired_behavior,
16+
body.ayu .does_not_compile,
17+
body.ayu .panics,
18+
body.ayu .not_desired_behavior {
19+
background: #501f21;
20+
}
21+
22+
.ferris-container {
23+
position: absolute;
24+
z-index: 99;
25+
right: 5px;
26+
top: 30px;
27+
}
28+
29+
.ferris {
30+
vertical-align: top;
31+
margin-left: 0.2em;
32+
height: auto;
33+
}
34+
35+
.ferris-large {
36+
width: 4.5em;
37+
}
38+
39+
.ferris-small {
40+
width: 2.3em;
41+
}
42+
43+
.ferris-explain {
44+
width: 100px;
45+
}

‎ferris.js

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
var ferrisTypes = [
2+
{
3+
attr: 'does_not_compile',
4+
title: 'This code does not compile!'
5+
},
6+
{
7+
attr: 'panics',
8+
title: 'This code panics!'
9+
},
10+
{
11+
attr: 'not_desired_behavior',
12+
title: 'This code does not produce the desired behavior.'
13+
}
14+
]
15+
16+
document.addEventListener('DOMContentLoaded', () => {
17+
for (var ferrisType of ferrisTypes) {
18+
attachFerrises(ferrisType)
19+
}
20+
})
21+
22+
function attachFerrises(type) {
23+
var elements = document.getElementsByClassName(type.attr)
24+
25+
for (var codeBlock of elements) {
26+
var lines = codeBlock.innerText.replace(/\n$/, '').split(/\n/).length
27+
var size = 'large'
28+
if (lines < 4) {
29+
size = 'small'
30+
}
31+
32+
var container = prepareFerrisContainer(codeBlock, size == 'small')
33+
container.appendChild(createFerris(type, size))
34+
}
35+
}
36+
37+
function prepareFerrisContainer(element, useButtons) {
38+
var foundButtons = element.parentElement.querySelector('.buttons')
39+
if (useButtons && foundButtons) {
40+
return foundButtons
41+
}
42+
43+
var div = document.createElement('div')
44+
div.classList.add('ferris-container')
45+
46+
element.parentElement.insertBefore(div, element)
47+
48+
return div
49+
}
50+
51+
function createFerris(type, size) {
52+
var a = document.createElement('a')
53+
a.setAttribute('href', 'ch00-00-introduction.html#ferris')
54+
a.setAttribute('target', '_blank')
55+
56+
var img = document.createElement('img')
57+
img.setAttribute('src', '../img/' + type.attr + '.svg')
58+
img.setAttribute('title', type.title)
59+
img.classList.add('ferris')
60+
img.classList.add('ferris-' + size)
61+
62+
a.appendChild(img)
63+
64+
return a
65+
}
66+

‎out.json

+1-1
Large diffs are not rendered by default.

‎src/SUMMARY.md

-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@
186186
# User Input
187187

188188
- [User Input](./user_input.md)
189-
- [readLine](./user_input/readLine.md)
190189

191190
# Data Types III
192191

‎src/first_steps/comments.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ words.
88

99
~IF toplevel_anonymous_class
1010

11-
```java
11+
```java, no_run
1212
void main() {
1313
// This prints hello world!
1414
System.out.println("Hello, World!");
@@ -17,7 +17,7 @@ void main() {
1717

1818
~ELSE
1919

20-
```java
20+
```java, no_run
2121
public class Main {
2222
public static void main(String[] args) {
2323
// This prints hello world!

‎src/first_steps/formatting.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ You may have noticed that after each `{` all the code that comes after it is "in
55
~IF toplevel_anonymous_class
66

77
```java
8-
void main() {
9-
System.out.println("Hello, World!");
8+
public class Main {
9+
public static void main(String[] args) {
10+
System.out.println("Hello, World!");
11+
}
1012
}
1113
```
1214

‎src/getting_started.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,18 @@ edit the following code.
1616

1717
~IF toplevel_anonymous_class
1818

19-
```java
19+
<span id="ferris"></span>
20+
21+
| Ferris | Meaning |
22+
|------------------------------------------------------------------------------------------------------------------|--------------------------------------------------|
23+
| <img src="img/does_not_compile.svg" class="ferris-explain" alt="Ferris with a question mark"/> | This code does not compile! |
24+
| <img src="img/panics.svg" class="ferris-explain" alt="Ferris throwing up their hands"/> | This code panics! |
25+
| <img src="img/not_desired_behavior.svg" class="ferris-explain" alt="Ferris with one claw up, shrugging"/> | This code does not produce the desired behavior. |
26+
27+
In most situations, we’ll lead you to the correct version of any code that
28+
doesn’t compile.
29+
30+
```java,panics
2031
void main() {
2132
System.out.println("Hello, World");
2233
}

‎src/img/does_not_compile.svg

+72
Loading

‎src/img/not_desired_behavior.svg

+75
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.