Skip to content

Instantly share code, notes, and snippets.

@jmcarbo
Created January 20, 2009 21:49
Show Gist options
  • Save jmcarbo/49681 to your computer and use it in GitHub Desktop.
Save jmcarbo/49681 to your computer and use it in GitHub Desktop.
CmdUtils.CreateCommand({
name: "gist-credentials",
//takes: {"login_name": noun_arb_text},
modifiers: {"login_name": noun_arb_text, "tok": noun_arb_text},
homepage: "http://www.sample.me.uk/ubiquity/",
author: { name: "Duncan Sample" },
description: "Sets the login credentials for github",
help: "service should be either 'delicious' or 'magnolia'",
license: "MPL",
preview: function( pblock ) {
var gist_cred = CmdUtils.retrieveLogins("gist-credentials");
pblock.innerHTML = CmdUtils.renderTemplate( "<strong>Current login: </strong>${login}", {login: gist_cred[0].username});
},
execute: function(tak, mods) {
CmdUtils.savePassword({name: "gist-credentials", username: mods.login_name.text, password: mods.tok.text});
displayMessage("Stored credentials for: " + mods.login_name.text);
}
});
/* gist-create-private */
CmdUtils.CreateCommand({
name: "gist-create-private",
icon: "http://gist.github.com/example.png",
homepage: "http://gist.github.com/49872",
author: { name: "Joan Marc Carbo Arnau", email: "[email protected]"},
license: "GPL",
description: "Creates a private gist at ",
help: "how to use your command",
takes: {"input": noun_arb_text},
preview: function( pblock, input ) {
var template = "Stores privately ${name} at gist.github.com";
the_matter = input.text;
pblock.innerHTML = CmdUtils.renderTemplate(template, {"name": the_matter});
},
execute: function(input) {
var gist_cred = CmdUtils.retrieveLogins("gist-credentials");
params = {
"file_ext[gistfile1]": ".txt",
"file_name[gistfile1]": "filename",
"file_contents[gistfile1]": input.text,
"private": "on",
"login": gist_cred[0].username,
"token": gist_cred[0].password
};
jQuery.post("http://gist.github.com/gists", params,
function(data){
//displayMessage("Gist " + data + "succesfully created");
} );
}
});
/* This is a template command */
CmdUtils.CreateCommand({
name: "gist_create",
icon: "http://example.com/example.png",
homepage: "http://example.com/",
author: { name: "Your Name", email: "[email protected]"},
license: "GPL",
description: "A short description of your command",
help: "how to use your command",
takes: {"input": noun_arb_text},
preview: function( pblock, input ) {
var template = "Stores ${name} at gist.github.com";
the_matter = input.text;
pblock.innerHTML = CmdUtils.renderTemplate(template, {"name": the_matter});
},
execute: function(input) {
var gist_cred = CmdUtils.retrieveLogins("gist-credentials");
params = {
"file_ext[gistfile1]": ".txt",
"file_name[gistfile1]": "filename",
"file_contents[gistfile1]": input.text,
"login": gist_cred[0].username,
"token": gist_cred[0].password
};
jQuery.post("http://gist.github.com/gists", params,
function(data){
//displayMessage("Gist " + data + "succesfully created");
} );
}
});
CmdUtils.CreateCommand(
{
name: "rspec",
takes: {"method": noun_arb_text},
icon: "http://rubyonrails.org/images/rails.png",
homepage: "",
author: {name: "Zhao Lu", email: "[email protected]"},
license: "MPL,GPL",
description: "Search rspec documentation",
help: "Type a rspec class or method",
execute: function(directObject)
{
var url = "http://apidock.com/rspec/{TERM}"
var urlString = url.replace("{TERM}", directObject.text);
Utils.openUrlInBrowser(urlString);
},
preview: function(pblock, directObject)
{
searchText = jQuery.trim(directObject.text);
if(searchText.length <= 0)
{
pblock.innerHTML = "Search rspec documentation";
return;
}
var previewTemplate = "Search rspec documentation of ${query}";
var previewData = {query: searchText};
pblock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
}
});
CmdUtils.CreateCommand(
{
name: "rails",
takes: {"method": noun_arb_text},
icon: "http://rubyonrails.org/images/rails.png",
homepage: "",
author: {name: "Zhao Lu", email: "[email protected]"},
license: "MPL,GPL",
description: "Search rails documentation",
help: "Type a rails class or method",
execute: function(directObject)
{
var url = "http://apidock.com/rails/{TERM}"
var urlString = url.replace("{TERM}", directObject.text);
Utils.openUrlInBrowser(urlString);
},
preview: function(pblock, directObject)
{
searchText = jQuery.trim(directObject.text);
if(searchText.length <= 0)
{
pblock.innerHTML = "Search rails documentation";
return;
}
var previewTemplate = "Search rails documentation of ${query}";
var previewData = {query: searchText};
pblock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
}
});
var noun_type_ruby_keyword = {
_name: "ruby keyword",
suggest: function( text, html ) {
var suggestions = [CmdUtils.makeSugg(text)];
return suggestions;
}
}
CmdUtils.CreateCommand({
name: "ruby-api",
takes: {keyword: noun_type_ruby_keyword},
icon: "http://www.ruby-doc.org/_img/favicon.ico",
description: "Searches Ruby-Doc for the keyword(s)",
preview: function(pblock, directObject) {
searchTerm = jQuery.trim(directObject.text);
var pTemplate = "Searches Ruby-Doc for ${query}";
var pData = {query: searchTerm}
pblock.innerHTML = CmdUtils.renderTemplate(pTemplate, pData);
var url = "http://ajax.googleapis.com/ajax/services/search/web";
var params = { v: "1.0", q: searchTerm };
jQuery.get(url, params, function(data) {
var numToDisplay = 3;
var results = data.responseData.results.splice( 0, numToDisplay );
pblock.innerHTML = CmdUtils.renderTemplate( {file:"google-search.html"},
{results:results}
);
}, "json");
},
execute: function(directObject) {
var url = "http://www.google.com/search?q=site%3Awww.ruby-doc.org+{QUERY}"
var query = directObject.text;
var urlString = url.replace("{QUERY}", query);
Utils.openUrlInBrowser(urlString);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment