diff --git a/project.clj b/project.clj index 1006b6a..3da76e5 100644 --- a/project.clj +++ b/project.clj @@ -20,7 +20,6 @@ :init luduverse.handler/init :destroy luduverse.handler/destroy :open-browser? false} - :repl-options {:timeout 12000} :aliases {"save-competition-30" ["run" "-m" "luduverse.scraper/save-competition" "30"]} :profiles {:production {:ring {:stacktrace? false}} :dev {:ring {:auto-reload? true diff --git a/resources/public/css/main.css b/resources/public/css/main.css new file mode 100644 index 0000000..db7e01d --- /dev/null +++ b/resources/public/css/main.css @@ -0,0 +1,85 @@ +* { + margin: 0; + padding: 0; + font-family: Arial, DejaVu Sans; +} + +#logo { + margin: auto; + margin-top: 200px; + display: block; +} + +form#search { + margin: auto; + width: 600px; +} + +form#search > input, form#search-results > input { + width: 580px; + font-size: 40px; + font-weight: bold; + margin: 20px 0 10px 0; + padding: 10px; + border: 2px solid #ddd; + background-color: #fcfcfc; +} + +form#search > p { + font-size: 12px; + color: #aaa; +} + +form#search > p > strong { + background-color: #eee; + color: black; + padding: 1px 5px; + border-radius: 2px; +} + +div#results-header { + margin: 10px 0 0 15px; +} + +#logo-search-results, form#search-results { + float: left; +} +form#search-results > input { + margin: 5px 0 0 20px; +} + +#results { + margin-top: 20px; +} + +#results > div { + width: 200px; + height: 200px; + background-color: #ccc; + border: 1px solid black; + margin: 3px; + float: left; + position: relative; +} +#results > div p { + position: absolute; + left: -2; + top: 172px; + width: 196px; + height: 25px; + background-color: black; + padding: 2px; + color: white; + font-size: 9px; +} +#results > div p > span { + font-weight: bold; +} + +a { + color: red; +} + +a:hover { + color: orange; +} \ No newline at end of file diff --git a/resources/img/logo.jpg b/resources/public/images/logo.jpg similarity index 100% rename from resources/img/logo.jpg rename to resources/public/images/logo.jpg diff --git a/resources/public/images/logo_small.jpg b/resources/public/images/logo_small.jpg new file mode 100644 index 0000000..b0ee100 Binary files /dev/null and b/resources/public/images/logo_small.jpg differ diff --git a/src/luduverse/handler.clj b/src/luduverse/handler.clj index 75fb457..475c5c7 100644 --- a/src/luduverse/handler.clj +++ b/src/luduverse/handler.clj @@ -3,11 +3,21 @@ [compojure.route :as route] [noir.util.middleware :as middleware] [luduverse.pages :as pages] - [luduverse.images :as images])) + [luduverse.images :as images] + [luduverse.search :as search])) + +(defn render [template & args] + (apply str (apply template args))) (defroutes core-routes (route/resources "/") - (GET "/" [] (pages/front-page)) + (GET "/" [] (render pages/landingpage-template)) + (POST "/search" {params :params} + (let [term (params "term") + s (search/search term) + hits (:hit-count s) + entries (:results s)] + (render pages/results-template term hits entries))) (route/not-found "404, sorry.")) (defn init []) diff --git a/src/luduverse/pages.clj b/src/luduverse/pages.clj index 81a305b..529d49a 100644 --- a/src/luduverse/pages.clj +++ b/src/luduverse/pages.clj @@ -1,4 +1,16 @@ -(ns luduverse.pages) +(ns luduverse.pages + (:require [net.cgrand.enlive-html :as html])) -(defn front-page [] - "Wait for it ...") +(html/deftemplate landingpage-template "templates/landingpage.html" []) + +(html/defsnippet item-model "templates/results.html" [:div#results :> :div] + [id image-path username title] + [:img] (html/set-attr :src image-path) + [:p] (html/content username) + [:span] (html/content title)) + +(html/deftemplate results-template "templates/results.html" + [search-term hits results] + [:form#search :> :input#term] (html/set-attr :value search-term) + ;[:div#results (html/content (map #(item-model %) results))] + ) diff --git a/src/luduverse/search.clj b/src/luduverse/search.clj index f530f49..a4ba076 100644 --- a/src/luduverse/search.clj +++ b/src/luduverse/search.clj @@ -4,8 +4,6 @@ [clojurewerkz.elastisch.rest.document :as eld] [clojurewerkz.elastisch.rest.response :as elresp] [clojurewerkz.elastisch.query :as elq] - - [clojure.pprint :as pp] [luduverse.models.entry :as entry])) (def connection (atom (el/connect "http://localhost:9200"))) @@ -40,7 +38,8 @@ (store (:id e)))) (defn search [term] - (let [res (eld/search @connection "luduverse" "entry" + (let [con (el/connect "http://localhost:9200") + res (eld/search con "luduverse" "entry" :query (elq/query-string :query term) :sort {:title "desc"} :from 0 diff --git a/src/templates/landingpage.html b/src/templates/landingpage.html new file mode 100644 index 0000000..c834e86 --- /dev/null +++ b/src/templates/landingpage.html @@ -0,0 +1,26 @@ + + + + + + LuduVerse - ClojureCup 2014 by Aaron Fischer + + + + + + + + + + + + diff --git a/src/templates/results.html b/src/templates/results.html new file mode 100644 index 0000000..3f03425 --- /dev/null +++ b/src/templates/results.html @@ -0,0 +1,32 @@ + + + + + + LuduVerse results- ClojureCup 2014 by Aaron Fischer + + + + + + +
+ +
+ +
+
+
+ +
+
+ + +

This is the dungeon
+ by Aaron

+
+
+
+ + +