Skip to content

Instantly share code, notes, and snippets.

@ljsc
Created September 12, 2008 13:55
Show Gist options
  • Save ljsc/10442 to your computer and use it in GitHub Desktop.
Save ljsc/10442 to your computer and use it in GitHub Desktop.
CmdUtils.CreateCommand({
name: "github",
description: "Searchs Github for a code repository",
icon: "http://github.com/favicon.ico",
author: { name: "Louis J. Scoras", email: "lou@ljstech.net"},
license: "MPL,GPL",
takes: { "search string": noun_arb_text },
templates: {
preview_header: function(q) {
var template = "Github search results for <em>${query}:</em>";
return CmdUtils.renderTemplate(template, {query: q});
},
result_line: function(repo) {
var resultTemplate = "<p><strong>${name}</strong> &mdash; ${description}</p>";
return CmdUtils.renderTemplate(resultTemplate, {
name: repo.name,
description: repo.description
});
}
},
preview: function(pblock, query) {
var url = "http://github.com/api/v1/json/search/" + query.text;
var templates = this.templates;
var header = templates.preview_header(query.text);
CmdUtils.loadJQuery(function($) {
$.getJSON(url, function(data) {
var repos = data.repositories.splice(0,10);
var results = "";
$.each(repos, function(i, repo) {
results += templates.result_line(repo);
});
$(pblock).html(header).append(results);
});
});
},
execute: function(query, mods) {
var urlTemplate = "http://github.com/search?q=${query}";
var urlString = CmdUtils.renderTemplate(urlTemplate, {query: query.text });
Utils.openUrlInBrowser(urlString);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment