Skip to content

Commit

Permalink
Added syntax highlighting markers to the code blocks in the README.
Browse files Browse the repository at this point in the history
  • Loading branch information
josephg committed Aug 18, 2011
1 parent 66ca01a commit 19d9f35
Showing 1 changed file with 54 additions and 44 deletions.
98 changes: 54 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ If you want redis support, you'll need to install redis:

Install some dependancies

Mac:
* Mac:

# sudo brew install redis
# sudo brew install redis

Linux:
* Linux:

# sudo apt-get install redis
# sudo apt-get install redis

Then:

Expand Down Expand Up @@ -65,37 +65,39 @@ There are two ways to run a sharejs server:

1. Embedded in a node.js server app:

var connect = require('connect'),
sharejs = require('share').server;
```javascript
var connect = require('connect'),
sharejs = require('share').server;

var server = connect(
connect.logger(),
connect.static(__dirname + '/my_html_files')
);
var server = connect(
connect.logger(),
connect.static(__dirname + '/my_html_files')
);

var options = {db: {type: 'memory'}}; // See docs for options. {type: 'redis'} to enable persistance.
var options = {db: {type: 'memory'}}; // See docs for options. {type: 'redis'} to enable persistance.

// Attach the sharejs REST and Socket.io interfaces to the server
sharejs.attach(server, options);
// Attach the sharejs REST and Socket.io interfaces to the server
sharejs.attach(server, options);

server.listen(8000);
console.log('Server running at http://127.0.0.1:8000/');
The above script will start up a ShareJS server on port 8000 which hosts static content from the `my_html_files` directory. See [bin/exampleserver](https://github.com/josephg/ShareJS/blob/master/bin/exampleserver) for a more complex configuration example.
server.listen(8000);
console.log('Server running at http://127.0.0.1:8000/');
```
The above script will start up a ShareJS server on port 8000 which hosts static content from the `my_html_files` directory. See [bin/exampleserver](https://github.com/josephg/ShareJS/blob/master/bin/exampleserver) for a more complex configuration example.

> See the [Connect](http://senchalabs.github.com/connect/) or [Express](http://expressjs.com/) documentation for more complex routing.
> See the [Connect](http://senchalabs.github.com/connect/) or [Express](http://expressjs.com/) documentation for more complex routing.

2. From the command line:

# sharejs
Configuration is pulled from a configuration file that can't be easily edited at the moment. For now, I recommend method #1 above.
Configuration is pulled from a configuration file that can't be easily edited at the moment. For now, I recommend method #1 above.
3. If you are just mucking around, run:
# sharejs-exampleserver
This will run a simple server on port 8000, and host all the example code there. Run it and check out http://localhost:8000/ . The example server stores everything in ram, so don't get too attached to your data.
This will run a simple server on port 8000, and host all the example code there. Run it and check out http://localhost:8000/ . The example server stores everything in ram, so don't get too attached to your data.

> If you're running sharejs from source, you can launch the example server by running `bin/exampleserver`.
> If you're running sharejs from source, you can launch the example server by running `bin/exampleserver`.
Putting Share.js on your website
Expand All @@ -105,7 +107,9 @@ If you want to get a simple editor working in your webpage with sharejs, here's

First, get an ace editor on your page:

<div id="editor"></div>
```html
<div id="editor"></div>
```

Your web app will need access to the following JS files:

Expand All @@ -115,20 +119,24 @@ Your web app will need access to the following JS files:

Add these script tags:

<script src="http://ajaxorg.github.com/ace/build/src/ace.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script src="/share/share.js"></script>
<script src="/share/ace.js"></script>
```html
<script src="http://ajaxorg.github.com/ace/build/src/ace.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script src="/share/share.js"></script>
<script src="/share/ace.js"></script>
```

And add this code:

<script>
var editor = ace.edit("editor");
```html
<script>
var editor = ace.edit("editor");
sharejs.open('hello', 'text', {host: 'localhost', port: 8000}, function(doc, error) {
doc.attach_ace(editor);
});
</script>
sharejs.open('hello', 'text', {host: 'localhost', port: 8000}, function(doc, error) {
doc.attach_ace(editor);
});
</script>
```

Thats about it :)

Expand All @@ -147,24 +155,26 @@ Here's an example application which opens a document and inserts some text in it

Run this from a couple terminal windows when sharejs is running to see it go.

var client = require('share').client;
```javascript
var client = require('share').client;
// Open the 'hello' document, which should have type 'text':
client.open('hello', 'text', {host: 'localhost', port: 8000}, function(doc, error) {
// Insert some text at the start of the document (position 0):
doc.insert("Hi there!\n", 0);
// Open the 'hello' document, which should have type 'text':
client.open('hello', 'text', {host: 'localhost', port: 8000}, function(doc, error) {
// Insert some text at the start of the document (position 0):
doc.insert("Hi there!\n", 0);
// Get the contents of the document for some reason:
console.log(doc.snapshot);
// Get the contents of the document for some reason:
console.log(doc.snapshot);
doc.on('change', function(op) {
console.log('Version: ' + doc.version);
});

// Close the doc if you want your node app to exit cleanly
// doc.close();
doc.on('change', function(op) {
console.log('Version: ' + doc.version);
});
// Close the doc if you want your node app to exit cleanly
// doc.close();
});
```

See [`the wiki`](https://github.com/josephg/ShareJS/wiki) for API documentation, and `examples/node*` for some more example apps.


0 comments on commit 19d9f35

Please sign in to comment.