Skip to content

Commit

Permalink
Boilerplate commit
Browse files Browse the repository at this point in the history
- Add backend and frontend code boilerplate for r/place
  • Loading branch information
kapilreddy committed Sep 22, 2024
0 parents commit 4406e4e
Show file tree
Hide file tree
Showing 12 changed files with 1,484 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*~
14 changes: 14 additions & 0 deletions r_place_backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/target
/classes
/checkouts
/resources/js/*
profiles.clj
pom.xml
pom.xml.asc
*.jar
*.class
/.lein-*
/.nrepl-port
/.prepl-port
.hgignore
.hg/
9 changes: 9 additions & 0 deletions r_place_backend/project.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(defproject r_place_backend "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
:url "https://www.eclipse.org/legal/epl-2.0/"}
:dependencies [[org.clojure/clojure "1.11.1"]
[compojure "1.7.1"]
[http-kit "2.8.0"]]
:repl-options {:init-ns r-place-backend.core})
73 changes: 73 additions & 0 deletions r_place_backend/resources/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background-color: #f0f0f0;
}

.container {
max-width: 100%;
padding: 20px;
box-sizing: border-box;
}

h1 {
margin: 0;
color: #333;
}

.header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
}

.tools {
display: flex;
gap: 5px;
}

button, input[type="color"] {
padding: 5px 10px;
font-size: 14px;
cursor: pointer;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 3px;
}

input[type="color"] {
height: 30px;
width: 30px;
padding: 0;
}

.canvas-container {
overflow: auto;
max-width: 100%;
max-height: 80vh;
border: 1px solid #ccc;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

#paintCanvas {
background-color: white;
}

@media (max-width: 768px) {
.header {
flex-direction: column;
align-items: flex-start;
}

.tools {
margin-top: 10px;
justify-content: flex-start;
}
}
27 changes: 27 additions & 0 deletions r_place_backend/resources/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>(r/place)</title>

<link href="static/css/output.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="header">
<h1>(r/place)</h1>
<div class="tools">
<button id="brush">Brush</button>
<button id="eraser">Eraser</button>
<input type="color" id="colorPicker" value="#000000">
<button id="demo">Demo</button>
</div>
</div>
<div class="canvas-container">
<canvas id="paintCanvas"></canvas>
</div>
</div>
<script src="static/js/main.js"></script>
</body>
</html>
38 changes: 38 additions & 0 deletions r_place_backend/src/r_place_backend/core.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(ns r-place-backend.core
(:require [org.httpkit.server :as http-kit]
[ring.util.response :refer [resource-response]]
[compojure.route :refer [files not-found]]
[compojure.core :refer [defroutes GET POST DELETE ANY context]]))

(defn chat-handler [req]
(http-kit/with-channel req channel ; get the channel
;; communicate with client using method defined above
(http-kit/on-close channel (fn [status]
(println "channel closed")))
(if (http-kit/websocket? channel)
(println "WebSocket channel")
(println "HTTP channel"))
(http-kit/on-receive channel (fn [data] ; data received from client
;; An optional param can pass to send!: close-after-send?
;; When unspecified, `close-after-send?` defaults to true for HTTP channels
;; and false for WebSocket. (send! channel data close-after-send?)
(http-kit/send! channel data))))) ; data is sent directly to the client

(defn show-landing-page [req] ;; ordinary clojure function, accepts a request map, returns a response map
;; return landing page's html string. Using template library is a good idea:
;; mustache (https://github.com/shenfeng/mustache.clj, https://github.com/fhd/clostache...)
;; enlive (https://github.com/cgrand/enlive)
;; hiccup(https://github.com/weavejester/hiccup)
(resource-response "templates/index.html"))


(defroutes all-routes
(GET "/" [] show-landing-page)

(GET "/ws" [] chat-handler) ;; websocket
(files "/static/" {:root "resources"}) ;; static file url prefix /static, in `public` folder
(not-found "<p>Page not found.</p>")) ;; all other, return 404


(defn -main []
(http-kit/run-server all-routes {:port 8080}))
7 changes: 7 additions & 0 deletions r_place_backend/test/r_place_backend/core_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(ns r-place-backend.core-test
(:require [clojure.test :refer :all]
[r-place-backend.core :refer :all]))

(deftest a-test
(testing "FIXME, I fail."
(is (= 0 1))))
21 changes: 21 additions & 0 deletions r_place_ui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
node_modules/
public/js

/target
/checkouts
/src/gen

pom.xml
pom.xml.asc
*.iml
*.jar
*.log
.shadow-cljs
.idea
.lein-*
.nrepl-*
.DS_Store

.hgignore
.hg/
out/*
Loading

0 comments on commit 4406e4e

Please sign in to comment.