Skip to content

Commit 8946988

Browse files
committed
Add syntax highlighting
Closes #62
1 parent 22fd29b commit 8946988

File tree

15 files changed

+124
-54
lines changed

15 files changed

+124
-54
lines changed

Diff for: Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
source 'https://rubygems.org'
22

33
gem 'jekyll', '1.4.3'
4+
gem 'rouge', '1.3.2'

Diff for: Gemfile.lock

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ GEM
3939
rb-kqueue (0.2.0)
4040
ffi (>= 0.5.0)
4141
redcarpet (2.3.0)
42+
rouge (1.3.2)
4243
safe_yaml (0.9.7)
4344
toml (0.1.0)
4445
parslet (~> 1.5.0)
@@ -49,3 +50,4 @@ PLATFORMS
4950

5051
DEPENDENCIES
5152
jekyll (= 1.4.3)
53+
rouge (= 1.3.2)

Diff for: content/lessons/_config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
highlighter: rouge

Diff for: content/lessons/_layouts/default.html

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
<!DOCTYPE html>
22
<head>
3-
<style>
4-
#chunk-game {
5-
background-color: black;
6-
display: block;
7-
margin-left: auto;
8-
margin-right: auto;
9-
}
10-
</style>
3+
<link rel="stylesheet" type="text/css" href="/css/syntax.css" />
114
</head>
125
<body>
136
<h1>{{ page.title }}</h1>
7+
148
{{ content }}
159

1610
<div id="footer">

