Skip to content

Commit 321119e

Browse files
committed
Adding repl
1 parent 9f86f93 commit 321119e

3 files changed

Lines changed: 130 additions & 12 deletions

File tree

_includes/default.njk

Lines changed: 88 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,34 @@ title: OpenJS NodeJS Application Developer Study Guide
1313
<link rel="stylesheet" href="{{ "/css/main.css" | url }}">
1414
<link rel="stylesheet"
1515
href="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.16.2/build/styles/default.min.css">
16-
<script src="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.16.2/build/highlight.min.js"></script>
17-
<script>hljs.initHighlightingOnLoad();</script>
16+
<script src="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.16.2/build/highlight.min.js"></script>
17+
<script>
18+
hljs.initHighlightingOnLoad();
19+
</script>
1820
<script src="{{ "/js/main.js" | url }}"></script>
1921
</head>
2022
<body>
2123
<header class="container">
22-
<div class="row">
23-
<div class="column column-50">
24-
<h1 class="logo"><a href="/">ONAD Study Guide</a></h1>
25-
</div>
26-
<div class="top-links column column-50">
27-
<ul>
28-
<li><a href="https://training.linuxfoundation.org/certification/jsnad/" target="_blank" title="OpenJS Node.js Application Developer (JSNAD)">JSNAD Certification</a></li>
29-
</ul>
30-
</div>
24+
<div class="row">
25+
<div class="column column-50">
26+
<h1 class="logo">
27+
<a href="/">ONAD Study Guide</a>
28+
</h1>
29+
</div>
30+
<div class="top-links column column-50">
31+
<ul>
32+
<li>
33+
<a href="https://training.linuxfoundation.org/certification/jsnad/" target="_blank" title="OpenJS Node.js Application Developer (JSNAD)">JSNAD Certification</a>
34+
</li>
35+
</ul>
3136
</div>
37+
</div>
3238
</header>
3339
<main class="container">
3440
<div class="row">
3541
<div class="sidebar column">
3642
<nav>
43+
<<<<<<< HEAD
3744
<ul class="topics">
3845
{% for topic in topics %}
3946
<li data-topic="{{topic.url}}">
@@ -58,4 +65,73 @@ title: OpenJS NodeJS Application Developer Study Guide
5865

5966
</footer>
6067
</body>
61-
</html>
68+
</html>
69+
=======
70+
<ul>
71+
<li>
72+
<a href="#" {% if page.url === '/buffer/' %} class="current" {% endif %}>Buffer and Streams</a>
73+
</li>
74+
<li>
75+
<a href="#">Control flow</a>
76+
</li>
77+
<li>
78+
<a href="#">Child Processes</a>
79+
</li>
80+
<li>
81+
<a href="#">Diagnostics</li>
82+
<li>
83+
<a href="#">Error Handling</a>
84+
</li>
85+
<li>
86+
<a href="#">Node.js CLI</a>
87+
</li>
88+
<li>
89+
<a href="{{ "/events" | url }}" {% if page.url === '/events/' %} class="current" {% endif %}>Events</li>
90+
<li>
91+
<a href="#">File System</a>
92+
</li>
93+
<li>
94+
<a href="#">JavaScript Prerequisites</a>
95+
</li>
96+
<li>
97+
<a href="#">Module system</a>
98+
</li>
99+
<li>
100+
<a href="#">Process/Operating System</a>
101+
</li>
102+
<li>
103+
<a href="#">Package.json</a>
104+
</li>
105+
<li>
106+
<a href="#">Unit Testing</a>
107+
</li>
108+
</ul>
109+
</nav>
110+
<nav class="secondary">
111+
<ul>
112+
<li>
113+
<a href="{{ "/repl/" | url }}" {% if page.url === '/repl/' %} class="current" {% endif %}>Node.js REPL</a>
114+
</li>
115+
</ul>
116+
</nav>
117+
</div>
118+
<div class="main-content column column-75">
119+
<h1>{{ title }}</h1>
120+
121+
{{ content | safe }}
122+
</div>
123+
</div>
124+
</main>
125+
<footer class="container">
126+
<div class="row">
127+
<div class="column column-75 column-offset-25">
128+
<p>
129+
<a href="https://github.com/Node-Study-Guide/openjs-nodejs-application-developer-study-guide/tree/master/{{ page.inputPath }}">Edit this page on GitHub</a>
130+
</p>
131+
</div>
132+
</div>
133+
134+
</footer>
135+
</body>
136+
</html>
137+
>>>>>>> Adding repl

events/index.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ When the EventEmitter object emits an event, all of the functions attached to th
1414

1515
This example creates an event listener for `foo` events, and an event emitter to fire these events.
1616

17+
<div class="repl-code">
18+
1719
```javascript
1820
const { EventEmitter } = require("events");
1921

@@ -33,6 +35,23 @@ eventEmitter.on("foo", foo);
3335
eventEmitter.emit("foo");
3436
```
3537

38+
</div>
39+
40+
<script>
41+
// TODO - move to main.js when other PRs merged
42+
const replCode = document.querySelectorAll('.repl-code');
43+
[...replCode].forEach(code => {
44+
const codeText = encodeURI(code.innerText);
45+
const link = document.createElement('a');
46+
link.title = "Run this code in the REPL";
47+
link.innerText = "Run this code in the REPL";
48+
link.href = "/repl/?code=" + codeText;
49+
const paragraph = document.createElement('p');
50+
paragraph.appendChild(link);
51+
code.appendChild(paragraph);
52+
});
53+
</script>
54+
3655
## Passing parameters
3756

3857
When an event is emitted using the `emit` method, the subsequent arguments are passed through to the listeners.

repl/index.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
layout: default.njk
3+
title: Node.js REPL
4+
---
5+
6+
Use this space to try out code from the examples!
7+
8+
<script src="https://embed.runkit.com"></script>
9+
10+
<div id="repl"></div>
11+
12+
<script>
13+
14+
const urlParams = new URLSearchParams(window.location.search);
15+
const code = urlParams.get('code');
16+
17+
const notebook = RunKit.createNotebook({
18+
element: document.getElementById("repl"),
19+
source: code || "// Your JavaScript code goes here",
20+
minHeight: "500px",
21+
});
22+
23+
</script>

0 commit comments

Comments
 (0)