Skip to content

Instantly share code, notes, and snippets.

@paulp
Created July 26, 2009 15:43
Show Gist options
  • Save paulp/155814 to your computer and use it in GitHub Desktop.
Save paulp/155814 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<head>
<title>Scala Ubiquity Commands</title>
</head>
<body>
<p>This xhtml source contains commands for executing scala code.
Its corresponding feed is <a href="sscala.html">here</a>.</p>
<script src="fake-infrastructure.js"></script>
<script class="commands"><![CDATA[
function replaceAll(text, strA, strB)
{
while ( text.indexOf(strA) != -1)
{
text = text.replace(strA,strB);
}
return text;
}
function getProcessedSelection() {
// getSelection() strips the newlines, so we have to drill down.
var selRaw = context.focusedWindow.getSelection();
var selRange = selRaw.getRangeAt(0);
var sel = replaceAll(selRange.toString(), "\n", " ; ");
return sel;
}
CmdUtils.CreateCommand({
names: [ "sscala" ],
description: "Execute the selected scala code on simply scala",
preview: function(pblock, { object }) {
pblock.innerHTML = _("Execute code block <pre>" + getProcessedSelection() + "</pre> on simplyscala.");
},
execute: function(args) {
var code = "{ " + encodeURIComponent(getProcessedSelection()) + " }";
var url = "http://www.simplyscala.com/interp?code=" + code;
jQuery.get(url, [], function(data) {
displayMessage(data);
}, "text");
}
})
]]></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment