Show the generated image on the HMTL esult page

This commit is contained in:
Aaron Fischer 2015-12-06 12:31:42 +01:00
parent d96250b444
commit 0786d3492a
2 changed files with 16 additions and 6 deletions

View file

@ -3,7 +3,12 @@
{% block content %}
<div class="row">
<div class="span12">
{{ mailheader }}
<h1>Results</h1>
<img src="/image/{{ token }}">
<h2>The analyzed email</h2>
<pre>{{ mailheader }}</pre>
</div>
</div>
{% endblock %}

View file

@ -2,7 +2,7 @@
(:require [mailhead.layout :as layout]
[mailhead.visualize :as v]
[compojure.core :refer [defroutes GET POST]]
[ring.util.http-response :refer [ok]]
[ring.util.http-response :refer [ok content-type]]
[clojure.java.io :as io]))
(defn home-page []
@ -13,13 +13,18 @@
(defn analyze-mailheader [mailheader]
(let [token (v/draw mailheader)]
;; TODO: Generate token
;; TODO: Generate image
;; TODO: Show image and other data on result.html
(layout/render "result.html" {:mailheader mailheader})))
(layout/render "result.html"
{:mailheader mailheader
:token token})))
(defn generated-image [token]
(-> (clojure.java.io/input-stream (str "generated-images/" token ".svg"))
ok
(content-type "image/svg+xml")))
(defroutes home-routes
(GET "/" [] (home-page))
(GET "/image/:token" [token] (generated-image token))
(POST "/analyze" [mailheader] (analyze-mailheader mailheader))
(GET "/about" [] (about-page)))