Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 96daa41

Browse files
committed
Better styling and a nav
1 parent f4f85af commit 96daa41

File tree

4 files changed

+54
-5
lines changed

4 files changed

+54
-5
lines changed

docs/index.css

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,43 @@
11
html, body {
2+
font-family: "Source Serif Pro", serif;
3+
font-size: 16px;
24
height: 100vh;
35
margin: 0;
46
}
57

68
#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 {
737
box-sizing: border-box;
838
display: flex;
939
gap: 0.5em;
10-
height: 100vh;
40+
height: 100%;
1141
padding: 0.5em;
1242
}
1343

src/Tree.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import createRuby, { Ruby } from "./createRuby";
55
// Create a singleton since we don't actually want there to be multiple virtual
66
// machines running even if there are multiple Tree components.
77
let ruby: Ruby = {
8+
format(source) {
9+
return source;
10+
},
811
prettyPrint(source) {
912
return "Loading...";
1013
}

src/createRuby.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ export default async function createRuby() {
7373
`);
7474

7575
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+
},
7685
// A function that calls through to PP to get the pretty-printed version of
7786
// the syntax tree.
7887
prettyPrint(source: string) {

src/index.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,17 @@ const App: React.FC = () => {
1818

1919
return (
2020
<>
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>
2532
</>
2633
);
2734
};

0 commit comments

Comments
 (0)