Diff for: content/lessons/css/syntax.css

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#chunk-game {
2+
background-color: black;
3+
display: block;
4+
margin-left: auto;
5+
margin-right: auto;
6+
}
7+
8+
/***********************/
9+
/* SYNTAX HIGHLIGHTING */
10+
/***********************/
11+
12+
.lineno { background: #AFAFAF; }
13+
.highlight { background: #ffffff; }
14+
.highlight .c { color: #999988; font-style: italic } /* Comment */
15+
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
16+
.highlight .k { font-weight: bold } /* Keyword */
17+
.highlight .o { font-weight: bold } /* Operator */
18+
.highlight .cm { color: #999988; font-style: italic } /* Comment.Multiline */
19+
.highlight .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
20+
.highlight .c1 { color: #999988; font-style: italic } /* Comment.Single */
21+
.highlight .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
22+
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
23+
.highlight .gd .x { color: #000000; background-color: #ffaaaa } /* Generic.Deleted.Specific */
24+
.highlight .ge { font-style: italic } /* Generic.Emph */
25+
.highlight .gr { color: #aa0000 } /* Generic.Error */
26+
.highlight .gh { color: #999999 } /* Generic.Heading */
27+
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
28+
.highlight .gi .x { color: #000000; background-color: #aaffaa } /* Generic.Inserted.Specific */
29+
.highlight .go { color: #888888 } /* Generic.Output */
30+
.highlight .gp { color: #555555 } /* Generic.Prompt */
31+
.highlight .gs { font-weight: bold } /* Generic.Strong */
32+
.highlight .gu { color: #aaaaaa } /* Generic.Subheading */
33+
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
34+
.highlight .kc { font-weight: bold } /* Keyword.Constant */
35+
.highlight .kd { font-weight: bold } /* Keyword.Declaration */
36+
.highlight .kp { font-weight: bold } /* Keyword.Pseudo */
37+
.highlight .kr { font-weight: bold } /* Keyword.Reserved */
38+
.highlight .kt { color: #445588; font-weight: bold } /* Keyword.Type */
39+
.highlight .m { color: #009999 } /* Literal.Number */
40+
.highlight .s { color: #d14 } /* Literal.String */
41+
.highlight .na { color: #008080 } /* Name.Attribute */
42+
.highlight .nb { color: #0086B3 } /* Name.Builtin */
43+
.highlight .nc { color: #445588; font-weight: bold } /* Name.Class */
44+
.highlight .no { color: #008080 } /* Name.Constant */
45+
.highlight .ni { color: #800080 } /* Name.Entity */
46+
.highlight .ne { color: #990000; font-weight: bold } /* Name.Exception */
47+
.highlight .nf { color: #990000; font-weight: bold } /* Name.Function */
48+
.highlight .nn { color: #555555 } /* Name.Namespace */
49+
.highlight .nt { color: #000080 } /* Name.Tag */
50+
.highlight .nv { color: #008080 } /* Name.Variable */
51+
.highlight .ow { font-weight: bold } /* Operator.Word */
52+
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
53+
.highlight .mf { color: #009999 } /* Literal.Number.Float */
54+
.highlight .mh { color: #009999 } /* Literal.Number.Hex */
55+
.highlight .mi { color: #009999 } /* Literal.Number.Integer */
56+
.highlight .mo { color: #009999 } /* Literal.Number.Oct */
57+
.highlight .sb { color: #d14 } /* Literal.String.Backtick */
58+
.highlight .sc { color: #d14 } /* Literal.String.Char */
59+
.highlight .sd { color: #d14 } /* Literal.String.Doc */
60+
.highlight .s2 { color: #d14 } /* Literal.String.Double */
61+
.highlight .se { color: #d14 } /* Literal.String.Escape */
62+
.highlight .sh { color: #d14 } /* Literal.String.Heredoc */
63+
.highlight .si { color: #d14 } /* Literal.String.Interpol */
64+
.highlight .sx { color: #d14 } /* Literal.String.Other */
65+
.highlight .sr { color: #009926 } /* Literal.String.Regex */
66+
.highlight .s1 { color: #d14 } /* Literal.String.Single */
67+
.highlight .ss { color: #990073 } /* Literal.String.Symbol */
68+
.highlight .bp { color: #999999 } /* Name.Builtin.Pseudo */
69+
.highlight .vc { color: #008080 } /* Name.Variable.Class */
70+
.highlight .vg { color: #008080 } /* Name.Variable.Global */
71+
.highlight .vi { color: #008080 } /* Name.Variable.Instance */
72+
.highlight .il { color: #009999 } /* Literal.Number.Integer.Long */
73+

Diff for: content/lessons/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ <h3>Launch your programming environment</h3>
2929
<li>Open game/snake.js in your text editor</li>
3030
<li>Open game/index.html in your browser</li>
3131
<li>Open your browsers javascript console</li>
32-
<li>type <pre>alert("hello world");</pre> in your browsers javascript console
33-
and dismiss the window that pops up<br />
32+
<li>type `alert("hello world");` in your browsers javascript console and
33+
dismiss the window that pops up<br />
3434
<img src='images/helloworld.png'
3535
height="300" width="600"></li>
3636
</ul>

Diff for: content/lessons/lesson-10/index.html

+10-11
Original file line numberDiff line numberDiff line change
@@ -11,53 +11,53 @@
1111
segment index and a snake and returns the segment closer to the head. Let's
1212
start with:</p>
1313

14-
<pre>
14+
{% highlight js %}
1515
var segmentFurtherForwardThan = function(index, snake) {
1616
return snake[index - 1]
1717
}
18-
</pre>
18+
{% endhighlight %}
1919

2020
While this <em>seems</em> OK, in reality it has a nefarious bug! Open your console and type:
2121

22-
<pre>
22+
{% highlight js %}
2323
segmentFurtherForwardThan(1, snake);
24-
</pre>
24+
{% endhighlight %}
2525

2626
<p>This returns a segment object, which looks great! But what happens if we try
2727
a index of 0?</p>
2828

29-
<pre>
29+
{% highlight js %}
3030
segmentFurtherForwardThan(0, snake);
31-
</pre>
31+
{% endhighlight %}
3232

3333
<p>Instead of a segment, we get `undefined`! This means we can't get a
3434
direction! Let's use an `if` statement to return the segment at the index if
3535
there isn't a segment further forward. Change `segmentFurtherForwardThan` to:
3636
</p>
3737

38-
<pre>
38+
{% highlight js %}
3939
var segmentFurtherForwardThan = function(index, snake) {
4040
if (snake[index - 1] === undefined) {
4141
return snake[index];
4242
} else {
4343
return snake[index - 1];
4444
}
4545
}
46-
</pre>
46+
{% endhighlight %}
4747

4848
<p>Now when you run `segmentFurtherForwardThan(0, snake)` it will return the
4949
snakes head instead of undefined. Excellent! Now we get to change moveSnake to
5050
use `segmentFurtherForwardThan` when it assigns the segments direction. Change `moveSnake` to:</p>
5151

52-
<pre>
52+
{% highlight js %}
5353
var moveSnake = function(snake) {
5454
return snake.map(function(oldSegment, segmentIndex) {
5555
var newSegment = moveSegment(oldSegment);
5656
newSegment.direction = segmentFurtherForwardThan(segmentIndex, snake).direction;
5757
return newSegment;
5858
});
5959
}
60-
</pre>
60+
{% endhighlight %}
6161

6262
<p>Great! Now each segment will follow the segment ahead of it!</p>
6363

@@ -70,4 +70,3 @@ <h3>Syntax Breakdown</h3>
7070
<h3>Play Time!</h3>
7171

7272
<h3><a href="../lesson-11">Move on to Lesson 11</a></h3>
73-

Diff for: content/lessons/lesson-11/index.html

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
---
66
<p>Let's make it so an apple appears on the screen!</p>
77

8-
<pre>
8+
{% highlight js %}
99
var draw = function(snakeToDraw, apple) {
1010
var drawableSnake = { color: "green", pixels: snakeToDraw };
1111
var drawableApple = { color: "red", pixels: [apple] };
1212
var drawableObjects = [drawableSnake, drawableApple];
1313
CHUNK.draw(drawableObjects);
1414
}
15-
</pre>
15+
{% endhighlight %}
1616

1717
<p>We renamed the `drawSnake` function and let it take multiple arguments so it
1818
can draw an apple.</p>
1919

2020
<p>Next, let's make sure we pass the `apple` to the `draw` function, when we call it!</p>
2121

22-
<pre>
22+
{% highlight js %}
2323
var advanceGame = function() {
2424
snake = moveSnake(snake);
2525
if (CHUNK.detectCollisionBetween(snake, CHUNK.gameBoundaries())) {
@@ -28,13 +28,13 @@
2828
}
2929
draw(snake, apple);
3030
}
31-
</pre>
31+
{% endhighlight %}
3232

3333
<p>Finally, let's create an apple to be drawn!</p>
3434

35-
<pre>
35+
{% highlight js %}
3636
var apple = { top: 8, left: 10 };
37-
</pre>
37+
{% endhighlight %}
3838

3939
{% include expected-results.html %}
4040

Diff for: content/lessons/lesson-12/index.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@
1111
the snake moves next the copied segment will stay in place, causing it to
1212
"grow" on the screen.</p>
1313

14-
<pre>
14+
{% highlight js %}
1515
var growSnake = function(snake) {
1616
var indexOfLastSegment = snake.length - 1;
1717
var lastSegment = snake[snake.length - 1];
1818
snake.push({ top: lastSegment.top, left: lastSegment.left });
1919
return snake;
2020
}
21-
</pre>
21+
{% endhighlight %}
2222

2323
<p>Now that we have a function to grow the snake, let's check for a collision
2424
between the apple and the snake whenever the game advances. Let's change the
2525
`advanceGame` function so it looks like this:</p>
2626

27-
<pre>
27+
{% highlight js %}
2828
var advanceGame = function() {
2929
snake = moveSnake(snake);
3030
if (CHUNK.detectCollisionBetween([apple], snake)) {
@@ -37,7 +37,7 @@
3737
}
3838
draw(snake, apple);
3939
}
40-
</pre>
40+
{% endhighlight %}
4141

4242
{% include expected-results.html %}
4343

Diff for: content/lessons/lesson-13/index.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
---
66
<p>The last thing we need to do is check to see if the snake ran into itself.</p>
77

8-
<pre>
8+
{% highlight js %}
99
var ate = function(snake, otherThing) {
1010
var head = snake[0];
1111
return CHUNK.detectCollisionBetween([head], otherThing);
1212
}
13-
</pre>
13+
{% endhighlight %}
1414

1515
<p>We've created an `ate` function that accepts a snake and the previous version of the snake. We can also think about passing the `ate` function other things, which we'll get into in a bit. In `ate` we also reuse the `detectCollisionBetween` to find out if there's a collision.</p>
1616

1717
<p>Now we just have to check if the `newSnake` ate it's previous self to see if there was a collision! We do this by calling the `ate` function inside of `advanceGame`.</p>
1818

19-
<pre>
19+
{% highlight js %}
2020
var advanceGame = function() {
2121
var newSnake = moveSnake(snake);
2222

@@ -38,7 +38,7 @@
3838
snake = newSnake;
3939
draw(snake, apple);
4040
}
41-
</pre>
41+
{% endhighlight %}
4242

4343
<p>Notice, we've abstracted out the `ate` function by resuing it. It can now determine if the snake ate itself, an apple or the wall.</p>
4444

Diff for: content/lessons/lesson-4/index.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@
1818
<p>By making these assumptions it keeps the code clear and makes it easy to
1919
take small steps. Add the following code to your snake.js file: </p>
2020

21-
<pre>
21+
{% highlight js %}
2222
var moveSnake = function(snake) {
2323
var oldSegment = snake[0];
2424
var newSegment = { top: oldSegment.top + 1, left: oldSegment.left };
2525
var newSnake = [newSegment];
2626
return newSnake;
2727
}
28-
</pre>
28+
{% endhighlight %}
2929

3030
<p>Once we have this `moveSnake` function, we can call it and it will give us a
3131
snake whose segment's location has changed. We can then call `drawSnake` with
3232
that snake and see it move across the screen!</p>
3333

3434
<p>Type the following lines into your javascript console a few times:</p>
3535

36-
<pre>
36+
{% highlight js %}
3737
snake = moveSnake(snake);
3838
drawSnake(snake);
39-
</pre>
39+
{% endhighlight %}
4040

4141
<h3>How the computer is interpreting this code:</h3>
4242

Diff for: content/lessons/lesson-5/index.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010

1111
<p>We'll start with an `advanceGame` function</p>
1212

13-
<pre>
13+
{% highlight js %}
1414
var advanceGame = function() {
1515
snake = moveSnake(snake);
1616
drawSnake(snake);
1717
}
18-
</pre>
18+
{% endhighlight %}
1919

2020
<p>To get this function running we'll use our CHUNK game engine to CALL the `executeNTimesPerSecond` function. It does exactly that, to do this `executeNTimesPerSecond` takes in two arguments. The first arugement advances the game, and the second tells it how many times to move per-second.</p>
2121

22-
<pre>
22+
{% highlight js %}
2323
CHUNK.executeNTimesPerSecond(advanceGame, 1);
24-
</pre>
24+
{% endhighlight %}
2525

2626
<p>Bam! Now the snake moves down until it runs off the game screen.</p>
2727

Diff for: content/lessons/lesson-6/index.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<p>First, we'll create a function that moves the segment based upon it's
1111
direction (down, up, right, left):</p>
1212

13-
<pre>
13+
{% highlight js %}
1414
var moveSegment = function(segment) {
1515
if (segment.direction === "down") {
1616
return { top: segment.top + 1, left: segment.left }
@@ -23,7 +23,7 @@
2323
}
2424
return segment;
2525
}
26-
</pre>
26+
{% endhighlight %}
2727

2828
<p>The `if` statement allows us to make choices about what code to execute
2929
based upon values. Here we use a series of `if` and `else if`s to create a
@@ -35,15 +35,15 @@
3535
Otherwise the snake will just stop moving! This means we'll updating our
3636
`moveSnake` function.</p>
3737

38-
<pre>
38+
{% highlight js %}
3939
var moveSnake = function(snake) {
4040
var oldSegment = snake[0];
4141
var newSegment = moveSegment(oldSegment);
4242
newSegment.direction = oldSegment.direction;
4343
var newSnake = [newSegment];
4444
return newSnake;
4545
}
46-
</pre>
46+
{% endhighlight %}
4747

4848
<p>Now it's time to add a direction to the starting snake's segments so it knows where to go.</p>
4949

0 commit comments

Comments
 (0)