Skip to content

Commit

Permalink
Add after-property to allow ordering of plugins
Browse files Browse the repository at this point in the history
Some plugins do not depend on each other and can be used
independently, but if they are used at the same time, they have to
be executed in a specific order.

The "after"-property in components.js, allows the download page to
concatenate the plugins in the right order, without enforcing a
hard dependency.
  • Loading branch information
zeitgeist87 committed Feb 26, 2016
1 parent 8cf72b3 commit 224b7a1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 2 additions & 0 deletions components.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ var components = {
"keep-markup": {
"title": "Keep Markup",
"owner": "Golmote",
"after": "normalize-whitespace",
"noCSS": true
},
"command-line": {
Expand All @@ -616,6 +617,7 @@ var components = {
"normalize-whitespace": {
"title": "Normalize Whitespace",
"owner": "zeitgeist87",
"after": "unescaped-markup",
"noCSS": true
}
}
Expand Down
21 changes: 15 additions & 6 deletions download.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ for (var category in components) {
noJS: all[id].noJS || all.meta.noJS,
enabled: checked,
require: $u.type(all[id].require) === 'string' ? [all[id].require] : all[id].require,
after: $u.type(all[id].after) === 'string' ? [all[id].after] : all[id].after,
owner: all[id].owner,
files: {
minified: {
Expand Down Expand Up @@ -374,18 +375,21 @@ function delayedGenerateCode(){
timerId = setTimeout(generateCode, 500);
}

function getSortedComponentsByRequirements(components){
var sorted = [];
for (var component in components) {
sorted.push(component);
function getSortedComponents(components, requireName, sorted) {
if (!sorted) {
sorted = [];
for (var component in components) {
sorted.push(component);
}
}

var i = 0;
while (i < sorted.length) {
var id = sorted[i];
var indexOfRequirement = i;
var notNow = false;
for (var requirement in components[id].require) {
indexOfRequirement = sorted.indexOf(components[id].require[requirement]);
for (var requirement in components[id][requireName]) {
indexOfRequirement = sorted.indexOf(components[id][requireName][requirement]);
if (indexOfRequirement > i) {
notNow = true;
break;
Expand All @@ -403,6 +407,11 @@ function getSortedComponentsByRequirements(components){
return sorted;
}

function getSortedComponentsByRequirements(components){
var sorted = getSortedComponents(components, "after");
return getSortedComponents(components, "require", sorted);
}

function generateCode(){
var promises = [];
var redownload = {};
Expand Down

0 comments on commit 224b7a1

Please sign in to comment.