From: dsc Date: Wed, 15 Feb 2012 06:01:55 +0000 (-0800) Subject: Adds many boilerplate files, including Coke buildfile, view helpers, and tmproj. X-Git-Url: http://git.less.ly:3516/?a=commitdiff_plain;h=af5f941e51e19024024ee7a32277478a73787b57;p=kraken-ui.git Adds many boilerplate files, including Coke buildfile, view helpers, and tmproj. --- diff --git a/.gitignore b/.gitignore index e3d5df7..cad98b1 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ test/*.log test/fixtures/*.json test/fixtures/logs/*.log +lib/version.js build/ dist/ tmp/ diff --git a/Cokefile b/Cokefile new file mode 100644 index 0000000..7527c91 --- /dev/null +++ b/Cokefile @@ -0,0 +1,40 @@ +require 'buildtools' +require 'buildtools/tasks' + + +PROJECT_NAME = 'kraken-ui' +MODULE_LINK = "node_modules/#PROJECT_NAME" + + + +task \link 'Link package source to node_modules so the name resolves correctly' -> + # Browser-based require doens't support relative requires, but things + # like `require 'kraken-ui/utils'` rarely work in node without this hack. + mkdirp 'node_modules' + if not exists MODULE_LINK + say "Creating #PROJECT_NAME symlink..." + fs.symlinkSync "../lib", MODULE_LINK + +task \server 'Start dev server' -> + invoke \link + invoke \update_version + run 'lib/server/server.co' + +task \build 'Build coco sources' -> + invoke \link + invoke \update_version + coco <[ -bjc package.co ]> + +task \test 'Rebuild test files and run tests' -> + invoke \link + tests = glob.globSync 'test/*.co' + tests.forEach (file) -> + js = file.replace '.co', '.js' + fs.unlinkSync js if exists js + coco [ '-bc', file ] + sh 'expresso' + +task \clean 'Clean up environment and artifacts' -> + remove [MODULE_LINK, 'var', 'tmp/dest'], true + + diff --git a/kraken-ui.tmproj b/kraken-ui.tmproj new file mode 100644 index 0000000..4a2a196 --- /dev/null +++ b/kraken-ui.tmproj @@ -0,0 +1,125 @@ + + + + + currentDocument + lib/server/server.co + documents + + + expanded + + name + kraken-ui + regexFileFilter + !(?x:package\.json|license\.md|paver-minilib\.zip|\.([oa]|dylib|fla|py[co]|mako\.py|pch|cm[oix]|cache|(xcode)proj)|(fish(_read)?_history|fishd\..*)|/Icon\r|/svn-commit(\.[2-9])?\.tmp|/\.(?!(git|svn|npm)ignore|htaccess|gitmodules)[^/]*)$ + regexFolderFilter + !.*/(?x: data | static/vendor|www/js/kraken-ui | var|target|node_modules|html-template|bin-debug | \.[^/]* | .*\.(egg-info|framework|app|(pbx?|xcode)proj|xcode|bundle) | CVS|_darcs|_MTN|\{arch\}|blib | .*~\.nib )$ + sourceDirectory + + + + fileHierarchyDrawerWidth + 217 + metaData + + lib/main.co + + caret + + column + 0 + line + 9 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + lib/server/server.co + + caret + + column + 0 + line + 29 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + lib/version.js + + caret + + column + 0 + line + 1 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + package.co + + caret + + column + 0 + line + 34 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + www/graph.jade + + caret + + column + 14 + line + 0 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + www/layout.jade + + caret + + column + 8 + line + 20 + + firstVisibleColumn + 0 + firstVisibleLine + 0 + + + openDocuments + + package.co + lib/server/server.co + lib/version.js + lib/main.co + www/layout.jade + www/graph.jade + + showFileHierarchyDrawer + + windowFrame + {{0, 0}, {1342, 1058}} + + diff --git a/lib/main.co b/lib/main.co index 8653c87..d43ca5e 100644 --- a/lib/main.co +++ b/lib/main.co @@ -1,13 +1,11 @@ g = null main = -> - g = new Dygraph do - $ '#graphdiv' .0 + g := new Dygraph do + $ '#graph' .0 'data/page_views_by_project.csv' {'logscale': true} - - jQuery main \ No newline at end of file diff --git a/lib/server/index.js b/lib/server/index.js new file mode 100755 index 0000000..0f3d9c4 --- /dev/null +++ b/lib/server/index.js @@ -0,0 +1,5 @@ +#!/usr/bin/env node +var coco = require('coco') +, coffee = require('coffee-script') +, server = require('./server') +; diff --git a/lib/server.co b/lib/server/server.co similarity index 55% rename from lib/server.co rename to lib/server/server.co index 62d83dc..16cc0d7 100755 --- a/lib/server.co +++ b/lib/server/server.co @@ -2,6 +2,7 @@ fs = require 'fs' path = require 'path' +{exec, spawn} = require 'child_process' _ = require 'underscore' express = require 'express' @@ -18,30 +19,41 @@ nib = require 'nib' PORT = 8081 CWD = process.cwd() -WWW = "#CWD/www" -VAR = "#CWD/var" +WWW = "#CWD/www" +VAR = "#CWD/var" +STATIC = "#CWD/static" +NODE_ENV = process.env.NODE_ENV or 'development' +VERSION = 'dev' +err, stdout, stderr <- exec 'git rev-parse --short HEAD', {cwd:CWD, env:process.env} +throw err if err +VERSION = stdout.trim! + +# err <- fs.writeFile 'lib/version.js', "module.exports = exports = '#{VERSION}';\n", 'utf8' +# try VERSION = require '../version' catch e + ### Setup exports.app = app = express.createServer() app.listen PORT -console.log "~>\tStarting kraken-ui Dev Server (port=#PORT)!\t<~" +console.log "starting Kraken dev server (port=#PORT, env=#NODE_ENV, version=#VERSION)" +console.log "========================================================================" app.configure -> - console.log 'server.configure()' - app.set 'views', WWW app.set 'view engine', 'jade' - app.set 'view options', - layout : true + app.set 'view options', { + layout : false pretty : true - _ : _ - jade : require 'jade' - fs : fs + version : VERSION + WWW : WWW + VAR : VAR + STATIC : STATIC + } import require './view-helpers' # app.use express.logger() app.use express.bodyParser() @@ -60,18 +72,18 @@ app.configure -> # wrap modules in commonjs closure for browser app.use compiler do enabled : 'commonjs' - src : [ VAR, WWW ] + src : [ VAR, WWW, STATIC ] dest : VAR options : commonjs : drop_path_parts:1 log_level : log_level app.use require('browserify') do - mount : '/lib/browserify.js' - require : 'seq' + mount : '/vendor/browserify.js' + require : <[ events seq ]> app.use express.static WWW app.use express.static VAR - app.use express.static "#{CWD}/static" + app.use express.static STATIC app.use express.errorHandler do dumpExceptions : true showStack : true @@ -80,6 +92,9 @@ app.configure -> ### Routes app.get '/', (req, res) -> - res.render 'index' + res.render 'graph' + +app.get '/:page', (req, res) -> + res.render req.params.page diff --git a/lib/server/view-helpers.co b/lib/server/view-helpers.co new file mode 100644 index 0000000..5313b03 --- /dev/null +++ b/lib/server/view-helpers.co @@ -0,0 +1,33 @@ +# Utilities for use in templates + +fs = exports.fs = require 'fs' +path = exports.path = require 'path' + +_ = exports._ = require 'underscore' +yaml = exports.yaml = require 'js-yaml' +jade = exports.jade = require 'jade' + +NODE_ENV = exports.NODE_ENV = (process.env.NODE_ENV or 'development').toLowerCase() +IS_PROD = exports.IS_PROD = _ <[ prod production ]> .contains NODE_ENV +IS_DEV = exports.IS_DEV = not IS_PROD + + +sources = exports.sources = (modulesFile) -> + mods = yaml.load fs.readFileSync modulesFile, 'utf8' + _.flatten mods.map ({suffix or '', paths}) -> joinTree('', paths).map -> it+suffix + +joinTree = exports.joinTree = function joinTree(root, tree) + return ["#root/#tree"] if typeof tree is 'string' + _ tree .reduce do + (acc, branch) -> + if typeof branch is 'string' + acc.push "#root/#branch" + else + _.each branch, (v, k) -> + acc.push.apply acc, joinTree "#root/#k", v + acc + [] + + +# util = exports.util = require '../util' + diff --git a/package.co b/package.co index 4c8ad2f..0d767ae 100644 --- a/package.co +++ b/package.co @@ -10,18 +10,18 @@ main : './lib/kraken-ui.js' dependencies : 'coco' : '>= 0.7.0' - 'express' : '>= 2.5.7' + 'express' : '>= 2.5.8' 'connect-compiler' : '>= 0.1.1' 'connect-compiler-extras' : 'https://github.com/dsc/connect-compiler-extras/tarball/master' 'jade' : '>= 0.20.1' 'stylus' : '>= 0.23.0' 'nib' : '>= 0.3.2' - 'browserify' : '>= 1.9.3' + 'browserify' : '>= 1.9.4' 'seq' : '>= 0.3.5' 'underscore' : '>= 1.3.1' 'underscore.string' : '>= 2.0.0' - 'js-yaml' : '>= 0.3.1' - 'backbone' : '>= 0.5.3' + 'js-yaml' : '>= 0.3.5' + 'backbone' : '>= 0.9.1' devDependencies : 'buildtools' : 'https://github.com/dsc/node-buildtools/tarball/master' 'expresso' : '>= 0.9.2' diff --git a/package.json b/package.json index a6db9ab..54d22a7 100644 --- a/package.json +++ b/package.json @@ -13,18 +13,18 @@ "main": "./lib/kraken-ui.js", "dependencies": { "coco": ">= 0.7.0", - "express": ">= 2.5.7", + "express": ">= 2.5.8", "connect-compiler": ">= 0.1.1", "connect-compiler-extras": "https://github.com/dsc/connect-compiler-extras/tarball/master", "jade": ">= 0.20.1", "stylus": ">= 0.23.0", "nib": ">= 0.3.2", - "browserify": ">= 1.9.3", + "browserify": ">= 1.9.4", "seq": ">= 0.3.5", "underscore": ">= 1.3.1", "underscore.string": ">= 2.0.0", - "js-yaml": ">= 0.3.1", - "backbone": ">= 0.5.3" + "js-yaml": ">= 0.3.5", + "backbone": ">= 0.9.1" }, "devDependencies": { "buildtools": "https://github.com/dsc/node-buildtools/tarball/master", diff --git a/www/graph.jade b/www/graph.jade new file mode 100644 index 0000000..a6dd409 --- /dev/null +++ b/www/graph.jade @@ -0,0 +1,9 @@ +extends layout + +block title + title Kraken Test Graph + +block content + section#graph + + diff --git a/www/index.jade b/www/index.jade deleted file mode 100644 index 547242f..0000000 --- a/www/index.jade +++ /dev/null @@ -1,3 +0,0 @@ -h1 ohboy - -#graphdiv diff --git a/www/layout.jade b/www/layout.jade index 27ef1f4..a071531 100644 --- a/www/layout.jade +++ b/www/layout.jade @@ -4,14 +4,32 @@ html meta(http-equiv="content-type", content="text/html; charset=utf-8") link(type='text/css', rel='stylesheet', media='screen', href='/css/reset.min.css') link(type='text/css', rel='stylesheet', media='screen', href="/css/kraken.css") - title Kraken + block head + link(type="image/ico", rel="icon", href="/favicon.ico") + link(type="image/x-icon", rel="shortcut icon", href="/favicon.ico") + block title + title Kraken body - .content - != body - .scripts - script(src="/vendor/jquery.min.js") - //- script(src="/vendor/dygraph-combined.js") - script(src="/vendor/dygraph.js") + header + h1: a(href="/") Kraken + //- + block nav + nav#menu: ul + li.home Home + block header + + section#content + block content + .inner + + footer + block footer + + .scripts + //- script(src='/lib/lib-bundle.min.js') + for src in sources(WWW+'/modules.yaml') + script(src=src+"?"+version) + block scripts script(src="/js/kraken-ui/main.js") diff --git a/www/modules.yaml b/www/modules.yaml new file mode 100644 index 0000000..fc83c4c --- /dev/null +++ b/www/modules.yaml @@ -0,0 +1,24 @@ +- suffix: .js + paths: + - vendor: + - es5-shim.min + - modernizr.min + - json2.min + - jquery.min + - jquery.hotkeys.min + - jquery.history.min + - browserify + - require + - underscore.mod + - underscore.string.mod + - u.min + - dygraph + +# - suffix: .mod.js +# paths: +# - 'js/kraken-ui': +# - graph + +# - suffix: .js +# paths: +# - js/kraken-ui/main