Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:temsa/wheat

Conflicts:
	README.markdown
  • Loading branch information...
commit dd5da4e3a934dbe545f681efbc1ed8f38ce94cf1 2 parents e4782fe + 2774aca
@temsa authored
Showing with 46 additions and 22 deletions.
  1. +13 −8 README.markdown
  2. +30 −10 lib/wheat/data.js
  3. +3 −4 lib/wheat/tools.js
View
21 README.markdown
@@ -8,12 +8,11 @@ Wheat engine takes a local git repository path as a parameter
// wheat is now a function which handles request and return response:
// wheat(req/*request*/, res/*response*/, next /*next handler to call for this request*/)
-Here's an example using Connect ( npm install connect ) to start a server, adapted from https://github.com/creationix/howtonode.org/blob/master/app.js :
+Here's an example using Connect ( npm install connect ) to start a server, adapted from [howtonode.org repo app.js](https://github.com/creationix/howtonode.org/blob/master/app.js) :
var Connect = require('connect');
- var repository = "/path/to/my/repo",
- port = 3000;
+ var repository = "/path/to/my/repo";
Connect.createServer(
Connect.logger(),
@@ -22,7 +21,7 @@ Here's an example using Connect ( npm install connect ) to start a server, adapt
Connect.cache(),
Connect.gzip(),
require('wheat')(repository)
- ).listen(port);
+ ).listen(3000);
## How to Install
@@ -30,12 +29,18 @@ Either manually install all the dependencies or use npm.
npm install wheat
-## Full example of how to use wheat :
+For on the fly rendering of Graphviz graphs (DOT files), Graphviz will need to be [installed](http://www.graphviz.org/Download..php)
+
+
+## Full example of how to use wheat, using howtonode.org [repository](http://github.com/creationix/howtonode.org) for skin/articles/... :
$> npm install wheat
$> git clone https://github.com/creationix/howtonode.org.git
$> cd howtonode.org
- $> node app.js
+
+Then edit app.js and add ".listen(3000);" at the end of "Connect.createServer", see above.
-That's it! Checkout the wheat branch of howtonode.org for an example of how to use the library.
+Now just run it, and open your browser on [your host, port 3000](http://127.0.0.1:3000)
+
+ $> node app.js
-<http://github.com/creationix/howtonode.org>
+That's it!
View
40 lib/wheat/data.js
@@ -1,7 +1,7 @@
var Git = require('git-fs'),
Path = require('path'),
Step = require('step'),
- sys = require('sys'),
+ util = require(process.binding('natives').util ? 'util' : 'sys'),
Script = process.binding('evals').Script,
QueryString = require('querystring');
@@ -59,33 +59,53 @@ function preProcessMarkdown(markdown) {
function sandbox(snippet) {
snippet.result = "";
snippet.output = "";
- var fakeRequire = function fakeRequire(path) {
+ function fakeRequire(path) {
var lib = require(path);
return lib;
- };
+ }
+ // Create a 'pseudo-write-stream', to act as the virtual 'stdout' stream.
+ var stdout = new (require('stream').Stream)();
+ stdout.writable = true;
+ stdout.write = function(buf, enc) {
+ if (!this.writable) throw new Error("Stream is not writable");
+ if (!Buffer.isBuffer(buf)) {
+ buf = new Buffer(buf, enc);
+ }
+ this.emit('data', buf);
+ }
+ stdout.end = function(buf, enc) {
+ if (buf) { this.write(buf, enc); }
+ this.writable = false;
+ }
+ stdout.on('data', function(data) {
+ snippet.output += data.toString();
+ });
+
var env = {
clear: function () { snippet.output = ""; },
require: fakeRequire,
process: {
exit: function fakeExit() {},
- argv: ['node', snippet.filename]
+ argv: [process.argv[0], snippet.filename],
+ stdout: stdout
},
console: {
- log: function fakePuts() {
+ log: function fakeLog() {
arguments.forEach(function (data) {
- snippet.output += data + "\n";
+ stdout.write(data + "\n");
});
},
- dir: function fakeP(data) {
+ dir: function fakeDir() {
arguments.forEach(function (data) {
- snippet.output += sys.inspect(data) + "\n";
+ snippet.output += util.inspect(data) + "\n";
});
}
- } };
+ }
+ };
env.process.__proto__ = process;
var toRun = (snippet.beforeCode ? (snippet.beforeCode + "\nclear();\n") : "") + snippet.code;
- console.log(toRun);
+ //console.log(toRun);
try {
snippet.lastExpression = Script.runInNewContext(toRun, env, snippet.filename);
View
7 lib/wheat/tools.js
@@ -1,5 +1,4 @@
-var Sys = require('sys'),
- Step = require('step'),
+var Step = require('step'),
Haml = require('haml'),
Markdown = require('./markdown'),
MD5 = require('./md5'),
@@ -37,7 +36,7 @@ var aMonths = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun",
var aDays = new Array( "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
var Helpers = {
- inspect: Sys.inspect,
+ inspect: require(process.binding('natives').util ? 'util' : 'sys').inspect,
intro: function intro(markdown) {
var html = Markdown.encode(markdown);
return html.substr(0, html.indexOf("<h2"));
@@ -118,7 +117,7 @@ var Helpers = {
// Convert UTF8 strings to binary buffers for faster loading
function stringToBuffer(string) {
var buffer = new Buffer(Buffer.byteLength(string));
- buffer.utf8Write(string);
+ buffer.write(string, 'utf8');
return buffer;
};
Please sign in to comment.
Something went wrong with that request. Please try again.