Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
caridy committed Oct 17, 2010
1 parent 0cf369e commit 8f3d1eb
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 3 deletions.
14 changes: 11 additions & 3 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ To use it, follow these simple steps:
npm install yui3-gallery
npm install yui3-2in3

git clone git://github.com/caridy/yui3-gallery-build.git
git clone git://github.com/caridy/yui3-gallery-dashboard.git

cd yui3-gallery-build
cd yui3-gallery-dashboard

For a normal run:
./server.js
Expand All @@ -19,9 +19,17 @@ Visit: http://localhost:8001/

To use Spark: http://github.com/senchalabs/spark

Spark Config (config.js):

module.exports = {
port: 8001,
env: 'production',
workers: 10
}

Install spark via:

npm install spark
spark

Visit: http://localhost:3200/
Visit: http://localhost:8001/
12 changes: 12 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
port: 3200,
env: 'development'
}

/*
module.exports = {
port: 8001,
env: 'production',
workers: 10
}
*/
179 changes: 179 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
#!/usr/bin/env node

//Needed for monit/upstart
//Change directory into the script directory so includes resolve
process.chdir(__dirname);

var express = require('express'),
path = require('path'),
fs = require('fs'),
YUI = require('yui3').YUI,
DEBUG = true;


//Create the express application and allow the use of Spark (http://github.com/senchalabs/spark)
var app = module.exports = express.createServer();
/**
* Create the external instance that will host our "express" server.
* For a performance gain, you can "use" common modules here, so they
* are available when a new instance is created per request.
*/
YUI({ debug: false }).use('express', 'node', function(Y) {

//Configure it with some simple configuration options.
app.configure(function(){
app.use(express.methodOverride());
app.use(express.bodyDecoder());
app.use(express.cookieDecoder());
app.use(app.router);
app.use(express.conditionalGet());
app.use(express.cache());
app.use(express.gzip());
app.use(express.staticProvider(__dirname + '/assets'));
});

//Set the development environment to debug, so YUI modues echo log statements
app.configure('development', function(){
DEBUG = true;
});
//Set the production environment to halt all debug logs.
app.configure('production', function(){
DEBUG = false;
});

/**
* This version of the YUIExpress engine comes with a simple YUI combo handler
* So you can put "use" inside your locals var on render:
*
* res.render('index.html', {
* locals: {
* use: ['dd', 'tabview']
* }
* });
*
* This will load a URL into the page like this:
* <script src="/combo?dd&tabview"></script>
*
* Note, currently it has to be "/combo", the internal renderer doesn't
* know what you set this to. Eventually we can add it to YUI.configure.
*/
app.get('/combo', YUI.combo);

/**
* This is the "black magic" part. This tells Express to use YUI to render
* all HTML pages
*/
app.register('.html', YUI);


/**
* These partials will be added to every page served by YUI, good for templating.
* They can be added to by locals.partials on a per page basis. A partial looks like this:
* {
* name: 'header', //Name of the /views/partial/{name}.html file to load
* method: 'append', //append,prepend,appendChild
* node: '#conent', //Any valid selector
* enum: 'one', //one,all
* fn: function //The callback function to run after the action.
* }
* Defaults to enum: "one" and method: "append"
*/

YUI.partials = [
{
name: 'layout_head',
node: 'head'
}
];

/**
* YUI.configure allows you to configure routes for the yui2 & yui3 assests.
* With this config you will serve yui2 assets from /yui2/ and yui3 assets from
* /yui3
*
*/
YUI.configure(app, {
yui2: '/yui2/',
yui3: '/yui3/'
});

/**
* The route controller for the default page: /
* This is a simple example of serving a static HTML page with a little
* Javascript to enhance the page.
*/
app.get('/', function(req, res) {
//Render from ./views/index.html
res.render('index.html', {
//Locals used by the YUI renderer
locals: {
/**
* This is the content placeholder in your ./views/layout.html file.
* The content of index.html will be inserted here.
*/
content: '#content',
/**
* Standard object hash to be passed to Y.Lang.sub after the
* content has been loaded, but before it's inserted into the YUI
* instance on render.
*/
sub: {
title: 'YUI3 Gallery: Dashboard'
},
/**
* The after method will be invoked after the layout.html file
* has been loaded into the instance. This allows you to change
* the total layout, after all the peices have been assembled.
*/
after: function(Y, options, partial) {
Y.one('title').set('innerHTML', 'YUI3 Gallery: Dashboard');
}
}
});
});

app.get('/api/:id?', function(req, res) {
require('./pages/module.js').partial(req, res, {
debug: DEBUG,
module: req.params.id,
partial: 'module_api.html'
});
});

app.get('/yeti/:id?', function(req, res) {
require('./pages/module.js').partial(req, res, {
debug: DEBUG,
module: req.params.id,
partial: 'module_yeti.html'
});
});

app.get('/jslint/:id?', function(req, res) {
require('./pages/module.js').partial(req, res, {
debug: DEBUG,
module: req.params.id,
partial: 'module_jslint.html'
});
});

app.get('/module/:id?', function(req, res) {
require('./pages/module.js').render(req, res, {
debug: DEBUG,
module: req.params.id,
page: 'module.html'
});
});

app.get('/modules', function(req, res) {
require('./pages/modules.js').render(req, res, {
debug: DEBUG,
bucket: 'oncdn'
});
});

app.listen(8001);
if (DEBUG) {
console.log('Server running at: http://localhost:8001/');
}

});

0 comments on commit 8f3d1eb

Please sign in to comment.