8000 Final demo improvements by coolreader18 · Pull Request #245 · RustPython/RustPython · GitHub
[go: up one dir, main page]

Skip to content

Final demo improvements #245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Dec 29, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
03c619f
Rearrange website directory and change webpack config
coolreader18 Dec 19, 2018
4c32693
Switch to using one workspace, move profile to root Cargo.toml
coolreader18 Dec 18, 2018
ca30ebc
Genericize the wasm lib to not be specifically for the demo
coolreader18 Dec 22, 2018
2ea9dca
Add example, change some stuff in the demo to align with example
coolreader18 Dec 23, 2018
d54d2b1
Make scripts executable
coolreader18 Dec 23, 2018
840c507
Improve UX for demo
coolreader18 Dec 23, 2018
ab23f2c
Use str.format for the demo
coolreader18 Dec 23, 2018
24507de
Re-add conflicting files
coolreader18 Dec 24, 2018
ffcd40b
Remove conflicting files
coolreader18 Dec 24, 2018
d1d9585
Change the instances of Fn(..) -> PyResult to a RustPyFunc trait alias
coolreader18 Dec 24, 2018
63b3f3e
Fix blanket impl of RustPyFunc
coolreader18 Dec 24, 2018
132930e
Allow passing closures from JS to python via `vars`
coolreader18 Dec 26, 2018
e0959b9
Implement error conversion for js_to_py
coolreader18 Dec 26, 2018
94d6a91
Fix js_to_py with JS `undefined`
coolreader18 Dec 26, 2018
c38796b
Add some documentation for functions on the demo site
coolreader18 Dec 26, 2018
877206d
Switch from shell to npm scripts for demo using webpack and @wasm-too…
coolreader18 Dec 27, 2018
2968982
Change README portion for compiling wasm
coolreader18 Dec 27, 2018
ada92d3
Add conflicting files
coolreader18 Dec 19, 2018
dfadd03
Remove (now outdated) previously conflicting files
coolreader18 Dec 27, 2018
396842e
Readd conflicting files
coolreader18 Dec 19, 2018
8303743
Remove RustPyFunc trait, just use Fn(..) everywhere
coolreader18 Dec 27, 2018
1f02cc0
Squash all demo commits onto one branch
coolreader18 Dec 28, 2018
4cc7f5a
Merge #console and #code styles
coolreader18 Dec 28, 2018
b277280
Add README and manifest fields for the WASM library
coolreader18 Dec 28, 2018
1d5df41
Add doc comments and typescript custom section
coolreader18 Dec 28, 2018
36997e1
Comment out WB's TS definitions using a hack
coolreader18 Dec 28, 2018
d7fdc5c
Fix typescript hack
coolreader18 Dec 28, 2018
e65639f
Remove yarn.lock
coolreader18 Dec 29, 2018
231e3f2
Export PyEvalOptions in typescript defs
coolreader18 Dec 29, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Rearrange website directory and change webpack config
  • Loading branch information
coolreader18 committed Dec 19, 2018
commit 03c619f79eeff17f84a0a1492beb7b98c0ceede1
6 changes: 0 additions & 6 deletions wasm/app/bootstrap.js

This file was deleted.

71 changes: 0 additions & 71 deletions wasm/app/index.html

This file was deleted.

25 changes: 0 additions & 25 deletions wasm/app/index.js

This file was deleted.

54 changes: 29 additions & 25 deletions wasm/app/package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"hello-wasm-pack": "^0.1.0",
"webpack": "^4.16.3",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.5",
"copy-webpack-plugin": "^4.5.2"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/RustPython/RustPython.git"
},
"author": "Ryan Liddle",
"license": "MIT",
"bugs": {
"url": "https://github.com/RustPython/RustPython/issues"
},
"homepage": "https://github.com/RustPython/RustPython#readme"
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"codemirror": "^5.42.0"
},
"devDependencies": {
"webpack": "^4.16.3",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.5",
"copy-webpack-plugin": "^4.5.2",
"mini-css-extract-plugin": "^0.5.0",
"html-webpack-plugin": "^3.2.0",
"css-loader": "^2.0.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/RustPython/RustPython.git"
},
"author": "Ryan Liddle",
"license": "MIT",
"bugs": {
"url": "https://github.com/RustPython/RustPython/issues"
},
"homepage": "https://github.com/RustPython/RustPython#readme"
}
10 changes: 10 additions & 0 deletions wasm/app/src/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import './style.css';
import 'codemirror/lib/codemirror.css';

