diff options
| author | Michael Williamson <mike@zwobble.org> | 2014-03-23 11:27:56 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2014-03-23 11:27:56 +0000 |
| commit | 7ab5b76b10e79377bcacff158b533513643179f3 (patch) | |
| tree | 0420de033c25cce0de43a91023002ac965d06974 | |
| parent | d0dc2dd324ff2ff5c31d676fe733eaf176af7fb7 (diff) | |
Remove web server
| -rw-r--r-- | README.md | 16 | ||||
| -rw-r--r-- | lib/web.js | 98 | ||||
| -rw-r--r-- | package.json | 1 |
3 files changed, 8 insertions, 107 deletions
@@ -13,20 +13,20 @@ There's a large mismatch between the structure used by .docx and the structure o meaning that the conversion is unlikely to be perfect for more complicated documents. Mammoth works best if you only use styles to semantically mark up your document. +### Web demo + +The easiest way to try out mammoth is to use the web demo: + +* Clone this repository +* Run `make setup` +* Open `browser-demo/index.html` in a web browser + ## Installation npm install mammoth ## Usage -### Web interface - -The easiest way to try out mammoth is to use the demo web server. -You can start it up by running `node lib/web.js` from the project directory. - -Browserify can be used to run Mammoth in the browser. -To see an example, run `make setup` and open `browser-demo/index.html` in a web browser. - ### CLI You can convert docx files by passing the path to the docx file and the output file. diff --git a/lib/web.js b/lib/web.js deleted file mode 100644 index 9a5ada2..0000000 --- a/lib/web.js +++ /dev/null @@ -1,98 +0,0 @@ -var http = require("http"); -var connect = require("connect"); -var url = require("url"); -var fs = require("fs"); -var q = require("q"); -var dust = require("dustjs-linkedin"); - -var mammoth = require("./"); - - -dust.onLoad = function(templateName, callback) { - fs.readFile("templates/" + templateName, "utf-8", callback) -}; - - -function startServer(options) { - var app = connect() - .use(connect.bodyParser()) - .use("/static/", connect.static(__dirname + '/../static')) - .use(handlePage) - .use(renderTemplate); - http.createServer(app).listen(options.port); -} - - -var handlers = { - "/": handleIndex, - "/convert": handleConvert -}; - -function handlePage(request, response, next) { - var pathname = url.parse(request.url).pathname; - var handler = handlers[pathname]; - if (handler) { - handler(request, response, next); - } else { - next(); - } -} - -function handleIndex(request, response, next) { - if (url.parse(request.url).pathname !== "/") { - return next(); - } - request.template = { - name: "index.html" - }; - next(); -} - -function handleConvert(request, response, next) { - if (url.parse(request.url).pathname !== "/convert") { - return next(); - } - - var uploadedDocument = request.files.document; - var documentPath = uploadedDocument.path; - - mammoth.convertToHtml({path: documentPath}) - .then(function(result) { - request.template = { - name: "convert.html", - values: { - documentName: uploadedDocument.name, - documentHtml: result.value, - messages: result.messages - } - }; - next(); - }) - .fin(function() { - return q.nfcall(fs.unlink, documentPath); - }) - .done(); -} - -function renderTemplate(request, response, next) { - if (!request.template) { - return next(); - } - var templateName = request.template.name; - - q.nfcall(dust.render, templateName, request.template.values) - .then(function(content) { - response.writeHead(200, { - "content-type": "text/html; charset=utf-8" - }); - response.end(content); - }) - .fail(next); -} - -if (require.main === module) { - var argv = require("optimist").argv; - var port = argv.port ? parseInt(argv.port, 10) : 3000; - startServer({port: port}); - console.log("Server running on http://localhost:" + port); -} diff --git a/package.json b/package.json index 976ff87..7454afb 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,6 @@ "lop": "~0.2.8", "unzip": "~0.1.7", "connect": "~2.7.3", - "dustjs-linkedin": "~1.2.1", "async": "~0.2.6", "buffers": "~0.1.1", "stream-buffers": "~0.2.4", |
