Added script to add node_modules/.bin path to PATH; updated Makefile to build correctly.

This commit is contained in:
Elf M. Sternberg 2013-06-07 16:11:43 -07:00
parent fac48b727a
commit d10767f0d0
4 changed files with 73 additions and 15 deletions

View File

@ -1,21 +1,39 @@
.PHONY: lib test .PHONY: lib test library docs
lib_sources:= $(wildcard src/*.coffee) COFFEE= ./node_modules/.bin/coffee
lib_objects:= $(subst src/, lib/, $(lib_sources:%.coffee=%.js)) PEGJS= ./node_modules/.bin/pegjs
DOCCO= ./node_modules/.bin/docco
MOCHA= ./node_modules/.bin/mocha
cof_sources:= $(wildcard src/*.coffee)
cof_objects:= $(subst src/, lib/, $(cof_sources:%.coffee=%.js))
peg_sources:= $(wildcard src/*.peg)
peg_objects:= $(subst src/, lib/, $(peg_sources:%.peg=%.js))
library: $(cof_objects) $(peg_objects)
default: build default: build
build: $(lib_objects) lib/tokenizer.js build: $(lib_objects)
lib: lib:
mkdir -p lib mkdir -p lib
lib/tumble.js: lib src/tumble.peg $(cof_objects): $(cof_sources)
./node_modules/.bin/pegjs src/tumble.peg lib/tumble.js
$(lib_objects): $(lib_sources)
@mkdir -p $(@D) @mkdir -p $(@D)
coffee -o $(@D) -c $< $(COFFEE) -o $(@D) -c $<
$(peg_objects): $(peg_sources)
@mkdir -p $(@D)
$(PEGJS) $< $@
docs:
$(DOCCO) $(cof_sources)
echo:
echo $(cof_sources)
echo $(cof_objects)
test: test/[0-9]*_mocha.coffee lib/tumble.js lib/parser.js test: test/[0-9]*_mocha.coffee lib/tumble.js lib/parser.js
./node_modules/.bin/mocha -R tap -C --compilers coffee:coffee-script -u tdd $< ./node_modules/.bin/mocha -R tap -C --compilers coffee:coffee-script -u tdd $<

8
bin/activate Normal file
View File

@ -0,0 +1,8 @@
#!/bin/bash
# /bin comes before /node_modules/.bin because sometimes I want to
# override the behaviors provided.
PROJECT_ROOT=`pwd`
PATH="$PROJECT_ROOT/bin:$PROJECT_ROOT/node_modules/.bin:$PATH"
export PATH

16
bin/devserver Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env coffee
staticserver = require('node-static')
files = new(staticserver.Server)('./dist')
require('http').createServer((request, response) ->
request.addListener 'end', ->
files.serve request, response, (err, res) ->
if (err)
console.error("> Error serving " + request.url + " - " + err.message)
response.writeHead(err.status, err.headers)
response.end()
else
console.log("> " + request.url + " - " + res.message)
).listen(8081)
console.log("> node-static is listening on http://127.0.0.1:8081")

View File

@ -9,42 +9,58 @@ class Contexter
@depth = 0 @depth = 0
has_any: (name) -> has_any: (name) ->
_.find this.stack, (o) -> _.has(o, name) # Scan the parse stack from more recent to most distant,
# return the reference that contains this name.
_.find @stack, (o) -> _.has(o, name)
has_any_one: (name) -> has_any_one: (name) ->
# Returns the most recent key seen on this stack, if any.
p = @has_any(name) p = @has_any(name)
if p then p[name] else null if p then p[name] else null
has: (name) -> has: (name) ->
# Returns references ONLY from the most recent context.
if @stack[0][name]? then @stack[0][name] else null if @stack[0][name]? then @stack[0][name] else null
get: (name, alt = '') -> get: (name, alt = '') ->
# Scalars only
p = @has_any_one(name) p = @has_any_one(name)
if p and (_.isString(p) or _.isNumber(p)) then p else alt return p if p and (_.isString(p) or _.isNumber(p))
return @render(p)
once: (obj, cb) -> once: (obj, cb) ->
# Create a new context, execute the block associated with that
# context, pop the context, and return the production.
@stack.unshift obj @stack.unshift obj
r = cb this r = cb @
@stack.shift() @stack.shift()
r r
if: (name, cb) -> if: (name, cb) ->
# Execute and return this specifiecd block if and only if the
# requested context is valid.
p = @has_any_one(name) p = @has_any_one(name)
if p then cb(this) else '' if p then cb(@) else ''
block: (name, cb) -> block: (name, cb) ->
# Execute and return this specified block if and only if the
# requested context is valid and entrant.
p = @has_any_one(name) p = @has_any_one(name)
if p and _.isObject(p) then @once(p, cb) else '' if p and _.isObject(p) then @once(p, cb) else ''
many: (name, cb) -> many: (name, cb) ->
# Execute and return this specified block for each element of
# the specified context if and only if the requested context
# is valid and is iterable.
ps = @has(name) ps = @has(name)
if not (ps and _.isArray(ps)) if not (ps and _.isArray(ps))
return "" return ""
(_.map ps, (p) => @once(p, cb)).join('') (_.map ps, (p) => @once(p, cb)).join('')
templatize: (name, cb) -> template: (name, cb) ->
# Store the specified block under a name. No production.
@templates[name] = cb @templates[name] = cb
"" return ""
render: (name) -> render: (name) ->
if @templates[name]? and _.isfunction(@templates[name]) then @templates[name](@) else "" if @templates[name]? and _.isfunction(@templates[name]) then @templates[name](@) else ""