Permalink
Browse files

Initial framework

  • Loading branch information...
1 parent 03b775f commit f0fd33bb6fdcda941046df368ee5835f11e343c1 @toantran committed Mar 24, 2012
Showing 403 changed files with 43,145 additions and 0 deletions.
View
86 app.js
@@ -0,0 +1,86 @@
+
+/*
+ Module dependencies.
+*/
+
+(function() {
+ var app, express, restrict, routes;
+
+ express = require('express');
+
+ routes = require('./routes');
+
+ app = module.exports = express.createServer();
+
+ app.configure(function() {
+ app.set('views', "" + __dirname + "/views");
+ app.set('view engine', 'jade');
+ app.use(express.bodyParser());
+ app.use(express.methodOverride());
+ app.use(express.cookieParser());
+ app.use(express.session({
+ secret: 'saigon riverland'
+ }));
+ app.use(app.router);
+ return app.use(express["static"]("" + __dirname + "/public"));
+ });
+
+ app.configure('development', function() {
+ return app.use(express.errorHandler({
+ dumpExceptions: true,
+ showStack: true
+ }));
+ });
+
+ app.configure('production', function() {
+ return app.use(express.errorHandler());
+ });
+
+ app.dynamicHelpers({
+ request: function(req) {
+ return req;
+ },
+ hasMessages: function(req) {
+ if (!req.session) {
+ return false;
+ } else {
+ return Object.keys(req.session.flash || {}).length;
+ }
+ },
+ messages: function(req) {
+ return function() {
+ var msgs, reduceFn, result;
+ msgs = req.flash();
+ reduceFn = function(arr, type) {
+ return arr.concat(msgs[type]);
+ };
+ return result = Object.keys(msgs).reduce(reduceFn, []);
+ };
+ }
+ });
+
+ restrict = function(req, res, next) {
+ var returnurl, _ref;
+ if ((_ref = req.session) != null ? _ref.user : void 0) {
+ req.user = req.session.user;
+ return next();
+ } else {
+ returnurl = encodeURIComponent(req.url);
+ req.session.error = 'Access denied!';
+ return res.redirect("/login?returnurl=" + returnurl);
+ }
+ };
+
+ app.get('/login', routes.login);
+
+ app.get('/logout', routes.logout);
+
+ app.post('/login', routes.authenticate);
+
+ app.get('/', restrict, routes.index);
+
+ app.listen(3000);
+
+ console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
+
+}).call(this);
View
@@ -0,0 +1,65 @@
+
+###
+ Module dependencies.
+###
+
+express = require 'express'
+routes = require './routes'
+
+app = module.exports = express.createServer()
+
+# Configuration
+app.configure ->
+ app.set 'views', "#{__dirname}/views"
+ app.set 'view engine', 'jade'
+ app.use express.bodyParser()
+ app.use express.methodOverride()
+ app.use express.cookieParser()
+ app.use express.session({ secret: 'saigon riverland' })
+ app.use app.router
+ app.use express["static"]("#{__dirname}/public")
+
+app.configure 'development', ->
+ app.use express.errorHandler( dumpExceptions: true, showStack: true )
+
+app.configure 'production', ->
+ app.use express.errorHandler()
+
+# Some dynamic view helpers
+app.dynamicHelpers
+ request: (req) -> req
+
+ hasMessages: (req) ->
+ if (!req.session)
+ false
+ else
+ Object.keys(req.session.flash || {}).length
+
+ messages: (req) ->
+ ->
+ msgs = req.flash()
+ reduceFn = (arr, type) -> arr.concat( msgs[type] )
+ result = Object.keys(msgs).reduce reduceFn, []
+
+
+restrict = (req, res, next) ->
+ if req.session?.user
+ req.user = req.session.user
+ next()
+ else
+ returnurl = encodeURIComponent req.url
+ req.session.error = 'Access denied!'
+ res.redirect "/login?returnurl=#{returnurl}"
+
+
+
+# Routes
+
+app.get '/login', routes.login
+app.get '/logout', routes.logout
+app.post '/login', routes.authenticate
+
+app.get '/', restrict, routes.index
+
+app.listen 3000
+console.log "Express server listening on port %d in %s mode", app.address().port, app.settings.env
View
@@ -0,0 +1,101 @@
+jQuery ($) ->
+ makethis = -> @
+
+ global = makethis.call()
+
+
+ ###
+ Publish helper
+ ###
+ $.publish = (title, body) ->
+ console.log title, body
+ ###
+ Publish helper end
+ ###
+
+ ###
+ Template engine
+ ###
+ el = () ->
+
+ doc = document;
+
+ directProperties =
+ 'class': 'className'
+ className: 'className'
+ defaultValue: 'defaultValue'
+ 'for': 'htmlFor'
+ html: 'innerHTML'
+ text: 'textContent'
+ value: 'value'
+
+ booleanProperties =
+ checked: 1
+ defaultChecked: 1
+ disabled: 1
+ multiple: 1
+ selected: 1
+
+ setProperty = ( el, key, value ) ->
+ prop = directProperties[ key ]
+ if prop
+ el[ prop ] = '' + (value ? '')
+ else if booleanProperties[ key ]
+ el[ key ] = !!value
+ else if not value?
+ el.removeAttribute key
+ else
+ el.setAttribute key, '' + value
+
+
+ appendChildren = ( el, children ) ->
+ for node in children when node?
+ do (node) ->
+ if node instanceof Array
+ appendChildren el, node
+ else
+ if typeof node is 'string'
+ spanEl = doc.createElement 'span'
+ spanEl.innerHTML = node
+ node = spanEl
+ el.appendChild node
+
+
+
+ splitter = /(#|\.)/
+
+ create = ( tag, props, children ) ->
+ if props instanceof Array
+ children = props;
+ props = null;
+
+ if splitter.test( tag )
+ parts = tag.split splitter
+ tag = parts[0]
+ parts = parts[1..]
+
+ if not props?
+ props = {}
+
+ for part, index in parts by 2
+ name = parts[index + 1]
+ if part is '#'
+ props.id = name
+ else
+ props.className = if props.className then props.className + ' ' + name else name
+
+ thisEl = doc.createElement tag
+
+ if props?
+ for prop, propVal of props
+ setProperty thisEl, prop, propVal
+ if children?
+ appendChildren thisEl, children
+
+ thisEl
+
+ $.el = el()
+
+ ###
+ Template engine end
+ ###
@@ -0,0 +1,4 @@
+jQuery ($) ->
+ $('.carousel').carousel
+ interval: 5000
+
@@ -0,0 +1,7 @@
+jQuery ($) ->
+ makethis = -> @
+
+ global = makethis.call()
+ global.setActiveMenu = (menuIndex) ->
+ $('ul.nav > li').removeClass 'active'
+ $($('ul.nav > li')[menuIndex]).addClass 'active'
@@ -0,0 +1,5 @@
+jQuery ($) ->
+ makethis = -> @
+
+ global = makethis.call()
+ global.setActiveMenu 3
@@ -0,0 +1,5 @@
+jQuery ($) ->
+ makethis = -> @
+
+ global = makethis.call()
+ global.setActiveMenu 4
@@ -0,0 +1,5 @@
+jQuery ($) ->
+ makethis = -> @
+
+ global = makethis.call()
+ global.setActiveMenu 2
Oops, something went wrong.

0 comments on commit f0fd33b

Please sign in to comment.