Skip to content

Commit e3e37d8

Browse files
committed
up
1 parent 26eb6fa commit e3e37d8

File tree

1 file changed

+47
-5
lines changed

1 file changed

+47
-5
lines changed

index.html

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
<!--stylesheets-->
1717
<link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css" >
1818
<link rel="stylesheet" type="text/css" href="/css/bootstrap-responsive.min.css">
19-
<link rel="stylesheet" type="text/css" href="/css/style.css?v=3">
19+
<link rel="stylesheet" type="text/css" href="/css/style.css?v=4">
20+
<link rel="stylesheet" type="text/css" href="https://cdn.rawgit.com/josdejong/jsoneditor/master/dist/jsoneditor.min.css">
2021
<!--[if lt IE 9]>
2122
<link rel="stylesheet" type="text/css" href="css/ie.css" />
2223
<![endif]-->
@@ -103,7 +104,7 @@ <h1>Quick start</h1>
103104
<div class="text">
104105
<p>
105106
Install the package from npm :
106-
<code data-gist-id="6f26ca36ca0896ad2b7bc182dd8c6c760"></code>
107+
<code data-gist-id="6f26ca36ca0896ad2b7bc182dd8c6c76"></code>
107108
</p>
108109
<p>
109110
And next use it on your own project :
@@ -127,16 +128,27 @@ <h1>Try it online</h1>
127128
Write your PHP code
128129
</div>
129130
<p>
130-
@todo
131+
<div id="editor">&lt;?php
132+
/**
133+
* Some namespace &amp; file description
134+
*/
135+
namespace foo {
136+
function bar($a, $b) {
137+
return $a + $b;
138+
}
139+
// will print : 5
140+
echo bar(2, 3);
141+
}</div>
131142
</p>
132143
</div>
133144
<div class="span6 supportright">
134145
<div class="supporttitle">
135146
Resulting AST
136147
</div>
137148
<p>
138-
@todo
139-
</p>
149+
<div id="jsoneditor" style="width: 100%; height: 400px;"></div>
150+
<div id="error-msg" class="alert alert-danger hidden"></div>
151+
</p>
140152
</div>
141153
</div>
142154
</div>
@@ -154,5 +166,35 @@ <h1>Try it online</h1>
154166
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
155167
<script type="text/javascript" src="/js/main.js?v=1"></script>
156168
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/gist-embed/2.4/gist-embed.min.js"></script>
169+
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.6/ace.js"></script>
170+
<script type="text/javascript" src="https://rawgit.com/glayzzle/php-parser/master/dist/php-parser.min.js"></script>
171+
<script type="text/javascript" src="https://cdn.rawgit.com/josdejong/jsoneditor/master/dist/jsoneditor-minimalist.min.js"></script>
172+
<script>
173+
var parser = require('php-parser');
174+
var editor = ace.edit("editor");
175+
var container = document.getElementById("jsoneditor");
176+
var options = {
177+
mode: 'view'
178+
};
179+
var json = new JSONEditor(container, options);
180+
editor.setTheme("ace/theme/monokai");
181+
editor.getSession().setMode("ace/mode/php");
182+
function refreshAst() {
183+
try {
184+
var ast = parser.parseCode(
185+
editor.getValue()
186+
);
187+
$('#error-msg').hide();
188+
$(container).show();
189+
json.set(ast);
190+
} catch(e) {
191+
$('#error-msg').show();
192+
$(container).hide();
193+
$('#error-msg').text(e.message);
194+
}
195+
}
196+
editor.on("change", refreshAst);
197+
refreshAst();
198+
</script>
157199
</body>
158200
</html>

0 commit comments

Comments
 (0)