-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Update yew-router examples, make them easier to run #1401
Closed
philip-peterson
wants to merge
13
commits into
yewstack:master
from
philip-peterson:peterson/update-examples
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1c2bcb2
Update readmes, make the examples easier to run
philip-peterson f5b3f51
update readmes
philip-peterson 394f421
newline
philip-peterson bf987ff
Update yew-router/examples/README.md
philip-peterson 0058eb4
Update yew-router/examples/README.md
philip-peterson ab6964d
Update yew-router/examples/README.md
philip-peterson f937b0d
Update README.md
philip-peterson 3cbfb0a
Update yew-router/examples/README.md
philip-peterson 01e12af
Update yew-router/examples/minimal/run.sh
philip-peterson 452e49e
Update README.md
philip-peterson 2fdb136
Update start_example_server.py
philip-peterson ae3c87e
update minimal run.sh
philip-peterson 75ebe9e
make requires more consistent
philip-peterson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
../run_example.sh minimal "a/lorem" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Router Component Example | ||
Run with `cargo web start`. | ||
Run with `./run.sh`. | ||
|
||
Shows how to use the `Router` component. | ||
This is the preferred way of how to use this library. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
INITIAL_URL='a' | ||
|
||
../run_example.sh router_component "$INITIAL_URL" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
# The example to build. | ||
EXAMPLE="${1%\/}" | ||
|
||
# The page to start on. | ||
INITIAL_URL="${2%\/}" | ||
|
||
# Path to this script's parent dir | ||
BASEDIR="$(dirname "$0")" | ||
|
||
cd "$BASEDIR/$1" | ||
( | ||
wasm-pack build \ | ||
--dev \ | ||
--target web \ | ||
--out-dir ../_static/ \ | ||
--out-name wasm \ | ||
. \ | ||
&& cd ../_static \ | ||
&& python3 ../start_example_server.py "$INITIAL_URL" | ||
) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env python3 | ||
from http.server import BaseHTTPRequestHandler, HTTPServer | ||
|
||
import os | ||
import sys | ||
import logging | ||
import webbrowser | ||
|
||
PORT=8080 | ||
STATIC_RESOURCES = { "/wasm.js", "/wasm_bg.wasm", "/favicon.ico" } | ||
|
||
class S(BaseHTTPRequestHandler): | ||
def _set_response(self, code, mime='text/html; charset=utf-8'): | ||
self.send_response(code) | ||
self.send_header('Content-type', mime) | ||
self.send_header('Cache-Control', 'private, max-age=0, must-revalidate') | ||
self.end_headers() | ||
|
||
def do_GET(self): | ||
if self.path in STATIC_RESOURCES: | ||
resolved_path = "." + self.path | ||
if os.path.isfile(resolved_path): | ||
with open(resolved_path, "rb") as f: | ||
mime='text/html; charset=utf-8' | ||
if resolved_path.endswith('.wasm'): | ||
mime = 'application/wasm' | ||
elif resolved_path.endswith('.js'): | ||
mime = 'text/javascript' | ||
self._set_response(200, mime) | ||
self.wfile.write(f.read()) | ||
else: | ||
self._set_response(404) | ||
self.wfile.write(b"404 file not found") | ||
else: | ||
self._set_response(200) | ||
with open("index.html", "rb") as f: | ||
self.wfile.write(f.read()) | ||
|
||
def run(server_class=HTTPServer, handler_class=S, initial_url=''): | ||
logging.basicConfig(level=logging.INFO) | ||
server_address = ('', PORT) | ||
httpd = server_class(server_address, handler_class) | ||
webbrowser.open(f"http://localhost:{PORT}/{initial_url}") | ||
logging.info('Starting web server...\n') | ||
try: | ||
httpd.serve_forever() | ||
except KeyboardInterrupt: | ||
pass | ||
httpd.server_close() | ||
logging.info('Stopping web server...\n') | ||
|
||
if __name__ == '__main__': | ||
from sys import argv | ||
|
||
run(initial_url=sys.argv[1] if len(sys.argv) > 1 else '') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ authors = ["Henry Zimmerman <[email protected]>"] | |
edition = "2018" | ||
|
||
[dependencies] | ||
yew-router = { path = "../..", default-features = false, features = ["web_sys"] } | ||
yew-router = { path = "../..", features = ["web_sys"], default-features = false } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reason I renamed this is to make it stand out;
static
when it's sorted alphabetically with the rest of the examples, looks like it's the name of an example.