Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Port brackets changes to registry_utils #73

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions lib/brackets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2016 - present Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/

/**
* Since registry_utils is in Brackets too it can end up using
* Brackets features not available here.
* Here we mimick the function exposed by the brackets global variable.
*/

"use strict";

exports.getLocale = function () {
return "en";
};
46 changes: 30 additions & 16 deletions lib/registry_utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
* Copyright (c) 2013 - present Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -29,11 +29,26 @@
* In the future, we should have a better mechanism for sharing code between the two.
*/

/*jslint vars: true, plusplus: true, node: true, nomen: true, indent: 4, maxerr: 50 */
/*global define*/

"use strict";

var brackets = require("./brackets");

// For Brackets-Registry we deliberately want to use YYYY-MM-DD format for the date.
// For Brackets remove it and use instead Date normally.
function FakeDate(date) {
var d = new Date(date);
function lpad(num) {
var s = String("") + num;
if (s.length === 1) {
return "0" + s;
}
return s;
}
this.toLocaleDateString = function (locale, options) {
return d.getUTCFullYear() + "-" + lpad((d.getUTCMonth() + 1)) + "-" + lpad(d.getUTCDate());
};
}

// From Brackets StringUtils
function htmlEscape(str) {
return String(str)
Expand All @@ -54,11 +69,12 @@ exports.lastVersionDate = function () {
if (this.versions && this.versions.length) {
result = this.versions[this.versions.length - 1].published;
if (result) {
// Just return the ISO-formatted date, which is the portion up to the "T".
var dateEnd = result.indexOf("T");
if (dateEnd !== -1) {
result = result.substr(0, dateEnd);
}
result = new FakeDate(result);
result = result.toLocaleDateString(brackets.getLocale(), {
"year": "numeric",
"month": "2-digit",
"day": "2-digit"
});
}
}
return result || "";
Expand Down Expand Up @@ -104,14 +120,12 @@ exports.authorInfo = function () {
ownerLink = exports.ownerLink.call(this),
userId = exports.formatUserId.call(this);
if (this.metadata && this.metadata.author) {
// author can be either a string or an object with a "name" field
result += htmlEscape(this.metadata.author.name || this.metadata.author);
result = htmlEscape(this.metadata.author.name || this.metadata.author);
} else if (userId) {
result = htmlEscape(userId);
}
if (userId) {
if (result !== "") {
result += " / ";
}
result += "<a href='" + htmlEscape(ownerLink) + "'>" + htmlEscape(userId) + "</a>";
if (ownerLink) {
result = "<a href='" + htmlEscape(ownerLink) + "' title='" + htmlEscape(ownerLink) + "'>" + result + "</a>";
}
return result;
};
Expand Down