Skip to content

Commit

Permalink
Added tests and README
Browse files Browse the repository at this point in the history
  • Loading branch information
davglass committed Dec 16, 2008
1 parent e1b5f3e commit 4b309a0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
13 changes: 13 additions & 0 deletions 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/
34 changes: 34 additions & 0 deletions index.php
@@ -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));
?>
19 changes: 19 additions & 0 deletions tests/post-source.html
@@ -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.