// A dependency graph that contains any wasm must all be imported
// asynchronously. This `bootstrap.js` file does the single async import, so
// that no one else needs to worry about it again.
import('./index.js').catch(e => {
console.error('Error importing `index.js`:', e);
document.getElementById('error').textContent = e;
});
45 changes: 45 additions & 0 deletions wasm/app/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>RustPython Demo</title>
</head>
<body>
<h1>RustPython Demo</h1>
<p>
RustPython is a Python interpreter writter in Rust. This demo is
compiled from Rust to WebAssembly so it runs in the browser
</p>
<p>Please input your python code below and click <kbd>Run</kbd>:</p>
<p>
Alternatively, open up your browser's devtools and play with
<code>rp.eval_py('print("a")')</code>
</p>
<textarea id="code">
n1 = 0
n2 = 1
count = 0
until = 10

print("These are the first " + str(until) + " number in a Fibonacci sequence:")

while count < until:
print(n1)
n1, n2 = n2, n1 + n2
count += 1

</textarea>
<button id="run-btn">Run &#9655;</button>
<div id="error"></div>
<h3>Standard Output</h3>
<textarea id="console">Loading...</textarea>

<a href="https://github.com/RustPython/RustPython">
<img
style="position: absolute; top: 0; right: 0; border: 0;"
src="https://s3.amazonaws.com/github/ribbons/forkme_right_green_007200.png"
alt="Fork me on GitHub"
/>
</a>
</body>
</html>
43 changes: 43 additions & 0 deletions wasm/app/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as rp from '../../pkg';
import CodeMirror from 'codemirror';
import 'codemirror/mode/python/python';
import 'codemirror/addon/comment/comment';

// so people can play around with it
window.rp = rp;

const editor = CodeMirror.fromTextArea(document.getElementById('code'), {
extraKeys: {
'Ctrl-Enter': runCodeFromTextarea,
'Cmd-Enter': runCodeFromTextarea,
'Shift-Tab': 'indentLess',
'Ctrl-/': 'toggleComment',
'Cmd-/': 'toggleComment'
},
mode: 'text/x-python',
indentUnit: 4,
autofocus: true
});

function runCodeFromTextarea() {
const consoleElement = document.getElementById('console');
const errorElement = document.getElementById('error');

// Clean the console and errors
consoleElement.value = '';
errorElement.textContent = '';

const code = editor.getValue();
try {
rp.run_from_textbox(code);
} catch (e) {
errorElement.textContent = e;
console.error(e);
}
}

document
.getElementById('run-btn')
.addEventListener('click', runCodeFromTextarea);

runCodeFromTextarea(); // Run once for demo
31 changes: 31 additions & 0 deletions wasm/app/src/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
textarea {
font-family: monospace;
resize: none;
}

#code {
height: 35vh;
width: calc(100% - 3px);
}

.CodeMirror {
border: 1px solid #ddd;
height: 35vh !important;
}

#console {
height: 35vh;
width: calc(100% - 3px);
}

#run-btn {
width: 6em;
height: 2em;
font-size: 24px;
}

#error {
color: tomato;
margin-top: 10px;
font-family: monospace;
}
32 changes: 22 additions & 10 deletions wasm/app/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
const CopyWebpackPlugin = require("copy-webpack-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');

module.exports = {
entry: "./bootstrap.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: "bootstrap.js",
},
mode: "development",
plugins: [
new CopyWebpackPlugin(['index.html'])
],
entry: './src/bootstrap.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bootstrap.js'
},
mode: 'development',
module: {
rules: [
{ test: /\.css$/, use: [MiniCssExtractPlugin.loader, 'css-loader'] }
]
},
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'src/index.html'
}),
new MiniCssExtractPlugin({
filename: 'styles.css'
})
]
};
0