-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First commit. See README. You probably don't want to use this (yet).
- Loading branch information
0 parents
commit 1a460c2
Showing
8 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_Store | ||
node_modules | ||
lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |