Almost working; rule editor doesn't save.

This commit is contained in:
Simon Brooke 2014-07-13 23:56:29 +01:00
parent 28da9555ba
commit 77cfb32bb2
7 changed files with 94 additions and 13 deletions

View file

@ -1,6 +1,7 @@
(ns mw-ui.routes.home
(:use compojure.core)
(:require [hiccup.core :refer [html]]
[mw-parser.bulk :as compiler]
[mw-ui.layout :as layout]
[mw-ui.util :as util]
[mw-ui.render-world :as world]
@ -12,6 +13,12 @@
:seconds (or (session/get :seconds) 5)
:maybe-refresh "refresh"}))
(defn world-page []
(layout/render "world.html" {:title "Watch your world grow"
:content (html (world/render-world-table))
:seconds (or (session/get :seconds) 5)
:maybe-refresh "refresh"}))
(defn about-page []
(layout/render "about.html" {:title "About MicroWorld" :content (util/md->html "/md/about.md")}))
@ -27,7 +34,27 @@
:states (list-states)
:components ["mw-engine" "mw-parser" "mw-ui"]}))
(defn rules-page
([request]
(let [rule-text (:src request)
error
(try
(do
(if rule-text
(session/put! :rules (compiler/compile-string rule-text)))
(session/put! :rule-text rule-text)
nil)
(catch Exception e (.getMessage e)))]
(layout/render "rules.html" {:title "Edit Rules"
:rule-text (or (session/get :rule-text) (slurp "resources/public/rulesets/basic.txt"))
:error error})))
([]
(rules-page nil)))
(defroutes home-routes
(GET "/" [] (home-page))
(GET "/about" [] (about-page))
(GET "/docs" [] (docs-page)))
(GET "/docs" [] (docs-page))
(GET "/world" [] (world-page))
(GET "/rules" request (rules-page request))
(POST "/rules" request (rules-page request)))