Skip to content

Commit

Permalink
prepare to re-use hash builds
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioCrisostomo committed Nov 6, 2014
1 parent 3320fe6 commit 449a29b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
12 changes: 11 additions & 1 deletion core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var guides = require('../middleware/guides')('core', {

var project = 'core';
var versions = require('../package.json')._projects[project].versions;
var getHashDependencies = require('../lib/getHashDependencies')();
var links = versions.slice(1).map(function(version){
return {
version: version,
Expand Down Expand Up @@ -41,13 +42,15 @@ module.exports = function(app){
});
});

app.get('/core/builder', function(req, res){
app.get('/core/builder/:hash?', function(req, res){
var hash = req.params.hash;
res.render('builder/index', {
title: 'MooTools Core Builder',
navigation: 'core',
page: 'builder',
project: 'Core',
site: 'core',
hashDependencies: getHashDependencies(hash),
version: versions[0],
versions: links,
dependencies: require('../builder/dependencies.js')(project, versions[0])
Expand All @@ -61,4 +64,11 @@ module.exports = function(app){
app.get('/core/guides', core, guides.index);
app.get('/core/guides/:guide', core, guides.article);

// hash build redirect
var regex = /core\/([a-z]+[0-9]+[a-z0-9]*|[0-9]+[a-z]+[a-z0-9]*)$/;
app.get(regex, function(req, res){
var hash = req.path.match(regex)[1];
res.redirect('/core/builder/' + hash);
});

};
20 changes: 20 additions & 0 deletions lib/getHashDependencies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

function getHashDependencies(){

return function(hash){
if (!hash) return [];
// I leave a dummy here so far with the first example
// on the issue Tim opened on Github
var DB = { 'e8f3003df2d0919c1091b11854a53e9b':
{
date: '1415017941',
deps: 'Core/Core;Core/String;Core/Event;Core/Browser;Core/Class;Core/Element.Style;Core/Element.Event;Core/Element.Delegation;Core/Element.Dimensions;Core/Fx;Core/Fx.CSS;Core/Fx.Tween;Core/Fx.Morph;Core/Fx.Transitions;Core/Request.HTML;Core/Request.JSON;Core/Cookie;Core/DOMReady'
}
};
var dependencies = DB[hash].deps.split(';');
return dependencies;
}
}

module.exports = getHashDependencies;
11 changes: 10 additions & 1 deletion more/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ module.exports = function(app){
});
});

app.get('/more/builder', function(req, res){
app.get('/more/builder/:hash?', function(req, res){
var hash = req.params.hash;
res.render('builder/index', {
title: 'MooTools More Builder',
navigation: 'more',
page: 'builder',
project: 'More',
site: 'more',
hashDependencies: getHashDependencies(hash),
version: lastVersion,
dependencies: require('../builder/dependencies.js')(project, lastVersion)
});
Expand All @@ -47,4 +49,11 @@ module.exports = function(app){
app.get('/more/guides', more, guides.index);
app.get('/more/guides/:guide', more, guides.article);

// hash build redirect
var regex = /more\/([a-z]+[0-9]+[a-z0-9]*|[0-9]+[a-z]+[a-z0-9]*)$/;
app.get(regex, function(req, res){
var hash = req.url.match(regex)[1];
res.redirect('/more/builder#' + hash);
});

};
9 changes: 5 additions & 4 deletions views/builder/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ block main

div.header.clearfix
h1 Download complete source
form(method="post", action="../builder")
form(method="post", action="/builder")
input(hidden, name="project", value="#{project}")
.save

Expand Down Expand Up @@ -40,7 +40,7 @@ block main

h3 Choose which modules you want to use

form(method="post", action="../builder")
form(method="post", action="/builder")
input(hidden, name="project", value="#{project}")
table#builderOptions
tr
Expand All @@ -50,16 +50,17 @@ block main
td Description

each yaml, module in dependencies
- var file = project + "/" + module;
- var hashRequested = hashDependencies.indexOf(file) != -1;
tr
td
input(type="checkbox", value="#{project}/#{module}", name="modules[]", data-provides="#{yaml.prov}", data-requires="#{yaml.req}")
input(type="checkbox", value=file, name="modules[]", data-provides="#{yaml.prov}", data-requires="#{yaml.req}", checked=hashRequested)
td #{module}
td #{yaml.prov}
td #{yaml.desc}

h2.step Options:


.save

label
Expand Down

0 comments on commit 449a29b

Please sign in to comment.