16
16
<!--stylesheets-->
17
17
< link rel ="stylesheet " type ="text/css " href ="/css/bootstrap.min.css " >
18
18
< 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 ">
20
21
<!--[if lt IE 9]>
21
22
<link rel="stylesheet" type="text/css" href="css/ie.css" />
22
23
<![endif]-->
@@ -103,7 +104,7 @@ <h1>Quick start</h1>
103
104
< div class ="text ">
104
105
< p >
105
106
Install the package from npm :
106
- < code data-gist-id ="6f26ca36ca0896ad2b7bc182dd8c6c760 "> </ code >
107
+ < code data-gist-id ="6f26ca36ca0896ad2b7bc182dd8c6c76 "> </ code >
107
108
</ p >
108
109
< p >
109
110
And next use it on your own project :
@@ -127,16 +128,27 @@ <h1>Try it online</h1>
127
128
Write your PHP code
128
129
</ div >
129
130
< p >
130
- @todo
131
+ < div id ="editor "> <?php
132
+ /**
133
+ * Some namespace & 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 >
131
142
</ p >
132
143
</ div >
133
144
< div class ="span6 supportright ">
134
145
< div class ="supporttitle ">
135
146
Resulting AST
136
147
</ div >
137
148
< 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 >
140
152
</ div >
141
153
</ div >
142
154
</ div >
@@ -154,5 +166,35 @@ <h1>Try it online</h1>
154
166
< script type ="text/javascript " src ="/js/bootstrap.min.js "> </ script >
155
167
< script type ="text/javascript " src ="/js/main.js?v=1 "> </ script >
156
168
< 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 >
157
199
</ body >
158
200
</ html >
0 commit comments