File tree 4 files changed +54
-5
lines changed
4 files changed +54
-5
lines changed Original file line number Diff line number Diff line change 1
1
html , body {
2
+ font-family : "Source Serif Pro" , serif;
3
+ font-size : 16px ;
2
4
height : 100vh ;
3
5
margin : 0 ;
4
6
}
5
7
6
8
# root {
9
+ display : flex;
10
+ flex-direction : column;
11
+ height : 100% ;
12
+ }
13
+
14
+ nav {
15
+ background-color : # fafafa ;
16
+ box-shadow : 0 1px 2px 0 # 888 ;
17
+ box-sizing : border-box;
18
+ display : flex;
19
+ padding : 0.5em ;
20
+ }
21
+
22
+ nav h1 {
23
+ font-size : 1.2em ;
24
+ font-weight : initial;
25
+ margin : 0 ;
26
+ }
27
+
28
+ nav a {
29
+ vertical-align : middle;
30
+ }
31
+
32
+ nav h1 , nav a {
33
+ padding : 0 1em ;
34
+ }
35
+
36
+ main {
7
37
box-sizing : border-box;
8
38
display : flex;
9
39
gap : 0.5em ;
10
- height : 100 vh ;
40
+ height : 100 % ;
11
41
padding : 0.5em ;
12
42
}
13
43
Original file line number Diff line number Diff line change @@ -5,6 +5,9 @@ import createRuby, { Ruby } from "./createRuby";
5
5
// Create a singleton since we don't actually want there to be multiple virtual
6
6
// machines running even if there are multiple Tree components.
7
7
let ruby : Ruby = {
8
+ format ( source ) {
9
+ return source ;
10
+ } ,
8
11
prettyPrint ( source ) {
9
12
return "Loading..." ;
10
13
}
Original file line number Diff line number Diff line change @@ -73,6 +73,15 @@ export default async function createRuby() {
73
73
` ) ;
74
74
75
75
return {
76
+ // A function that calls through to the SyntaxTree.format function to get
77
+ // the pretty-printed version of the source.
78
+ format ( source : string ) {
79
+ const rubySource = `
80
+ SyntaxTree.format(JSON.parse(${ JSON . stringify ( JSON . stringify ( source ) ) } ))
81
+ ` ;
82
+
83
+ return ruby . eval ( rubySource ) . toString ( ) ;
84
+ } ,
76
85
// A function that calls through to PP to get the pretty-printed version of
77
86
// the syntax tree.
78
87
prettyPrint ( source : string ) {
Original file line number Diff line number Diff line change @@ -18,10 +18,17 @@ const App: React.FC = () => {
18
18
19
19
return (
20
20
< >
21
- < Editor cols = { cols } value = { source } onChange = { setSource } />
22
- < Suspense fallback = { < TreeFallback cols = { cols } /> } >
23
- < Tree cols = { cols } value = { source } />
24
- </ Suspense >
21
+ < nav >
22
+ < h1 > Syntax Tree</ h1 >
23
+ < a href = "https://ruby-syntax-tree.github.io/syntax_tree" > Docs</ a >
24
+ < a href = "https://github.com/ruby-syntax-tree/syntax_tree" > Source</ a >
25
+ </ nav >
26
+ < main >
27
+ < Editor cols = { cols } value = { source } onChange = { setSource } />
28
+ < Suspense fallback = { < TreeFallback cols = { cols } /> } >
29
+ < Tree cols = { cols } value = { source } />
30
+ </ Suspense >
31
+ </ main >
25
32
</ >
26
33
) ;
27
34
} ;
You can’t perform that action at this time.
0 commit comments