Skip to content

Commit

Permalink
First commit. See README. You probably don't want to use this (yet).
Browse files Browse the repository at this point in the history
  • Loading branch information
debrouwere committed May 15, 2011
0 parents commit 1a460c2
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
node_modules
lib
4 changes: 4 additions & 0 deletions Cakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exec = require('child_process').exec

task 'build', 'build the application', ->
exec 'coffee -co lib src'
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (C) 2011 by Stijn Debrouwere

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
49 changes: 49 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Draughtsman is an MIT-licensed tool for front-end developers who want a cutting-edge
stack while prototyping (like Jade, Stylus and CoffeeScript for you node.js aficionados),
but can't be bothered to run all sorts of command-line tools and who don't want to
set up an entire project structure simply to test out a few layouts in their favorite
CSS alternative.

In addition to parsing .styl, .coffee and .jade files, Draughtsman will also search for
an eponymous .yml, .txt or .json file and use whatever it finds there to feed dummy data
to your template.

This application is solely intended to facilitate front-end prototyping. Once you or your
team moves on from sketching, forget about Draughtsman and use a proper dev environment.

# Installation

Draughtsman can work as a web server or as a reverse proxy. To use Draughtsman as a rudimentary
web server (bypassing e.g. Apache entirely), simply start up the app by opening up a terminal and
execute `draughtsman /my/basepath`. Surf to http://0.0.0.0:3400/ for a directory listing and take
it from there.

To use Draughtsman as a reverse proxy, you'll need to configure your main web server. For Apache,
a configuration like this should work:

<VirtualHost *:*>
<Location />
Order allow,deny
allow from all
ProxyPassMatch ^(/.*\.)(jade|styl|coffee)$ http://localhost:3400$1
ProxyPassReverse http://localhost:8888
</Location>
</VirtualHost>

It should be part of your `httpd.conf`.

For NGINX, try something like this:

server {
listen 80;
...

location ~ \.(jade|styl|coffee)$ {
proxy_pass http://127.0.0.1:3400;
proxy_redirect default;
}
}

For additional convenience, you may want to deamonize the application and run it after
login or startup just like your web server. Use whatever method or tool you prefer;
upstart is a good bet if you're on Ubuntu.
7 changes: 7 additions & 0 deletions bin/draughtsman
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env node

var path = require('path');
var fs = require('fs');
var lib = path.join(path.dirname(fs.realpathSync(__filename)), '../lib');

require(lib + '/command').run();
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "draughtsman",
"author": "Stijn Debrouwere",
"description": "Easy transparent compilation of templates and stylesheets for prototyping HTML interfaces.",
"version": "0.1",
"main": "./lib/app.js",
"dependencies": {
"coffee-script": "latest",
"config": "latest",
"express": "latest",
"jade": "latest",
"stylus": "latest"
}
}
73 changes: 73 additions & 0 deletions src/app.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
express = require 'express'
fs = require 'fs'
path = require 'path'
_ = require 'underscore'
jade = require 'jade'
coffee = require 'coffee-script'
stylus = require 'stylus'
#yaml = require 'yaml'

# App

app = module.exports = express.createServer()

ROOT = process.argv[2]

parse =
txt: (str) ->
json: (str) ->
yaml: (str) ->

find_template_variables = (template) ->
match = /^(.*\.)[a-z]{2,6}$/.exec template
base = match[1]
related_files = [
base + 'txt'
base + 'yml'
base + 'json'
]

variables = related_files
.map (file) ->
file = ROOT + file
if path.existsSync file
str = fs.readFileSync file, 'utf-8'
return JSON.parse str
else
return {}
.reduce (a, b) ->
_.extend a, b

return variables

app.get /^(.*\.coffee)$/, (req, res) ->
file = req.params[0]
if path.existsSync ROOT + file
res.contentType 'application/javascript'
script = fs.readFileSync ROOT + file, 'utf-8'
res.send coffee.compile script
else
res.send 404

app.get /^(.*\.styl)$/, (req, res) ->
file = req.params[0]
if path.existsSync ROOT + file
style = fs.readFileSync ROOT + file, 'utf-8'
stylus(style).render (err, css) ->
if err
res.send err
else
res.contentType 'text/css'
res.send css
else
res.send 404

app.get /^(.*\.jade)$/, (req, res) ->
file = req.params[0]
res.contentType 'text/html'
vars = find_template_variables file
jade.renderFile ROOT + file, {locals: vars}, (err, html) ->
if err
res.send err
else
res.send html
7 changes: 7 additions & 0 deletions src/command.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fs = require 'fs'
draughtsman = require './app'

# TODO: convert ./ and ../ based on CWD

exports.run = ->
draughtsman.listen 3400

0 comments on commit 1a460c2

Please sign in to comment.