File tree Expand file tree Collapse file tree 5 files changed +45
-6
lines changed Expand file tree Collapse file tree 5 files changed +45
-6
lines changed Original file line number Diff line number Diff line change @@ -4,4 +4,4 @@ source "https://rubygems.org"
44
55gem "js" , "~> 2.5" unless ENV [ "JS" ] == "false"
66gem "ruby_wasm" , "~> 2.5"
7- gem "ruby-next" , "~> 1.0"
7+ gem "ruby-next" , "~> 1.0.3 "
Original file line number Diff line number Diff line change 55 diff-lcs (1.5.1 )
66 js (2.5.0 )
77 paco (0.2.3 )
8- parser (3.3.0.5 )
8+ parser (3.3.1.0 )
99 ast (~> 2.4.1 )
1010 racc
1111 racc (1.7.3 )
1212 require-hooks (0.2.2 )
13- ruby-next (1.0.2 )
13+ ruby-next (1.0.3 )
1414 paco (~> 0.2 )
1515 require-hooks (~> 0.2 )
16- ruby-next-core (= 1.0.2 )
16+ ruby-next-core (= 1.0.3 )
1717 ruby-next-parser (>= 3.2.2.0 )
1818 unparser (~> 0.6.0 )
19- ruby-next-core (1.0.2 )
19+ ruby-next-core (1.0.3 )
2020 ruby-next-parser (3.2.2.0 )
2121 parser (>= 3.0.3.1 )
2222 ruby_wasm (2.5.0 )
@@ -35,7 +35,7 @@ PLATFORMS
3535
3636DEPENDENCIES
3737 js (~> 2.5 )
38- ruby-next (~> 1.0 )
38+ ruby-next (~> 1.0.3 )
3939 ruby_wasm (~> 2.5 )
4040
4141BUNDLED WITH
Original file line number Diff line number Diff line change @@ -103,6 +103,22 @@ export default class App {
103103 this . showEditor ( "outputEditor" ) ;
104104 } ) ;
105105
106+ this . autorunCb = document . getElementById ( "autorun" ) ;
107+ let refreshDebounceId ;
108+
109+ this . codeEditor . onDidChangeModelContent ( ( ev ) => {
110+ if ( ! this . autorunCb . checked ) return ;
111+
112+ if ( refreshDebounceId ) {
113+ clearTimeout ( refreshDebounceId ) ;
114+ }
115+
116+ refreshDebounceId = setTimeout ( ( ) => {
117+ this . refresh ( ) ;
118+ refreshDebounceId = undefined ;
119+ } , 500 ) ;
120+ } ) ;
121+
106122 this . el . addEventListener ( "change" , this . onSelectEditor ) ;
107123
108124 this . versionSelect = document . getElementById ( "versionSelect" ) ;
@@ -197,6 +213,23 @@ export default class App {
197213 this . loadExampleFromUrl ( ) ;
198214 }
199215
216+ refresh ( ) {
217+ let newSource ;
218+ try {
219+ newSource = this . transpile ( this . codeEditor . getValue ( ) , { raise : true } ) ;
220+ } catch ( e ) {
221+ return ;
222+ }
223+
224+ this . previewEditor . setValue ( newSource ) ;
225+
226+ let { result, output } = this . executeWithOutput ( newSource ) ;
227+
228+ if ( result ) output += "\n\n> " + result ;
229+
230+ this . outputEditor . setValue ( output ) ;
231+ }
232+
200233 transpile ( code , opts = { } ) {
201234 let rubyOptions = "{" ;
202235
@@ -218,6 +251,10 @@ export default class App {
218251
219252 return result ;
220253 } catch ( e ) {
254+ if ( opts . raise ) {
255+ throw e ;
256+ }
257+
221258 console . error ( e ) ;
222259 return e . message ;
223260 }
Original file line number Diff line number Diff line change @@ -72,6 +72,7 @@ <h1 class="text-2xl">Playground</h1>
7272 < span > Run</ span >
7373 </ span >
7474 </ sl-button >
75+ < sl-checkbox id ="autorun "> Auto</ sl-checkbox >
7576 </ div >
7677 < div class ="flex flex-row space-x-2 justify-center items-center px-2 mr-4 ">
7778 < a href ="https://github.com/ruby-next/ruby-next " target ="_blank " class ="flex flex-row items-center space-x-1 hover:opacity-75 cursor-pointer ">
Original file line number Diff line number Diff line change @@ -8,3 +8,4 @@ import "@shoelace-style/shoelace/dist/components/dialog/dialog.js";
88import "@shoelace-style/shoelace/dist/components/icon/icon.js" ;
99import "@shoelace-style/shoelace/dist/components/button/button.js" ;
1010import "@shoelace-style/shoelace/dist/components/input/input.js" ;
11+ import "@shoelace-style/shoelace/dist/components/checkbox/checkbox.js" ;
You can’t perform that action at this time.
0 commit comments