Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ config/
node_modules/
npm-debug.log
/coverage/
*.map
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "public/dev"]
path = public/dev
url = https://github.com/adobe/brackets-site-sass
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,59 @@ __Note:__ If you discovered any issue with the extension registry or have an ide

5. `npm start`

## Developing CSS
While the js, and html can be modified right in the repository, the sass stylesheets for brackets-registry exist in another repository - [brackets-site-sass](https://github.com/adobe/brackets-site-sass), and are included in as a submodule.

This is because the same style sheets are shared by [brackets.io](https://github.com/adobe/brackets.io) as well.

Refer to the section below for assistance on how to develop the css for brackets-registry

- Requirements
- Git command line tools — follow the setup instructions on [GitHub](https://help.github.com/articles/set-up-git) or download [here](http://git-scm.com/downloads)
- [NodeJS installed](https://nodejs.org/en/download/releases/). Tested with node v6.3.1 & npm v5.5.1
- Steps to follow
- Open gitbash (or any other command line shell of your choice, that supports git & node) & clone the repository

```bash
git clone https://github.com/adobe/brackets-registry.git
cd brackets-registry
```

- Update the brackets-site-sass submodule

```bash
git submodule update --init
```

- Change directory to the brackets-site-sass submodule

```bash
cd public/dev
```

- Get the development dependencies for the submodule

```bash
npm install
```

The brackets-site-sass folder contains the scss folder, which contains the sass files that were used to develop the minified css(brackets.min.css). Any modification that needs to be made to the minified css must be made by compiling these scss files.

- And then run the auto-compile grunt task

```bash
grunt watch
```

The above task will watch the _scss_ folder for any changes. Post this, you can modify the files in the scss folder and _brackets.min.css_ will be automatically generated in the css folder.

**Note:** You must keep the grunt task running for the automatic compilation to work, so don't close the
shell running the task.

**Note:** Also, test the new styles with brackets.io as well, and update the minified css there as well.

**Note:** Chrome generally caches resources, and so sometimes, even on reloading, code changes are not reflected. In such a case, use the [Empty Cache and Hard Reload](http://www.thewindowsclub.com/empty-cache-hard-reload-chrome) option in Chrome.

## Debugging REPL

There's an optional REPL available. To set it up:
Expand Down
8 changes: 8 additions & 0 deletions lib/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "lib",
"version": "1.0.0",
"description": "Server Side code for brackets-registry",
"dependencies": {
"numeral": "^2.0.6"
}
}
204 changes: 203 additions & 1 deletion lib/registry_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

"use strict";

var numeral = require("numeral");

// From Brackets StringUtils
function htmlEscape(str) {
return String(str)
Expand Down Expand Up @@ -84,7 +86,7 @@ exports.formatUserId = function () {
* Assumes "this" is the current template context.
* @return {string} A link to that user's page on the service.
*/
exports.ownerLink = function () {
exports.ownerLink = function ownerLink () {
var url;
if (this.user && this.user.owner) {
var nameComponents = this.user.owner.split(":");
Expand All @@ -95,6 +97,35 @@ exports.ownerLink = function () {
return url;
};

/**
* Returns the src url for an owner's git Avatar.
* @returns {string} The url for an owners Git Avatar.
*/
exports.gitAvatar = function gitAvatar () {
var avatar = "img/registry/github-grey.svg";
if (this.owner) {
var nameComponents = this.owner.split(":");
if (nameComponents[0] === "github") {
avatar = "https://github.com/" + nameComponents[1] + ".png?size=50";
}
}
return avatar;
};


/**
* Given a registry item, fetches and formats the total Downloads
* @returns {string} Formatted total Downloads
*/
exports.totalDownloads = function () {
var retval = parseInt(this.totalDownloads);
retval = isNaN(retval) ? 0 : retval;
if (retval > 999) {
retval = numeral(retval).format('0.0a');
}
return retval;
};

/**
* Given a registry item, formats the author information, including a link to the owner's
* github page (if available) and the author's name from the metadata.
Expand Down Expand Up @@ -161,3 +192,174 @@ exports.sortRegistry = function (registry, subkey) {

return sortedEntries;
};

/**
* Returns an array of 4 registry entries, sorted by the total downloads from the begining of time.
* @param {object} registry The unsorted registry.
* @param {string} subkey The subkey to look for the registry metadata in. If unspecified, assumes
* we should look at the top level of the object.
* @return {Array} Sorted array of registry entries.
*/
exports.getMostDownloaded = function (registry, subkey) {
var sortedEntries = [];

// Sort the registry by most downloads (highest first).
Object.keys(registry).forEach(function (key) {
sortedEntries.push(registry[key]);
});
sortedEntries.sort(function (entry1, entry2) {
var e1 = parseInt(entry1.totalDownloads),
e2 = parseInt(entry2.totalDownloads);

e1 = isNaN(e1) ? 0 : e1;
e2 = isNaN(e2) ? 0 : e2;

return e2 - e1;
});

return sortedEntries.slice(0,4);
};


/**
* Returns an array of 4 current registry entries, sorted by the publish date of the latest version of each entry.
* @param {object} registry The unsorted registry.
* @param {string} subkey The subkey to look for the registry metadata in. If unspecified, assumes
* we should look at the top level of the object.
* @return {Array} Sorted array of registry entries.
*/
exports.getRecentlyUpdated = function (registry, subkey) {
function getPublishTime(entry) {
if (entry.versions) {
return new Date(entry.versions[entry.versions.length - 1].published).getTime();
}

return Number.NEGATIVE_INFINITY;
}

var sortedEntries = [];

// Sort the registry by last published date (newest first).
Object.keys(registry).forEach(function (key) {
sortedEntries.push(registry[key]);
});
sortedEntries.sort(function (entry1, entry2) {
return getPublishTime((subkey && entry2[subkey]) || entry2) -
getPublishTime((subkey && entry1[subkey]) || entry1);
});

return sortedEntries.slice(0,4);
};

/**
* Returns an array of 4 most recently created registry entries.
* @param {object} registry The unsorted registry.
* @param {string} subkey The subkey to look for the registry metadata in. If unspecified, assumes
* we should look at the top level of the object.
* @return {Array} Sorted array of registry entries.
*/
exports.getRecentlyCreated = function (registry, subkey) {
function getPublishTime(entry) {
if (entry.versions) {
return new Date(entry.versions[0].published).getTime();
}

return Number.NEGATIVE_INFINITY;
}

var sortedEntries = [];

// Sort the registry by last published date (newest first).
Object.keys(registry).forEach(function (key) {
sortedEntries.push(registry[key]);
});
sortedEntries.sort(function (entry1, entry2) {
return getPublishTime((subkey && entry2[subkey]) || entry2) -
getPublishTime((subkey && entry1[subkey]) || entry1);
});

return sortedEntries.slice(0,4);
};

/**
* Returns an array of 4 registry entries, sorted by the recent week downloads (highest first).
* @param {object} registry The unsorted registry.
* @param {string} subkey The subkey to look for the registry metadata in. If unspecified, assumes
* we should look at the top level of the object.
* @return {Array} Sorted array of registry entries.
*/
exports.getTrending = function (registry, subkey) {

function getWeeklyDownloads(entry) {
var downloads = 0;
if (entry.recent) {
Object.keys(entry.recent).forEach(function (key) {
downloads = downloads + parseInt(entry.recent[key]);
});
}
return downloads;
}

var sortedEntries = [];

// Sort the registry by most downloads (highest first).
Object.keys(registry).forEach(function (key) {
sortedEntries.push(registry[key]);
});
sortedEntries.sort(function (entry1, entry2) {
return getWeeklyDownloads(entry2) -
getWeeklyDownloads(entry1);
});

return sortedEntries.slice(0,4);
};

/**
* Returns a filtered registry list.
* @param {object} registry The unsorted registry.
* @param {object} filterKey:filterValue pairs to look for the registry metadata in.
* @return {Array} Filtered array of registry entries.
*/
exports.getFilteredList = function (registry, filters) {
var config = {};
var filterEntries = decodeURIComponent(filters['q'] || "").split(/\s/).every(function(entry) {
var pair = entry.split(":");
var decodedStringVal;
if (pair.length === 1) {
config["name"] = pair[0];
config["title"] = pair[0];
config["keywords"] = pair[0];
config["owner"] = pair[0];
} else {
config[pair[0]] = pair[1];
}
});
var sortedEntries = [],
filteredEntries = [];

// Sort the registry by most downloads (highest first).
Object.keys(registry).forEach(function (key) {
sortedEntries.push(registry[key]);
});
sortedEntries.sort(function (entry1, entry2) {
return entry2.totalDownloads -
entry1.totalDownloads;
});

sortedEntries.every(function(registryEntry) {
var matched = false;
Object.keys(config).every(function(filterkey) {
if (registryEntry.metadata[filterkey] && registryEntry.metadata[filterkey].indexOf(config[filterkey]) !== -1) {
matched = true;
}
});
if (matched) {
filteredEntries.push(registryEntry);
}
return true;
});

return filteredEntries;
};


Loading