diff --git a/env/dev/clj/user.clj b/env/dev/clj/user.clj index 549a7fd..29a777d 100644 --- a/env/dev/clj/user.clj +++ b/env/dev/clj/user.clj @@ -15,4 +15,7 @@ (stop) (start)) +(defn start-with-server [] + (start) + (mount/start #'yenu.core/http-server)) diff --git a/project.clj b/project.clj index 6f03ac9..6990ea9 100644 --- a/project.clj +++ b/project.clj @@ -1,7 +1,6 @@ (defproject yenu "0.1.0-SNAPSHOT" - :description "yenu -- The image sharing tool for friends" - :url "http://example.com/FIXME" + :url "https://aaron-fischer.net/" :dependencies [[bouncer "1.0.0"] [cljs-ajax "0.5.8"] @@ -11,7 +10,6 @@ [luminus-immutant "0.2.3"] [luminus-migrations "0.2.9"] [luminus-nrepl "0.1.4"] - [markdown-clj "0.9.94"] [metosin/ring-http-response "0.8.1"] [mount "0.1.11"] [org.clojure/clojure "1.8.0"] diff --git a/resources/public/css/screen.css b/resources/public/css/screen.css index 0b6a61c..26b3d46 100644 --- a/resources/public/css/screen.css +++ b/resources/public/css/screen.css @@ -1,4 +1,9 @@ -html, body { - font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; - height: 100%; - padding-top: 40px; } +#images { + margin: auto; +} + +.thumbnail-image { + margin: 2px; + padding: 1px; + border: 1px solid #ddd; +} diff --git a/resources/templates/admin/upload.html b/resources/templates/admin/upload.html new file mode 100644 index 0000000..c414f85 --- /dev/null +++ b/resources/templates/admin/upload.html @@ -0,0 +1,37 @@ +{% extends "layout.html" %} + +{% block content %} +

Upload a new image

+

Here you can upload a new image to the gallery. This image is then saved in + three different formats. The raw image, a scaled down version and a scoped + thumbnail image for the overview. You can upload all sorts of images.

+ +
+ {% csrf-field %} + +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + +
+{% endblock %} diff --git a/resources/templates/error.html b/resources/templates/error.html index 6fcd237..ff17577 100644 --- a/resources/templates/error.html +++ b/resources/templates/error.html @@ -1,56 +1,12 @@ - - - - Something bad happened - - - {% style "/assets/bootstrap/css/bootstrap.min.css" %} - {% style "/assets/bootstrap/css/bootstrap-theme.min.css" %} - - - -
-
-
-
-
-

Error: {{status}}

-
- {% if title %} -

{{title}}

- {% endif %} - {% if message %} -

{{message}}

- {% endif %} -
-
-
-
-
- - +{% extends "layout.html" %} + +{% block content %} +

Error: {{status}}

+
+{% if title %} +

{{title}}

+{% endif %} +{% if message %} +

{{message}}

+{% endif %} +{% endblock %} diff --git a/resources/templates/home.html b/resources/templates/home.html deleted file mode 100644 index 33d8d3e..0000000 --- a/resources/templates/home.html +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - Welcome to yenu - - - -
-
-
-
-

Welcome to yenu

-

If you're seeing this message, that means you haven't yet compiled your ClojureScript!

-

Please run lein figwheel to start the ClojureScript compiler and reload the page.

-

For better ClojureScript development experience in Chrome follow these steps:

-
    -
  • Open DevTools -
  • Go to Settings ("three dots" icon in the upper right corner of DevTools > Menu > Settings F1 > General > Console) -
  • Check-in "Enable custom formatters" -
  • Close DevTools -
  • Open DevTools -
-

See ClojureScript documentation for further details.

-
-
-
-
- - - {% style "/assets/bootstrap/css/bootstrap.min.css" %} - {% style "/assets/font-awesome/css/font-awesome.min.css" %} - {% style "/css/screen.css" %} - - - {% script "/js/app.js" %} - - - - - - diff --git a/resources/templates/index.html b/resources/templates/index.html new file mode 100644 index 0000000..cf6176d --- /dev/null +++ b/resources/templates/index.html @@ -0,0 +1,16 @@ +{% extends "layout.html" %} + +{% block content %} +
+ {% for image in images %} +
+ + {{ image.title }} +

{{ image.title }} + +

+ {% endfor %} +
+
+{% endblock %} + diff --git a/resources/templates/layout.html b/resources/templates/layout.html new file mode 100644 index 0000000..88114fc --- /dev/null +++ b/resources/templates/layout.html @@ -0,0 +1,34 @@ + + + + + + yenu -- the image sharing tool for friends + + +
+

yenu

+ Images, + Upload a new image +
+ + {% block content %} + {% endblock %} +
+ + + +
+ + {% style "/assets/bootstrap/css/bootstrap.min.css" %} + {% style "/assets/font-awesome/css/font-awesome.min.css" %} + {% style "/css/screen.css" %} + + + {% script "/js/app.js" %} + + + diff --git a/resources/templates/upload.html b/resources/templates/upload.html deleted file mode 100644 index f783c58..0000000 --- a/resources/templates/upload.html +++ /dev/null @@ -1,9 +0,0 @@ -

Upload image

-
- {% csrf-field %} - - - - - -
diff --git a/src/clj/yenu/handler.clj b/src/clj/yenu/handler.clj index 3bcd99b..6b30711 100644 --- a/src/clj/yenu/handler.clj +++ b/src/clj/yenu/handler.clj @@ -1,7 +1,8 @@ (ns yenu.handler (:require [compojure.core :refer [routes wrap-routes]] [yenu.layout :refer [error-page]] - [yenu.routes.home :refer [home-routes upload-routes]] + [yenu.routes.core :refer [core-routes]] + [yenu.routes.admin :refer [admin-routes]] [compojure.route :as route] [yenu.env :refer [defaults]] [mount.core :as mount] @@ -13,10 +14,10 @@ (def app-routes (routes - (-> #'home-routes + (-> #'core-routes (wrap-routes middleware/wrap-csrf) (wrap-routes middleware/wrap-formats)) - (-> #'upload-routes + (-> #'admin-routes (wrap-routes middleware/wrap-csrf) (wrap-routes middleware/wrap-formats)) (route/not-found diff --git a/src/clj/yenu/helpers/images.clj b/src/clj/yenu/helpers/images.clj index 59b02bb..912b529 100644 --- a/src/clj/yenu/helpers/images.clj +++ b/src/clj/yenu/helpers/images.clj @@ -54,7 +54,8 @@ (defn scale-image-and-save [filepath] (let [image-hash (target-image-filename filepath) file-extension (fs/extension filepath) - new-file-name (str image-hash file-extension)] + new-raw-file-name (str image-hash file-extension) + new-file-name (str image-hash ".png")] (fs/copy filepath (data-path "gallery" "raw" new-file-name)) (save scale-normal [1024 768] filepath (data-path "gallery" "normal" new-file-name)) (save scale-thumbnail [250] filepath (data-path "gallery" "thumbnails" new-file-name)) diff --git a/src/clj/yenu/layout.clj b/src/clj/yenu/layout.clj index 4dc0d7e..457e3b1 100644 --- a/src/clj/yenu/layout.clj +++ b/src/clj/yenu/layout.clj @@ -1,28 +1,26 @@ (ns yenu.layout (:require [selmer.parser :as parser] - [selmer.filters :as filters] - [markdown.core :refer [md-to-html-string]] [ring.util.http-response :refer [content-type ok]] [ring.util.anti-forgery :refer [anti-forgery-field]] + [yenu.helpers.images :as image-helper] [ring.middleware.anti-forgery :refer [*anti-forgery-token*]])) (declare ^:dynamic *app-context*) (parser/set-resource-path! (clojure.java.io/resource "templates")) (parser/add-tag! :csrf-field (fn [_ _] (anti-forgery-field))) -(filters/add-filter! :markdown (fn [content] [:safe (md-to-html-string content)])) (defn render "renders the HTML template located relative to resources/templates" [template & [params]] (content-type - (ok - (parser/render-file - template - (assoc params - :page template - :csrf-token *anti-forgery-token* - :servlet-context *app-context*))) - "text/html; charset=utf-8")) + (ok + (parser/render-file + template + (assoc params + :page template + :csrf-token *anti-forgery-token* + :servlet-context *app-context*))) + "text/html; charset=utf-8")) (defn error-page "error-details should be a map containing the following keys: diff --git a/src/clj/yenu/routes/home.clj b/src/clj/yenu/routes/admin.clj similarity index 77% rename from src/clj/yenu/routes/home.clj rename to src/clj/yenu/routes/admin.clj index d0b812c..8e0b3e8 100644 --- a/src/clj/yenu/routes/home.clj +++ b/src/clj/yenu/routes/admin.clj @@ -1,4 +1,4 @@ -(ns yenu.routes.home +(ns yenu.routes.admin (:require [yenu.layout :as layout] [compojure.core :refer [defroutes GET POST]] [ring.util.http-response :as response] @@ -28,25 +28,17 @@ (let [{tag-id :id} (db/get-tag {:tagname tag})] (db/add-tag-to-image! {:imageid image-id :tagid tag-id}))) -(defn add-to-database [filehash title description tags] +(defn add-image-to-database [filehash title description tags] (let [img (db/create-image! {:hash filehash :title title :description description}) image-id ((keyword "last_insert_rowid()") img) all-tags (str/split tags, #"(\s*,\s*|\s+)")] (map #(add-tag image-id %) all-tags))) -(defroutes upload-routes +(defroutes admin-routes (GET "/upload" [] - (layout/render "upload.html")) + (layout/render "admin/upload.html")) (POST "/upload" [file title description tags] (-> (upload-file file) (images/process-image) - (add-to-database title description tags)) + (add-image-to-database title description tags)) (redirect "/"))) - -(defroutes home-routes - (GET "/" [] - (layout/render "home.html")) - (GET "/docs" [] - (-> (response/ok (-> "docs/docs.md" io/resource slurp)) - (response/header "Content-Type" "text/plain; charset=utf-8")))) - diff --git a/src/clj/yenu/routes/core.clj b/src/clj/yenu/routes/core.clj new file mode 100644 index 0000000..d6fa7c4 --- /dev/null +++ b/src/clj/yenu/routes/core.clj @@ -0,0 +1,27 @@ +(ns yenu.routes.core + (:require [yenu.layout :as layout] + [compojure.core :refer [defroutes GET POST]] + [ring.util.http-response :as response] + [ring.util.response :refer [redirect file-response]] + [yenu.helpers.images :as images] + [yenu.db.core :as db])) + +(defn index-page [] + (layout/render "index.html" + {:images (db/get-all-images {:offset 0 :count 10})})) + +(defn image-file [type hash ext] + (let [filename (str hash "." ext)] + (file-response (images/data-path "gallery" type filename)))) + +(defroutes core-routes + (GET "/" [] + (index-page)) + (GET ["/images/:type/:hash.:ext" + ;;:type #"(normal|raw|thumbnails)" + ;;:hash #"[0-9]+-[^.]+" + ;;:ext #"(png|jpg)" + ] + [type hash ext] + (image-file type hash ext))) + diff --git a/src/cljs/yenu/core.cljs b/src/cljs/yenu/core.cljs index 295194c..841bfc7 100644 --- a/src/cljs/yenu/core.cljs +++ b/src/cljs/yenu/core.cljs @@ -4,7 +4,6 @@ [secretary.core :as secretary :include-macros true] [goog.events :as events] [goog.history.EventType :as HistoryEventType] - [markdown.core :refer [md->html]] [yenu.ajax :refer [load-interceptors!]] [ajax.core :refer [GET POST]]) (:import goog.History)) @@ -40,7 +39,7 @@ (when-let [docs (session/get :docs)] [:div.row>div.col-sm-12 [:div {:dangerouslySetInnerHTML - {:__html (md->html docs)}}]])]) + {:__html "test"}}]])]) (def pages {:home #'home-page @@ -80,7 +79,8 @@ (r/render [#'page] (.getElementById js/document "app"))) (defn init! [] - (load-interceptors!) - (fetch-docs!) - (hook-browser-navigation!) - (mount-components)) + ;; (load-interceptors!) + ;; (fetch-docs!) + ;; (hook-browser-navigation!) + ;; (mount-components) + )