Skip to content

Commit f06e1a4

Browse files
committed
add template example project
1 parent b5c3f27 commit f06e1a4

File tree

11 files changed

+94
-0
lines changed

11 files changed

+94
-0
lines changed

core.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ function decode_result() {
133133

134134
function component() {
135135
local REQUEST_PATH
136+
local REQUEST_METHOD
136137
REQUEST_PATH="$1"
138+
REQUEST_METHOD="GET"
137139
route_script=`matchRoute "$REQUEST_PATH"`
138140
INTERNAL_REQUEST=true
139141
result=$(source "pages/${route_script}")

examples/template/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
data/
2+
pubsub/
3+
uploads/

examples/template/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM ubuntu
2+
3+
RUN apt-get update && apt-get install ucspi-tcp
4+
5+
EXPOSE 3000
6+
7+
COPY . /app
8+
9+
CMD [ "/app/start.sh" ]

examples/template/config.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PROJECT_NAME="Counter"

examples/template/core.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../core.sh

examples/template/pages/count.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
if [[ ! -f data/count ]]; then
3+
echo "0" > data/count
4+
fi
5+
6+
COUNT=$(cat data/count)
7+
8+
if [[ "$REQUEST_METHOD" == "POST" ]]; then
9+
# increment the count
10+
COUNT=$(( COUNT + 1 ))
11+
echo "$COUNT" > data/count
12+
fi
13+
14+
htmx_page << EOF
15+
<p id="count" hx-swap-oob="true">$COUNT</p>
16+
EOF

examples/template/pages/index.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
source config.sh
3+
4+
htmx_page << EOF
5+
<h1>${PROJECT_NAME}</h1>
6+
<button hx-post="/count" hx-swap="none">Count</button>
7+
<button hx-post="/reset" hx-swap="none">Reset</button>
8+
$(component '/count')
9+
EOF

examples/template/pages/reset.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
if [[ "$REQUEST_METHOD" != "POST" ]]; then
2+
# only allow POST to this endpoint
3+
return $(status_code 405)
4+
fi
5+
6+
echo "0" > data/count
7+
8+
component '/count'

examples/template/pages/upload.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# allow-uploads
2+
3+
echo "<pre>"
4+
printf "%s\n" "${FILE_UPLOADS[@]@K}"
5+
printf "%s\n" "${FILE_UPLOAD_NAMES[@]@K}"
6+
printf "%s\n" "${FILE_UPLOAD_TYPES[@]@K}"
7+
echo "</pre>"

examples/template/start.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../start.sh

examples/template/static/style.css

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
body {
2+
padding: 0 40px;
3+
}
4+
#signature {
5+
position: absolute;
6+
z-index: 100;
7+
right: 20px;
8+
top: 20px;
9+
display: flex;
10+
align-items: center;
11+
justify-content: center;
12+
}
13+
14+
#signature a {
15+
text-decoration: none;
16+
}
17+
18+
#signature a:hover {
19+
text-decoration: underline;
20+
}
21+
22+
#signature svg {
23+
width: 36px;
24+
height: 36px;
25+
margin-top: -4px;
26+
vertical-align: middle;
27+
}
28+
29+
#form {
30+
display: flex;
31+
max-width: 400px;
32+
flex-direction: column;
33+
}
34+
35+
#count {
36+
font-size: 24px;
37+
}

0 commit comments

Comments
 (0)