diff options
author | Linus Lee <linus@thesephist.com> | 2020-09-24 06:42:23 -0400 |
---|---|---|
committer | Linus Lee <linus@thesephist.com> | 2020-09-24 06:42:23 -0400 |
commit | cee091893a2d9d9aad26959dab095e71bc43b895 (patch) | |
tree | 6cc0aeb50f2a4edfbce80bdba048da89ce21f7ba /static/js/main.js | |
parent | aafa74e7bce6e47052c58a663ac3f2013649711e (diff) | |
download | tabloid-fake-closure-cee091893a2d9d9aad26959dab095e71bc43b895.tar.gz tabloid-fake-closure-cee091893a2d9d9aad26959dab095e71bc43b895.zip |
Nail down basic app styles / layout
Diffstat (limited to 'static/js/main.js')
-rw-r--r-- | static/js/main.js | 73 |
1 files changed, 60 insertions, 13 deletions
diff --git a/static/js/main.js b/static/js/main.js index b6aa634..3815538 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -1,5 +1,4 @@ -const PROG_DEFAULT = ` -DISCOVER HOW TO factorial WITH n +const PROG_DEFAULT = `DISCOVER HOW TO factorial WITH n WE SAID WHAT IF n IS ACTUALLY 0 WE SAID @@ -16,6 +15,18 @@ YOU WON'T WANT TO MISS result PLEASE LIKE AND SUBSCRIBE`; +const HEADLINES = [ + `You Won't Believe What This Programming Language Can Do!`, + `The Best Programming Language You Haven't Heard Of (It Will Surprise You!)`, + `Shocking New Programming Language Bewilders Programmers at Google and Facebook!`, + `Programmer Who Made Everything Now Predicts the Next Big Language!`, + `The Secret Programming Language Every 10x Programmer Recommends!`, +]; + +function randomHeadline() { + return HEADLINES[~~(Math.random() * HEADLINES.length)]; +} + const { Component, } = window.Torus; @@ -28,6 +39,10 @@ class Editor extends Component { this.errors = ''; this.handleRun = () => this.eval(); + this.handleReset = () => { + this.prog = PROG_DEFAULT; + this.render(); + } this.handleInput = evt => { this.prog = evt.target.value; this.render(); @@ -35,12 +50,13 @@ class Editor extends Component { } eval() { this.output = ''; + this.errors = ''; try { const tokens = tokenize(this.prog); const nodes = new Parser(tokens).parse(); const env = new Environment({ print: s => { - this.output += s.toString(); + this.output += s.toString() + '\n'; this.render(); }, }); @@ -53,23 +69,31 @@ class Editor extends Component { compose() { return jdom`<div class="editor fixed block"> <div class="controls"> + ${this.prog === PROG_DEFAULT ? null : + jdom`<button class="block" + onclick=${this.handleReset}>Reset</button>`} <button class="accent block" onclick=${this.handleRun}>Run!</button> </div> <div class="code"> - <textarea cols="30" rows="10" + <div class="filler"> + ${this.prog.split('\n') + .map(line => jdom`<p>${line.trim() ? line : '-'}</p>`)} + </div> + <textarea class="editor-input" cols="30" rows="10" value=${this.prog} oninput=${this.handleInput}> </textarea> </div> - <div class="result"> - <div class="output"> - ${this.output.split('\n').map(line => jdom`<code>${line}</code>`)} - </div> - <div class="errors"> - ${this.errors.split('\n').map(line => jdom`<code>${line}</code>`)} - </div> + <div class="output"> + ${this.output ? this.output + .split('\n') + .map(line => jdom`<code class="output-line">${line}</code>`) + : jdom`<code class="no-output">No output.</code>`} </div> + ${this.errors ? jdom`<div class="errors"> + ${this.errors.split('\n').map(line => jdom`<code>${line}</code>`)} + </div>` : null} </div>`; } } @@ -80,9 +104,32 @@ class App extends Component { } compose() { return jdom`<main> - <h1>Tabloid</h1> - <p class="subtitle">The Clickbait Headline Programming Language</p> + <header> + <h1>${randomHeadline()}</h1> + <nav> + <a href="https://github.com/thesephist/tabloid" + target="_blank" noopener noreferer>GitHub</a> + <a href="https://dotink.co/posts/tabloid/" + target="_blank" noopener noreferer>Blog post</a> + </nav> + <p class="subtitle"> + <strong class="lang fixed inline block">Tabloid:</strong> The Clickbait Headline Programming Language + </p> + </header> ${this.editor.node} + <h2>What?</h2> + <h2>But why?</h2> + <h2>Does it actually work?</h2> + <footer> + <p> + Tabloid is a project by + <a href="https://thesephist.com/">@thesephist</a>, + website built with + <a href="https://github.com/thesephist/torus">Torus</a> + and + <a href="https://thesephist.github.io/blocks.css/">blocks.css</a>. + </p> + </footer> </main>`; } } |