Permalink
Browse files

release 0.0.1

  • Loading branch information...
0 parents commit 9db31c5cdc7b0c906ac0c9f3fa2a4c83aa867d17 @aheckmann committed Aug 30, 2012
Showing with 235 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +7 −0 History.md
  3. +5 −0 Makefile
  4. +39 −0 README.md
  5. +69 −0 bin/greadme
  6. +27 −0 package.json
  7. +86 −0 test/Readme.md
  8. 0 test/index.js
@@ -0,0 +1,2 @@
+*.sw*
+node_modules/
@@ -0,0 +1,7 @@
+
+0.0.1 / 2012-08-30
+==================
+
+ * initial release
+
+
@@ -0,0 +1,5 @@
+
+test:
+ @./node_modules/.bin/mocha --reporter list $(TESTFLAGS)
+
+.PHONY: test
@@ -0,0 +1,39 @@
+#greadme
+===========
+
+Locally preview your README.md with github-like styling applied.
+
+## Installation
+
+via npm:
+
+ $ npm install -g greadme
+
+## Usage
+
+ $ cd to/dir/with/readme.markdown
+ $ greadme
+
+ view your readme at http://localhost:8124/
+ press CTRL+C to quit
+
+Execute the `greadme` command from a directory holding your README and it will be parsed and served from a locally running http server.
+
+If you are running on a mac, a brower will automatically be opened to the readme preview.
+
+The following filenames and extensions are tried, if none are found, an error is printed and the program exits.
+
+ - README.md
+ - README.markdown
+ - Readme.md
+ - Readme.markdown
+ - readme.md
+ - readme.markdown
+
+## Notes
+
+This just hardlinks to githubs css so the styling may not last forever. If its out of date send a pull request or open an issue.
+
+## License
+
+[MIT](https://github.com/aheckmann/aheckmann/blob/master/LICENSE)
@@ -0,0 +1,69 @@
+#!/usr/bin/env node
+
+// readme.md
+
+var fs = require('fs')
+var md = require('marked')
+var http = require('http')
+
+// TODO configurable
+var host = 'localhost'
+var port = 8124
+
+var dir = process.cwd()
+var exts = 'markdown md'.split(' ')
+var names = 'README Readme readme'.split(' ')
+
+var file = ''
+names.some(function (name) {
+ return exts.some(function (ext) {
+ try {
+ var filename = dir + '/' + name + '.' + ext
+ var stat = fs.statSync(filename)
+ file = filename
+ return true
+ } catch (err) {
+ return false
+ }
+ })
+})
+
+if (!file) {
+ console.error('no readme.md found')
+ return process.exit(1)
+}
+
+var contents = fs.readFileSync(file, 'utf8')
+var html = md(contents)
+
+html = '<link href="https://a248.e.akamai.net/assets.github.com/assets/github-78df541aa7e7c0d038536bb979d896805331f6ee.css" rel="stylesheet">'
+ + '<link href="https://a248.e.akamai.net/assets.github.com/assets/github2-a2d333a1fd790f13b3c38ae51111c0acdbca7b65.css" rel="stylesheet">'
+ + '<div id="readme"><article class="markdown-body entry-content">'
+ + html
+ + '</article></div>'
+
+if (!/<body/i.test(html)) {
+ html = '<body>' + html + '</body>'
+}
+if (!/<html/i.test(html)) {
+ html = '<html>' + html + '</html>'
+}
+
+var server = http.createServer(function (req, res) {
+ res.writeHead(200, { 'Content-Type': 'text/html' })
+ res.end(html)
+}).listen(port, host)
+
+server.on('listening', function () {
+ var url = 'http://' + host + ':' + port
+ console.log("\n view your readme at \u001B[32m%s/\u001B[0m", url)
+ console.log(' press CTRL+C to quit')
+
+ // open in browser on mac
+ if ('darwin' != process.platform) return
+
+ require('child_process').exec('open ' + url, function (err) {
+ // ignore errors
+ })
+});
+
@@ -0,0 +1,27 @@
+{
+ "name": "greadme",
+ "version": "0.0.1",
+ "description": "locally preview your README.md github style",
+ "bin": { "greadme": "./bin/greadme" },
+ "scripts": {
+ "test": "make test"
+ },
+ "keywords": [
+ "readme",
+ "markdown",
+ "github",
+ "git",
+ "md",
+ "server",
+ "preview"
+ ],
+ "dependencies": {
+ "marked": "0.2.5"
+ },
+ "devDependencies": {
+ "mocha": "1.4.1"
+ },
+ "author": "Aaron Heckmann <aaron.heckmann+github@gmail.com>",
+ "license": "MIT",
+ "repository": { "type": "git", "url": "git://github.com/aheckmann/greadme.git" }
+}
@@ -0,0 +1,86 @@
+# gridfs-stream
+
+Easily stream files to and from MongoDB [GridFS](http://www.mongodb.org/display/DOCS/GridFS).
+
+```js
+var mongo = require('mongodb');
+var Grid = require('gridfs-stream')(mongo);
+var gfs = Grid(db);
+
+// streaming to gridfs
+var writestream = gfs.createWriteStream('filename');
+fs.createReadStream('/some/path').pipe(writestream);
+
+// streaming from gridfs
+var readstream = gfs.createReadStream('filename');
+readstream.pipe(response);
+```
+
+Created streams are compatible with other Node streams so piping anywhere is easy.
+
+## install
+
+```
+npm install gridfs-stream
+```
+
+## use
+
+```js
+var mongo = require('mongodb');
+var Grid = require('gridfs-stream')(mongo);
+
+// create or use an existing mongodb-native db instance.
+// for this example we'll just create one:
+var db = new mongo.Db('yourDatabaseName', new Server("127.0.0.1", 27017));
+
+// make sure the db instance is open before passing into `Grid`
+db.open(function (err) {
+ if (err) return handleError(err);
+ var gfs = Grid(db);
+
+ // all set!
+})
+```
+
+The `gridfs-stream` module exports a function that accepts the [mongodb-native](https://github.com/mongodb/node-mongodb-native/) driver you are using.
+
+Executing this function, (_`Grid` in the example above_), returns a constructor that accepts a [mongodb-native](https://github.com/mongodb/node-mongodb-native/) db. The db must already be opened before calling `createWriteStream` or `createReadStream`.
+
+Now we're ready to start streaming.
+
+## createWriteStream
+
+To stream data to GridFS we call `createWriteStream` passing a filename and any options.
+
+```js
+var writestream = gfs.createWriteStream('filename' [, options]);
+fs.createReadStream('/some/path').pipe(writestream);
+```
+
+## createReadStream
+
+To stream data out of GridFS we call `createReadStream` passing a filename and any options.
+
+```js
+var readstream = gfs.createReadStream('filename' [, options]);
+readstream.pipe(response);
+```
+
+Any options are passed to the internally created [GridStore](http://mongodb.github.com/node-mongodb-native/api-generated/gridstore.html).
+
+## using with mongoose
+
+```js
+var mongoose = require('mongoose');
+var Grid = require('gridfs-stream')(mongoose.mongo);
+
+var conn = mongoose.createConnection(..);
+conn.once('open', function () {
+ var gfs = Grid(conn.db);
+
+ // all set!
+})
+```
+
+[LICENSE](https://github.com/aheckmann/gridfs-stream/blob/master/LICENSE)
No changes.

0 comments on commit 9db31c5

Please sign in to comment.