Permalink
Browse files

Added tests and README

  • Loading branch information...
davglass committed Dec 16, 2008
1 parent e1b5f3e commit 4b309a0472ac02e1a6a4ff1fc3f3b33f0ba678dd
Showing with 66 additions and 0 deletions.
  1. +13 −0 README
  2. +34 −0 index.php
  3. +19 −0 tests/post-source.html
View
13 README
@@ -0,0 +1,13 @@
+This project is a JSON webservice for running JSLint via PHP.
+
+
+Libraries used:
+
+ Mozilla Rhino:
+ http://www.mozilla.org/rhino/
+ https://developer.mozilla.org/en/Rhino_License
+
+
+ JSLint:
+ Copyright 2002 Douglas Crockford
+ http://jslint.com/
View
@@ -0,0 +1,34 @@
+<?php
+
+$str = '';
+$java = `which java`;
+$dir = realpath('./');
+$jslint = $dir.'/lib/jslint/jslint-console.js';
+$rhino = $dir.'/lib/rhino/js.jar';
+
+
+$json = new stdclass();
+
+if ($_POST['source']) {
+ $str = $_POST['source'];
+ $tempName = tempnam(sys_get_temp_dir(), 'jslint-');
+ file_put_contents($tempName, stripslashes($str));
+ chmod($tempName, 0755);
+}
+
+
+if ($tempName) {
+ $cmd = $java.' -jar '.escapeshellarg($rhino).' '.escapeshellarg($jslint).' '.escapeshellarg($tempName);
+ echo($cmd);
+ $out = exec($cmd, $data);
+
+ echo('<pre>'.print_r($out, 1).'</pre>');
+ echo('<pre>'.print_r($data, 1).'</pre>');
+} else {
+ $json->error = new stdclass();
+ $json->error->message = 'No javascript to lint.';
+}
+
+
+echo(json_encode($json));
+?>
View
@@ -0,0 +1,19 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>JSON Web Service Test</title>
+</head>
+<body>
+<h2>Posting Source</h2>
+
+<form method="post" action="../index.php">
+<textarea name="source" rows="10" cols="50">
+var arr = new Array('1', '2', '3',);
+</textarea>
+<br><input type="submit" name="go" value="jslint this code">
+</form>
+
+</body>
+</html>
+

0 comments on commit 4b309a0

Please sign in to comment.