Skip to content

Commit

Permalink
Localization of metadata blocks
Browse files Browse the repository at this point in the history
Second attempt... needed the other boogs fixed first plus found one and missed UI metas

* Use *pegjs* synchronously... I do have a portion of the routine for asynchronous *(done first)* but *(sync)* seems safer in the event of a production failure
* Establish the `OpenUserJS` metadata block and migrate all collaboration there
* Store localized `@name` and `@description`... not currently in use but available
* Some, but not all, line lengths in affected files wrapped according to STYLEGUIDE.md
* If no script description don't create the `p` tag on script lists
* Some stray trailing commas removed
* Some string constants shortened for error messages.. type 400 is Bad Request by standards and we shouldn't need to say that again.
* Some DOC/UI changes to match

**NOTE**: Still needs *mongoose* DB migration otherwise all the meta values used don't show up

* Bumping project version... e.g. once the *mongoose* *(DB data)* migration occurs there is no going back to a prior project version otherwise there will be possible DB corruption/failures *(most notably the meta.js route)* in older commit HEADS

Applies to OpenUserJS#285
  • Loading branch information
Martii committed Aug 24, 2015
1 parent 861ba18 commit ad08b6f
Show file tree
Hide file tree
Showing 10 changed files with 305 additions and 281 deletions.
103 changes: 40 additions & 63 deletions controllers/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ var getScriptPageTasks = function (aOptions) {
var authedUser = aOptions.authedUser;

// Intermediates
var homepagesURL = null;
var copyrights = null;
var licenses = null;
var collaborators = null;
var homepageURL = null;
var copyright = null;
var license = null;
var author = null;
var collaborator = null;

// Temporaries
var htmlStub = null;
Expand Down Expand Up @@ -93,79 +94,55 @@ var getScriptPageTasks = function (aOptions) {
});

// Show homepages of the script
homepagesURL = scriptStorage.findMeta(script.meta, 'homepageURL');
if (homepagesURL) {
if (typeof homepagesURL === 'string') {
htmlStub = '<a href="' + homepagesURL + '"></a>';
homepageURL = scriptStorage.findMeta(script.meta, 'UserScript.homepageURL');
if (homepageURL) {
aOptions.script.homepages = [];
homepageURL.forEach(function (aElement, aIndex, aArray) {
htmlStub = '<a href="' + aElement.value + '"></a>';
if (htmlStub === sanitizeHtml(htmlStub, htmlWhitelistLink)) {
aOptions.script.homepages = [{
url: homepagesURL,
text: decodeURI(homepagesURL),
aOptions.script.homepages.unshift({
url: aElement.value,
text: decodeURI(aElement.value),
hasNoFollow: !/^(?:https?:\/\/)?openuserjs\.org\//i.
test(homepagesURL)
}];
test(aElement.value)
});
}
} else {
aOptions.script.homepages = [];
homepagesURL.forEach(function (aHomepage) {
htmlStub = '<a href="' + aHomepage + '"></a>';
if (htmlStub === sanitizeHtml(htmlStub, htmlWhitelistLink)) {
aOptions.script.homepages.unshift({
url: aHomepage,
text: decodeURI(aHomepage),
hasNoFollow: !/^(?:https?:\/\/)?openuserjs\.org/i.test(aHomepage)
});
}
});
}
});
}

// Show copyrights of the script
copyrights = scriptStorage.findMeta(script.meta, 'copyright');
if (copyrights) {
if (typeof copyrights === 'string') {
aOptions.script.copyrights = [{ name: copyrights }];
} else {
aOptions.script.copyrights = [];
copyrights.forEach(function (aCopyright) {
aOptions.script.copyrights.unshift({ name: aCopyright });
});
}
copyright = scriptStorage.findMeta(script.meta, 'UserScript.copyright');
if (copyright) {
aOptions.script.copyrights = [];
copyright.forEach(function (aElement, aIndex, aArray) {
aOptions.script.copyrights.unshift({ name: aElement.value });
});
}

// Show licensings of the script
licenses = scriptStorage.findMeta(script.meta, 'license');
if (licenses) {
if (typeof licenses === 'string') {
aOptions.script.licenses = [{ name: licenses }];
} else {
aOptions.script.licenses = [];
licenses.forEach(function (aLicense) {
aOptions.script.licenses.unshift({ name: aLicense });
});
}
license = scriptStorage.findMeta(script.meta, 'UserScript.license');
if (license) {
aOptions.script.licenses = [];
license.forEach(function (aElement, aIndex, aArray) {
aOptions.script.licenses.unshift({ name: aElement.value });
});
} else if (!script.isLib) {
aOptions.script.licenses = [{ name: 'MIT License (Expat)' }];
}

// Show collaborators of the script

collaborators = scriptStorage.findMeta(script.meta, 'oujs.collaborator');
if (scriptStorage.findMeta(script.meta, 'oujs.author') && collaborators) {

author = scriptStorage.findMeta(script.meta, 'OpenUserJS.author.0.value');
collaborator = scriptStorage.findMeta(script.meta, 'OpenUserJS.collaborator');
if (author && collaborator) {
aOptions.hasCollab = true;
if (typeof collaborators === 'string') {
aOptions.script.collaborators = [{
url: encodeURIComponent(collaborators),
text: collaborators }];
} else {
aOptions.script.collaborators = [];
collaborators.forEach(function (aCollaborator) {
aOptions.script.collaborators.unshift({
url: encodeURIComponent(aCollaborator),
text: aCollaborator });

aOptions.script.collaborators = [];
collaborator.forEach(function (aElement, aIndex, aArray) {
aOptions.script.collaborators.unshift({
url: encodeURIComponent(aElement.value),
text: aElement.value
});
}
});
}

// Show which libraries hosted on the site a script uses
Expand Down Expand Up @@ -339,7 +316,7 @@ exports.view = function (aReq, aRes, aNext) {
function preRender() {
if (script.groups) {
pageMetadata(options, ['About', script.name, (script.isLib ? 'Libraries' : 'Scripts')],
scriptStorage.findMeta(script.meta, 'description'), _.pluck(script.groups, 'name'));
script.description, _.pluck(script.groups, 'name'));
}
}
function render() { aRes.render('pages/scriptPage', options); }
Expand Down Expand Up @@ -368,7 +345,7 @@ exports.view = function (aReq, aRes, aNext) {

// Page metadata
pageMetadata(options, ['About', script.name, (script.isLib ? 'Libraries' : 'Scripts')],
scriptStorage.findMeta(script.meta, 'description'));
script.description);
options.isScriptPage = true;

// SearchBar
Expand Down
Loading

0 comments on commit ad08b6f

Please sign in to comment.