Permalink
Browse files

Add alloy.

  • Loading branch information...
1 parent b421c71 commit 41a9de1784a12c90169846e7751d00a8655c114a Josh Roesslein committed Nov 23, 2010
Showing with 113 additions and 0 deletions.
  1. +9 −0 tools/alloy/Resources/index.html
  2. +14 −0 tools/alloy/manifest
  3. +81 −0 tools/alloy/modules/alloy/alloymodule.js
  4. +9 −0 tools/alloy/tiapp.xml
@@ -0,0 +1,9 @@
+<html>
+
+ <head>
+ </head>
+
+ <body>
+ </body>
+
+</html>
View
@@ -0,0 +1,14 @@
+#appname:Alloy
+#version:1.0
+#appid:com.titaniumapp.alloy
+#publisher:Appcelerator
+#image:default_app_logo.png
+#url:http://titaniumapp.com
+#guid:be69fe4c-966b-483c-b57c-7ba4a34fbf10
+#desc:Alloy shell
+runtime:
+python:
+ruby:
+alloy:
+tiapp:
+#php:
@@ -0,0 +1,81 @@
+(function(){
+ Titanium.API.setLogLevel(Titanium.API.ERROR);
+
+ var stdout = Titanium.App.stdout;
+ var stdin = Titanium.App.stdin;
+
+ String.prototype.rtrim=function(){return this.replace(/\s+$/,'');}
+ String.prototype.endsWith = function endsWith(pattern)
+ {
+ var d = this.length - pattern.length;
+ return d >= 0 && this.lastIndexOf(pattern) === d;
+ }
+
+ stdout("~~~~~Alloy~~~~~");
+ stdout("Type /<language name> to switch languages");
+ stdout("Supported languages: javascript, python, ruby");
+ stdout("For multi-line blocks of code, use a \\ to continue on a newline");
+ stdout("Type /exit to quit");
+ stdout("");
+
+ var langEvals = {
+ javascript: function(mimeType, scriptName, code, globals)
+ {
+ try
+ {
+ eval(code);
+ }
+ catch(e)
+ {
+ stdout("Javascript error: " + e);
+ }
+ },
+ python: Titanium.Python.evaluate,
+ ruby: Titanium.Ruby.evaluate,
+ };
+
+ var activeEval = langEvals["javascript"];
+ var activeMime = "text/javascript";
+ var command = "";
+ while (true)
+ {
+ command += stdin(">>> ").rtrim();
+ if (command == "/exit")
+ {
+ break;
+ }
+ else if (command.charAt(0) == '/')
+ {
+ // Switch languages
+ var lang = command.substr(1).toLowerCase();
+ var langEval = langEvals[lang];
+ if (langEval != undefined)
+ {
+ activeMime = "text/" + lang;
+ activeEval = langEvals[lang];
+ }
+ else
+ {
+ stdout("Invalid language: " + lang);
+ }
+ }
+ else if (command.endsWith("\\"))
+ {
+ // multi-line code
+ command = command.substring(0, command.length - 1) + "\n";
+ continue;
+ }
+ else
+ {
+ // evalute it as code
+ var result = activeEval(activeMime, "alloy", command, this);
+ if (result != undefined)
+ {
+ stdout(result);
+ }
+ }
+ command = "";
+ }
+
+ Titanium.App.exit();
+})();
View
@@ -0,0 +1,9 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<ti:app xmlns:ti='http://ti.appcelerator.org'>
+<id>com.titaniumapp.alloy</id>
+<name>Alloy</name>
+<version>1.0</version>
+<publisher>Appcelerator</publisher>
+<url>titaniumapp.com</url>
+<copyright>2009 by Appcelerator</copyright>
+</ti:app>

0 comments on commit 41a9de1

Please sign in to comment.