Browse files

Merge pull request #1 from davglass/master

Add a seed file to use rather than hijacking YUI_config, add small changes for ease of use. (Work by Dav Glass)
  • Loading branch information...
2 parents b5f4a25 + 0c1c0dc commit 91e76275255d0da001c4ab0dd66b7f3e7ef1961e @rockstar committed Dec 14, 2011
Showing with 90 additions and 7 deletions.
  1. +1 −0 .gitignore
  2. +5 −0 Makefile
  3. +8 −0 app.js
  4. +47 −0 lib/seed.js
  5. +0 −1 static/style.css
  6. +16 −0 test/index.html
  7. +13 −6 views/index.mustache
View
1 .gitignore
@@ -1 +1,2 @@
build
+node_modules
View
5 Makefile
@@ -0,0 +1,5 @@
+all: install
+
+install:
+ npm i express combohandler stache
+
View
8 app.js
@@ -3,6 +3,8 @@
var combo = require('combohandler'),
express = require('express'),
stache = require('stache'),
+ seed = require('./lib/seed'),
+ stamp = 'yui3-nightly',
app = express.createServer();
app.configure(function() {
@@ -26,6 +28,12 @@ app.get('/', function(req, res) {
res.render('index', {});
});
app.get('/yui', combo.combine({rootPath: 'build/www'}), function (req, res) {
+ res.body = res.body.replace(/@VERSION@/g, stamp);
+ res.send(res.body, 200);
+});
+
+app.get('/seed', seed.stamp({rootPath: 'build/www'}), function (req, res) {
+ res.body = res.body.replace(/@VERSION@/g, stamp);
res.send(res.body, 200);
});
View
47 lib/seed.js
@@ -0,0 +1,47 @@
+
+var path = require('path'),
+ fs = require('fs');
+ root = '',
+ seeds = {
+ min: '',
+ raw: '',
+ debug: ''
+ };
+
+
+module.exports = {
+ stamp: function(o) {
+ root = path.join(__dirname, '../', o.rootPath);
+
+ if (!path.existsSync(root)) {
+ throw('Root path does not exist');
+ }
+
+ //All the seed files
+ seeds['min'] = fs.readFileSync(path.join(root, 'yui/yui-min.js'), 'utf8');
+ seeds['raw'] = fs.readFileSync(path.join(root, 'yui/yui.js'), 'utf8');
+ seeds['debug'] = fs.readFileSync(path.join(root, 'yui/yui-debug.js'), 'utf8');
+
+ return function(req, res, next) {
+ //Set the filter type for the seed fetch
+ var filt = seeds[req.query.filter] ? req.query.filter : 'min',
+
+ //Stamp the seed config and version
+ seedStamp = '\n\n/* Stamping Seed File */\n' +
+ 'YUI.applyConfig({\n' +
+ ' comboBase: "http://' + req.headers.host + '/yui?",\n' +
+ ' root: "",\n' +
+ ' filter: "' + filt + '"\n' +
+ '});\n' +
+ '\nYUI.version = "yui3-nightly";';
+
+ //Concat the file with the stamp
+ res.body = seeds[filt] + seedStamp;
+ //Set the content type
+ res.contentType('.js');
+ //Send to next route
+ next();
+
+ }
+ }
+}
View
1 static/style.css
@@ -9,7 +9,6 @@ div {
margin: .5em 0;
}
pre {
- width: 70%;
border: 1px solid #333;
line-height: 1.5hm;
background-color: #ccc;
View
16 test/index.html
@@ -0,0 +1,16 @@
+<!doctype html>
+<html>
+<head>
+ <title>Nightly test</title>
+</head>
+<body>
+
+
+<script src="http://127.0.0.1:8082/seed?filter=debug"></script>
+<script>
+YUI().use('node', function(Y) {
+ Y.one('body').setStyle('backgroundColor', 'green');
+});
+</script>
+</body>
+</html>
View
19 views/index.mustache
@@ -9,13 +9,20 @@ releases.</div>
source tree is built and served from /yui. All you need to do is to point your
YUI object to the nightly combo loader.</div>
-<div>Add the following code to your main template before any calls to
-<code>YUI().use()</code>.</div>
+<div>To use this, simply use this as your seed file:</div>
-<pre><code>YUI_config = {
- comboBase: 'http://yuinightly.kludg.com/yui?',
- root: ''
-};</code></pre>
+<pre><code>
+&lt;script src="http://yuinightly.kludg.com/seed"&gt;&lt;/script&gt;
+</code></pre>
+
+<div>
+The seed file also supports the 3 default YUI filter's: <code>min, raw, filter</code>
+</div>
+<pre><code>
+&lt;script src="http://yuinightly.kludg.com/seed?filter=min"&gt;&lt;/script&gt;
+&lt;script src="http://yuinightly.kludg.com/seed?filter=raw"&gt;&lt;/script&gt;
+&lt;script src="http://yuinightly.kludg.com/seed?filter=debug"&gt;&lt;/script&gt;
+</code></pre>
<div><strong>Note:</strong> Do this in a development instance. If you point
production to this development code, you deserve everything you get.</div>

0 comments on commit 91e7627

Please sign in to comment.