Permalink
Browse files

Added root param + small refactor

  • Loading branch information...
1 parent 2adf5cc commit 5a48854eb49175ea66835408faf58768469c16db @olaf-k-1a olaf-k-1a committed Oct 9, 2013
Showing with 50 additions and 22 deletions.
  1. +20 −18 cdn.js
  2. +15 −2 static/cdn.css
  3. +15 −2 static/index.html
View
38 cdn.js
@@ -51,7 +51,7 @@ app.configure(function() {
* - skin (serve skin, default does not)
*/
app.get(/^\/ariatemplates-(\d\.\d\.\d{1,2})\.js/, function (req, res) {
- getFwk(res, 'ariatemplates-', req.params[0], req.query.dev != undefined, req.query.skin != undefined);
+ getFwk(req, res, 'ariatemplates-', req.params[0]);
});
/*
@@ -64,7 +64,7 @@ app.get(/^\/ariatemplates-(\d\.\d\.\d{1,2})\.js/, function (req, res) {
* - skin (serve skin, default does not)
*/
app.get(/^\/aria-templates-(\d\.\d\-\d{1,2}[a-zA-Z]?)\.js/, function (req, res) {
- getFwk(res, 'aria-templates-', req.params[0], req.query.dev != undefined, req.query.skin != undefined);
+ getFwk(req, res, 'aria-templates-', req.params[0]);
});
/*
@@ -80,11 +80,10 @@ app.get(/^\/aria-templates-(\d\.\d\-\d{1,2}[a-zA-Z]?)\.js/, function (req, res)
app.get(/^\/at(\d)[\-\.]?(\d)[\-\.]?(\d{1,2})([a-zA-Z]?)\.js/, function (req, res) {
var amadeus = req.query['1a'] != undefined;
getFwk(
- res, // res
- amadeus ? 'aria-templates-' : 'ariatemplates-', // suffix
- req.params[0] + '.' + req.params[1] + (amadeus ? '-' : '.') + req.params[2] + req.params[3], // version
- req.query.dev != undefined, // dev?
- req.query.skin != undefined // skin?
+ req,
+ res,
+ amadeus ? 'aria-templates-' : 'ariatemplates-', // prefix
+ req.params[0] + '.' + req.params[1] + (amadeus ? '-' : '.') + req.params[2] + req.params[3] // version
);
});
@@ -94,24 +93,27 @@ app.get(/^\/at(\d)[\-\.]?(\d)[\-\.]?(\d{1,2})([a-zA-Z]?)\.js/, function (req, re
app.get('/atlatest.js', function (req, res) {
var amadeus = req.query['1a'] != undefined;
getFwk(
- res, // res
- amadeus ? 'aria-templates-' : 'ariatemplates-', // suffix
- config.LATEST.substr(0,1) + '.' + config.LATEST.substr(1,1) + (amadeus ? '-' : '.') + config.LATEST.substr(2), // version
- req.query.dev != undefined, // dev?
- req.query.skin != undefined // skin?
+ req,
+ res,
+ amadeus ? 'aria-templates-' : 'ariatemplates-', // prefix
+ config.LATEST.substr(0,1) + '.' + config.LATEST.substr(1,1) + (amadeus ? '-' : '.') + config.LATEST.substr(2) // version
);
})
/*
* Retrieve the content of the bootstrap file from disk or cache
*/
-var getFwk = function (res, suffix, version, dev, skin) {
+var getFwk = function (req, res, prefix, version) {
+ var dev = req.query.dev != undefined;
+ var skin = req.query.skin != undefined;
+ var root = req.query.root ? escape(req.query.root) : '';
+
var cache = dev ? fwkdevcache : fwkcache;
- var filename = suffix + version + '.js';
+ var filename = prefix + version + '.js';
if (cache[filename]) {
// console.log('using cache for ' + filename);
- sendFwk(res, cache[filename], version, dev, skin)
+ sendFwk(res, cache[filename], version, dev, skin, root)
} else {
var fwkfile = (dev ? config.PATH_TO_DEV_FWK + version + '/aria/' : config.PATH_TO_MIN_FWK) + filename;
// console.log('looking for ' + fwkfile);
@@ -124,7 +126,7 @@ var getFwk = function (res, suffix, version, dev, skin) {
}
else {
cache[filename] = data;
- sendFwk(res, data, version, dev, skin);
+ sendFwk(res, data, version, dev, skin, root);
}
});
}
@@ -139,7 +141,7 @@ var getFwk = function (res, suffix, version, dev, skin) {
/*
* Send the content of the bootstrap along with the necessary JS lines to add skin, change dev url, update transport, update the root map.
*/
-var sendFwk = function (res, content, version, dev, skin) {
+var sendFwk = function (res, content, version, dev, skin, root) {
var l = content.length;
var url = config.CDN_URL + (dev ? '/dev/' + version : '');
@@ -154,7 +156,7 @@ var sendFwk = function (res, content, version, dev, skin) {
var bufSkin = new Buffer('document.write(\'<script src="'+ url + '/aria/css/atskin-' + version + '.js"><\/script>\');', 'utf-8');
l += bufSkin.length;
}
- var bufFix = new Buffer('document.write("<script>aria.core.IO.updateTransports({\'crossDomain\' : \'aria.core.transport.XHR\'});aria.core.DownloadMgr.updateRootMap({\'aria\' : \'' + url + '/\', \'*\' : \'\'});</script>");', 'utf-8');
+ var bufFix = new Buffer('document.write("<script>aria.core.IO.updateTransports({\'crossDomain\' : \'aria.core.transport.XHR\'});aria.core.DownloadMgr.updateRootMap({\'aria\' : \'' + url + '/\', \'*\' : \'' + root + '\'});</script>");', 'utf-8');
@benouat

benouat Oct 11, 2013

Owner

I think you don't need to use '*' in the updateRootMap()

To me updateRootMap should only contain a rule for 'aria', and that's it. For all other url's (what correspond to *) you should use the Aria.rootFolderPath to be set to root, not a rule in the updateRootMap()

l += bufFix.length;
var r = new Buffer(l), offset = 0;
View
@@ -5,10 +5,10 @@ body {
background: #f8f8f8;
}
h1 {
- margin: 50px 0 30px 0;
+ margin: 40px 0 20px 0;
color: #5092BD
}
-.code {
+.code, dt {
font-family: monospace;
color: white;
background: #333;
@@ -20,4 +20,17 @@ h1 {
}
.option {
color: #6bdcff;
+}
+dt {
+ color: #666;
+ display: list-item;
+ float: left;
+ margin-left: 70px;
+}
+dd {
+ margin: 0 0 10px 130px;
+}
+.warn {
+ background: #fcffb7;
+ padding: 5px;
}
View
@@ -2,20 +2,33 @@
<html>
<head>
<link rel="stylesheet" href="http://ariatemplates.com/styles/webfonts.css" type="text/css"/>
+ <title>Aria Templates CDN</title>
<link rel="stylesheet" href="/cdn.css" type="text/css"/>
</head>
<body>
<img src="/logo-cdn.png" alt="Aria Templates"/>
+
<h1>Usage</h1>
+
<p>To use this CDN in your Aria Templates project, include the following line in your bootstrap file:</p>
<p class="term code">&lt;script src="http://cdn.ariatemplates.com/at<span class="option">&lt;version&gt;</span>.js<span class="option">[?params]</span>"&gt;&lt;/script&gt;</p>
<p>Where:</p>
<p><span class="code option">version</span> is the version label of the framework, using either dots or dashes, or <span class="code">latest</span> to get the latest build available.</p>
- <p><span class="code option">params</span> contains optional parameters such as <span class="code">skin</span> to request the Aria skin or <span class="code">dev</span> to fetch unminified files.</p>
+ <p><span class="code option">params</span> contains optional parameters of the following list:</p>
+ <dl>
+ <dt><span class="code">skin</span></dt><dd>to request the Aria skin</dd>
+ <dt><span class="code">dev<span></dt><dd>to fetch unminified files.</dd>
+ <dt><span class="code">root<span></dt><dd>to set a specific rootMap (i.e. the URL root used to resolve classpaths) which by default is the URL of your bootstrap.</dd>
+ </dl>
+
<h1>Examples</h1>
<div class="term code">&lt;script src="http://cdn.ariatemplates.com/<span class="option">at1.4.9.js</span>"&gt;&lt;/script&gt;</div>
<div class="term code">&lt;script src="http://cdn.ariatemplates.com/<span class="option">atlatest.js?skin</span>"&gt;&lt;/script&gt;</div>
- <div class="term code">&lt;script src="http://cdn.ariatemplates.com/<span class="option">at1.4-2.js?dev&skin</span>"&gt;&lt;/script&gt;</div>
+ <div class="term code">&lt;script src="http://cdn.ariatemplates.com/<span class="option">at1.4-2.js?dev&skin&root=/</span>"&gt;&lt;/script&gt;</div>
+
+ <h1>Disclaimer</h1>
+ <p class="warn">This CDN is intended for prototyping and development purposes only. <strong>Do not use in production</strong>.</p>
+
</body>
</html>

0 comments on commit 5a48854

Please sign in to comment.