Skip to content
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 by Bors] - Improve example page #350

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
29 changes: 19 additions & 10 deletions generate-wasm-examples/generate_wasm_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ sed -i.bak 's/asset_folder: "assets"/asset_folder: "\/assets\/examples\/"/' crat
add_category()
{
category=$1
category_path=`echo $category | tr '[:upper:]' '[:lower:]'`
category_path=$2
example_weight=0

mkdir ../../content/examples/$category_path

shift
# Remove first two arguments
shift 2

# Generate a markdown file for each example
# These represent each example page
for example in $@
do
echo "building $category / $example"
Expand All @@ -43,6 +47,7 @@ header_message = \"Examples\"
example_weight=$((example_weight+1))
done

# Generate category index
echo "+++
title = \"$category\"
sort_by = \"weight\"
Expand All @@ -66,11 +71,15 @@ header_message = \"Examples\"

category_weight=0

add_category 2d rect sprite sprite_flipping sprite_sheet text2d mesh2d mesh2d_manual
add_category 3d 3d_scene lighting load_gltf orthographic parenting pbr spherical_area_lights texture update_gltf_scene
add_category UI button text text_debug ui
add_category audio audio
add_category shader shader_instancing shader_material_glsl shader_material
add_category ecs iter_combinations
add_category Games breakout alien_cake_addict
add_category stress_tests bevymark
# Add categories
# - first param: the label that will show on the website
# - second param: `bevy/examples/???` folder name
# - rest params: space separated list of example files within the folder that want to be used
add_category 2D 2d rect sprite sprite_flipping sprite_sheet text2d mesh2d mesh2d_manual
add_category 3D 3d 3d_scene lighting load_gltf orthographic parenting pbr spherical_area_lights texture update_gltf_scene
add_category UI ui button text text_debug ui
add_category Audio audio audio
add_category Shader shader shader_instancing shader_material_glsl shader_material
add_category ECS ecs iter_combinations
add_category Games games breakout alien_cake_addict
add_category "Stress Tests" stress_tests bevymark
56 changes: 56 additions & 0 deletions sass/components/_example.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
.example {
padding: 0 16px;

&__header {
display: grid;
gap: 8px;
margin: 16px 0 8px;
align-items: baseline;
grid-template-columns: 1fr 1fr;
grid-template-areas:
'title title'
'back github'
;

@media #{$bp-tablet-portrait-up} {
margin: 24px 0 8px;
grid-template-areas: 'back title github';
grid-template-columns: 150px 1fr 150px;
}
}

&__title {
grid-area: title;
margin: 0;
font-size: 1.75rem;
text-align: center;
}

&__back,
&__github {
font-size: 1rem;

@include override-anchor {
color: #aaa;
}

&:hover {
color: $color-white;
}
}

&__back {
grid-area: back;
}

&__github {
grid-area: github;
text-align: right;
}

&__canvas {
width: 100% !important;
height: auto !important;
border-radius: $border-radius;
}
}
2 changes: 2 additions & 0 deletions sass/components/_icon.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

display: inline-block;
background-color: currentColor;
vertical-align: text-bottom;
-webkit-mask-repeat: no-repeat;
mask-repeat: no-repeat;
-webkit-mask-size: contain;
Expand All @@ -15,6 +16,7 @@
('chevron-down', 15),
('chevron-left', 9),
('chevron-right', 9),
('github', 24),
('pencil', 19),
('times', 16),
);
Expand Down
1 change: 1 addition & 0 deletions sass/site.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@import "components/book-footer";
@import "components/book-nav";
@import "components/card";
@import "components/example";
@import "components/headerbar";
@import "components/icon";
@import "components/sponsors";
Expand Down
10 changes: 10 additions & 0 deletions static/assets/icon-github.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 14 additions & 14 deletions templates/example.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{% extends "layouts/base.html" %}

{% block content %}
<div class="book-content">
<div class="media-content">
<script type="module">
import init from './{{ page.title }}.js';
init()
</script>
<div><a href="/examples">Back to examples</a></div>
<canvas id="bevy" width="1024" height="720"></canvas>
<div>
{{ page.components[1] }} / {{ page.title }} -
<a href="https://github.com/bevyengine/bevy/blob/latest/examples/{{ page.components[1] }}/{{ page.title }}.rs">
See this example in Bevy github repo
</a>
</div>
<div class="example">
<div class="example__header">
<h2 class="example__title">{{ page.components[1] }} / {{ page.title }}</h2>
<a class="example__back" href="/examples"><i class="icon icon--chevron-left"></i> Back to examples</a>
<a class="example__github" href="https://github.com/bevyengine/bevy/blob/latest/examples/{{ page.components[1] }}/{{ page.title }}.rs">
<i class="icon icon--github"></i> View in GitHub
</a>
</div>
<canvas class="example__canvas" id="bevy"></canvas>
<div class="example__code media-content">
{% set code = load_data(path="content/examples/" ~ page.components[1] ~ "/" ~ page.title ~ "/" ~ page.title ~ ".rs") %}
{% set data = "```rust
" ~ code ~ "```" %}

{{data | markdown(inline=true) | safe}}
</div>
</div>
<script type="module">
import init from './{{ page.title }}.js';
init();
</script>
{% endblock content %}