Skip to content

Commit

Permalink
code hilight
Browse files Browse the repository at this point in the history
  • Loading branch information
hacksparrow committed Feb 14, 2015
1 parent b39f34a commit 9bb4cbe
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 44 deletions.
1 change: 0 additions & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@

# Build settings
markdown: kramdown
highlighter: rouge
11 changes: 10 additions & 1 deletion css/prism.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,16 @@ pre[class*="language-"] {

:not(pre) > code[class*="language-"],
pre[class*="language-"] {
background: #fff;
background: #F7F7F7;
}

pre.language-sh {
background-color: #272727;
}

code.language-sh {
color: #4fbf40;
text-shadow: none;
}

/* Inline code */
Expand Down
2 changes: 0 additions & 2 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,6 @@ pre {
color: #666;
font-size: 14px;
line-height: 1.4;
background: white;
border: 1px solid #eee;
padding: 16px;
border-radius: 3px;
overflow: scroll;
Expand Down
8 changes: 4 additions & 4 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ $(function(){

// code highlight

$('code.lang-js, pre.js code').each(function(){
$(this).addClass('language-javascript').removeClass('lang-js')
$('code.language-js').each(function(){
$(this).addClass('language-javascript').removeClass('language-js')
})

$('code.lang-sh').each(function(){
$(this).addClass('language-bash').removeClass('lang-sh')
$('code.language-sh').each(function(){
$(this).parent().addClass('language-sh')
})

Prism.highlightAll()
Expand Down
4 changes: 2 additions & 2 deletions starter/basic-routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This tutorial assumes that an instance of `express` named `app` is created and t

The following code illustrates some example routes in an app.

```
~~~js
// respond with "Hello World!" on the homepage
app.get('/', function (req, res) {
res.send('Hello World!');
Expand All @@ -36,6 +36,6 @@ app.put('/user', function (req, res) {
app.delete('/user', function (req, res) {
res.send('Got a DELETE request at /user');
})
```
~~~

For more details about routing, refer the [routing guide](/guide/routing.html).
16 changes: 8 additions & 8 deletions starter/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ within your application. With the following middleware setup, and a request
for `GET /javascripts/jquery.js`, the first check would be `./public/javascripts/jquery.js`;
if it does not exist, then the subsequent middleware will check `./files/javascripts/jquery.js`.

```js
~~~js
app.use(express.static('public'));
app.use(express.static('files'));
```
~~~

## How can I prefix a pathname for serving static files?

Expand All @@ -64,9 +64,9 @@ part of the path. Suppose you wanted `GET /files/javascripts/jquery.js`.
You could mount the middleware at `/files`, exposing `/javascripts/jquery.js`
as the `req.url`, allowing the middleware to serve the file:

```js
~~~js
app.use('/public', express.static('public'));
```
~~~

## How do you handle 404s?

Expand All @@ -78,24 +78,24 @@ and found that none of them responded. All you need to
do is add a middleware at the very bottom (below all others)
to handle a 404:

```js
~~~js
app.use(function(req, res, next){
res.send(404, 'Sorry cant find that!');
});
```
~~~

## How do you setup an error handler?

You define error-handling middleware the same way as other middleware,
except with four arguments instead of three; specifically with the signature `(err, req, res, next)`:


```js
~~~js
app.use(function(err, req, res, next){
console.error(err.stack);
res.send(500, 'Something broke!');
});
```
~~~

For more information, see [Error handling](/guide/error-handling.html).

Expand Down
31 changes: 17 additions & 14 deletions starter/generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ Use the application generator tool, `express`, to quickly create a application s

Install it with the following command.

```sh
~~~sh
$ npm install express-generator -g
```
~~~

Display the command options with the `-h` option:

```sh
~~~sh
$ express -h

Usage: express [options] [dir]
Expand All @@ -28,11 +28,11 @@ $ express -h
-H, --hogan add hogan.js engine support
-c, --css <engine> add stylesheet <engine> support (less|stylus|compass) (defaults to plain css)
-f, --force force on non-empty directory
```
~~~

For example, the following creates an Express app named _myapp_ in the current working directory.

```sh
~~~sh
$ express myapp

create : myapp
Expand All @@ -52,29 +52,32 @@ $ express myapp
create : myapp/views/error.jade
create : myapp/bin
create : myapp/bin/www
```
~~~

Then install dependencies:
```

~~~sh
$ cd myapp
$ npm install
```
~~~

Run the app (on MacOS or Linux):
```

~~~sh
$ DEBUG=myapp ./bin/www
```
~~~

On Windows, use this command:

```sh
~~~sh
> set DEBUG=myapp & node .\bin\www
```
~~~

Then load `http://localhost:3000/` in your browser to access the app.

The generated app directory structure looks like the following.

```sh
~~~sh
.
├── app.js
├── bin
Expand All @@ -94,7 +97,7 @@ The generated app directory structure looks like the following.
└── layout.jade

7 directories, 9 files
```
~~~

<div class="doc-box doc-info">
The app structure generated by the generator is just one of the multiple ways of structuring Express apps. Feel free to not use it or to modify it to best suit your needs.
Expand Down
8 changes: 4 additions & 4 deletions starter/hello-world.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ layout: page

Here is an example of a very basic Express app.

{% highlight js %}
~~~js
var express = require('express')
var app = express()

Expand All @@ -22,7 +22,7 @@ var server = app.listen(3000, function () {
console.log('Example app listening at http://%s:%s', host, port)

})
{% endhighlight %}
~~~

<div class="doc-box doc-notice">
The `req` (request) and `res` (response) are the exact same objects that Node provides, so you can invoke
Expand All @@ -33,8 +33,8 @@ The app starts a server and listens on port 3000 for connection. It will respond

Save the code in a file named `app.js` and run it with the following command.

```
~~~ sh
$ node app.js
```
~~~

Then, load [http://localhost:3000/](http://localhost:3000/) in a browser to see the output.
16 changes: 8 additions & 8 deletions starter/installing.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@ layout: page

First, create a directory to hold your application, if you haven't already done so, and make that your working directory.

{% highlight bash %}
~~~sh
$ mkdir myapp
$ cd myapp
{% endhighlight %}
~~~

Create a `package.json` file in the directory of interest, if it does not exist already, with the `npm init` command.

{% highlight bash %}
~~~sh
$ npm init
{% endhighlight %}
~~~

Install Express in the app directory and save it in the dependencies list:

{% highlight bash %}
~~~sh
$ npm install express --save
{% endhighlight %}
~~~

To install Express temporarily, and not add it to the dependencies list, omit the `--save` option:

{% highlight bash %}
~~~sh
$ npm install express
{% endhighlight %}
~~~

<div class="doc-box doc-info">
Node modules installed with the `--save` option are added to the `dependencies` list in the `package.json` file.
Expand Down

0 comments on commit 9bb4cbe

Please sign in to comment.