Compare commits
2 commits
0.1.5_MAIN
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
ab03ad2106 | ||
|
cc16329196 |
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -8,14 +8,9 @@ pom.xml
|
||||||
/.lein-*
|
/.lein-*
|
||||||
/.env
|
/.env
|
||||||
*.log
|
*.log
|
||||||
/.calva/
|
|
||||||
|
|
||||||
# Links to other places:
|
# Links to other places:
|
||||||
resources/public/docs/mw-*/uberdoc.html
|
resources/public/docs/mw-*/uberdoc.html
|
||||||
# Artefacts:
|
# Artefacts:
|
||||||
mw_ui.log
|
mw_ui.log
|
||||||
pom.xml
|
pom.xml
|
||||||
|
|
||||||
buildall.tmp.*/
|
|
||||||
|
|
||||||
.nrepl-port
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
FROM tomcat:alpine
|
|
||||||
COPY target/microworld.war $CATALINA_HOME/webapps/
|
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
## Part of the overall Microworld system
|
## Part of the overall MicroWorld system
|
||||||
|
|
||||||
*mw-ui* is not a stand-alone project. To use it you also need at least
|
*mw-ui* is not a stand-alone project. To use it you also need at least
|
||||||
[mw-parser](https://github.com/simon-brooke/mw-parser) and
|
[mw-parser](https://github.com/simon-brooke/mw-parser) and
|
||||||
[mw-engine](https://github.com/simon-brooke/mw-engine). There will be other
|
[mw-engine](https://github.com/simon-brooke/mw-engine). There will be other
|
||||||
modules in due course.
|
modules in due course.
|
||||||
|
|
||||||
|
You can see MicroWorld in action [here](http://www.journeyman.cc/microworld/) -
|
||||||
|
but please don't be mean to my poor little server. If you want to run big maps
|
||||||
|
or complex rule-sets, please run it on your own machines.
|
||||||
|
|
||||||
## What this is about
|
## What this is about
|
||||||
|
|
||||||
<img alt="Screenshot" id="screenshot" style="float: left; padding-right: 2em;" src="img/screenshot_med.png"/>
|
<img alt="Screenshot" id="screenshot" alt="MicroWrold in action"
|
||||||
|
style="float: left; padding-right: 2em;" src="img/screenshot_med.png"/>
|
||||||
MicroWorld is a rule driven cellular automaton. What does that mean? Well, it's
|
MicroWorld is a rule driven cellular automaton. What does that mean? Well, it's
|
||||||
a two dimensional world made up of squares called **cells**. The world develops
|
a two dimensional world made up of squares called **cells**. The world develops
|
||||||
in steps, and at each step, each cell is modified by applying the rules.
|
in steps, and at each step, each cell is modified by applying the rules.
|
||||||
|
|
39
project.clj
39
project.clj
|
@ -1,4 +1,4 @@
|
||||||
(defproject mw-ui "0.1.5"
|
(defproject mw-ui "0.1.5-SNAPSHOT"
|
||||||
:description "Web-based user interface for MicroWorld"
|
:description "Web-based user interface for MicroWorld"
|
||||||
:url "http://www.journeyman.cc/microworld"
|
:url "http://www.journeyman.cc/microworld"
|
||||||
:manifest {
|
:manifest {
|
||||||
|
@ -8,29 +8,22 @@
|
||||||
"build-signature-timestamp" "unset"
|
"build-signature-timestamp" "unset"
|
||||||
"Implementation-Version" "unset"
|
"Implementation-Version" "unset"
|
||||||
}
|
}
|
||||||
:dependencies [[org.clojure/clojure "1.8.0"]
|
:dependencies [[org.clojure/clojure "1.6.0"]
|
||||||
[mw-engine "0.1.5"]
|
[mw-engine "0.1.5-SNAPSHOT"]
|
||||||
[mw-parser "0.1.5"]
|
[mw-parser "0.1.5-SNAPSHOT"]
|
||||||
[lib-noir "0.9.9"]
|
[lib-noir "0.8.4"]
|
||||||
[ring-server "0.5.0"]
|
[ring-server "0.3.1"]
|
||||||
[selmer "1.11.3" :exclusions [cheshire
|
[selmer "0.6.8"]
|
||||||
com.fasterxml.jackson.core/jackson-core
|
[com.taoensso/timbre "3.2.1"]
|
||||||
com.fasterxml.jackson.dataformat/jackson-dataformat-smile
|
[com.taoensso/tower "2.0.2"]
|
||||||
com.fasterxml.jackson.dataformat/jackson-dataformat-cbor]]
|
[markdown-clj "0.9.44"]
|
||||||
[hiccup "1.0.5"]
|
[environ "0.5.0"]
|
||||||
[com.taoensso/timbre "4.10.0" :exclusions [org.clojure/tools.reader]]
|
[noir-exception "0.2.2"]]
|
||||||
[com.taoensso/tower "3.0.2"]
|
|
||||||
[markdown-clj "1.0.1"]
|
|
||||||
[environ "1.1.0"]
|
|
||||||
[noir-exception "0.2.5"]]
|
|
||||||
:main mw-ui.repl
|
|
||||||
:repl-options {:init-ns mw-ui.repl}
|
:repl-options {:init-ns mw-ui.repl}
|
||||||
:plugins [[lein-ring "0.8.11"]
|
:plugins [[lein-ring "0.8.11"]
|
||||||
[lein-environ "0.5.0"]
|
[lein-environ "0.5.0"]
|
||||||
[lein-marginalia "0.7.1"]
|
[lein-marginalia "0.7.1"]]
|
||||||
[io.sarnowski/lein-docker "1.1.0"]]
|
|
||||||
:docker {:image-name "simonbrooke/microworld"
|
|
||||||
:dockerfile "Dockerfile"}
|
|
||||||
:ring {:handler mw-ui.handler/app
|
:ring {:handler mw-ui.handler/app
|
||||||
:init mw-ui.handler/init
|
:init mw-ui.handler/init
|
||||||
:destroy mw-ui.handler/destroy
|
:destroy mw-ui.handler/destroy
|
||||||
|
@ -44,8 +37,8 @@
|
||||||
:stacktraces? false
|
:stacktraces? false
|
||||||
:auto-reload? false}}
|
:auto-reload? false}}
|
||||||
:dev {:dependencies [[ring-mock "0.1.5"]
|
:dev {:dependencies [[ring-mock "0.1.5"]
|
||||||
[ring/ring-devel "1.6.3" :exclusions [ring/ring-codec]]
|
[ring/ring-devel "1.3.0"]
|
||||||
[pjstadig/humane-test-output "0.8.3"]]
|
[pjstadig/humane-test-output "0.6.0"]]
|
||||||
:injections [(require 'pjstadig.humane-test-output)
|
:injections [(require 'pjstadig.humane-test-output)
|
||||||
(pjstadig.humane-test-output/activate!)]
|
(pjstadig.humane-test-output/activate!)]
|
||||||
:env {:dev true}}}
|
:env {:dev true}}}
|
||||||
|
|
|
@ -45,9 +45,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if error %}
|
{% if error %}
|
||||||
<div id="error">
|
<div id="error">
|
||||||
<pre class="error">
|
<p class="error">{{error}}</p>
|
||||||
{{error}}
|
|
||||||
</pre>
|
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
@ -59,8 +57,7 @@
|
||||||
Built with <a href="http://www.luminusweb.net/">LuminusWeb</a> ||
|
Built with <a href="http://www.luminusweb.net/">LuminusWeb</a> ||
|
||||||
<img height="16" width="16" align="top" src="img/clojure-icon.gif" alt="λ"> Powered by <a href="http://clojure.org">Clojure</a> ||
|
<img height="16" width="16" align="top" src="img/clojure-icon.gif" alt="λ"> Powered by <a href="http://clojure.org">Clojure</a> ||
|
||||||
Engineering and hosting by <a href="http://www.journeyman.cc">Journeyman</a> ||
|
Engineering and hosting by <a href="http://www.journeyman.cc">Journeyman</a> ||
|
||||||
World generated using <a href="http://git.journeyman.cc/?p=mw-engine;a=summary">MicroWorld Engine</a> ||
|
World generated using <a href="http://git.journeyman.cc/?p=mw-engine;a=summary">MicroWorld Engine</a>
|
||||||
Version {{version}}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
{% extends "templates/base.html" %}
|
{% extends "templates/base.html" %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<form action="{{servlet-context}}/params" method="POST">
|
<form action="{{servlet-context}}/params" method="POST">
|
||||||
{% csrf-field %}
|
|
||||||
<p class="widget">
|
<p class="widget">
|
||||||
<label for="ruleset">The rule set to use</label>
|
<label for="ruleset">The rule set to use</label>
|
||||||
<select name="ruleset">
|
<select name="ruleset">
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
{% extends "templates/base.html" %}
|
{% extends "templates/base.html" %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<form action="{{servlet-context}}/rules" method="POST">
|
<form action="{{servlet-context}}/rules" method="POST">
|
||||||
{% csrf-field %}
|
|
||||||
<textarea name="src" id="src" rows="10" cols="80">
|
<textarea name="src" id="src" rows="10" cols="80">
|
||||||
{{rule-text}}
|
{{rule-text}}
|
||||||
</textarea>
|
</textarea>
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
(ns ^{:doc "Set up and tear down the request handler."
|
(ns mw-ui.handler
|
||||||
:author "Simon Brooke"}
|
|
||||||
mw-ui.handler
|
|
||||||
(:require [compojure.core :refer [defroutes]]
|
(:require [compojure.core :refer [defroutes]]
|
||||||
[mw-ui.routes.home :refer [home-routes]]
|
[mw-ui.routes.home :refer [home-routes]]
|
||||||
[mw-ui.middleware :refer [load-middleware]]
|
[mw-ui.middleware :refer [load-middleware]]
|
||||||
|
@ -8,59 +6,35 @@
|
||||||
[noir.util.middleware :refer [app-handler]]
|
[noir.util.middleware :refer [app-handler]]
|
||||||
[compojure.route :as route]
|
[compojure.route :as route]
|
||||||
[taoensso.timbre :as timbre]
|
[taoensso.timbre :as timbre]
|
||||||
[taoensso.timbre.appenders.3rd-party.rotor :as rotor]
|
[taoensso.timbre.appenders.rotor :as rotor]
|
||||||
[selmer.parser :as parser]
|
[selmer.parser :as parser]
|
||||||
[environ.core :refer [env]]))
|
[environ.core :refer [env]]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
;;;;
|
|
||||||
;;;; mw-ui: a servlet user/visualisation interface for MicroWorld.
|
|
||||||
;;;;
|
|
||||||
;;;; This program is free software; you can redistribute it and/or
|
|
||||||
;;;; modify it under the terms of the GNU General Public License
|
|
||||||
;;;; as published by the Free Software Foundation; either version 2
|
|
||||||
;;;; of the License, or (at your option) any later version.
|
|
||||||
;;;;
|
|
||||||
;;;; This program is distributed in the hope that it will be useful,
|
|
||||||
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
;;;; GNU General Public License for more details.
|
|
||||||
;;;;
|
|
||||||
;;;; You should have received a copy of the GNU General Public License
|
|
||||||
;;;; along with this program; if not, write to the Free Software
|
|
||||||
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
||||||
;;;; USA.
|
|
||||||
;;;;
|
|
||||||
;;;; Copyright (C) 2014 Simon Brooke
|
|
||||||
;;;;
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
|
|
||||||
(defroutes app-routes
|
(defroutes app-routes
|
||||||
(route/resources "/")
|
(route/resources "/")
|
||||||
(route/not-found "Not Found"))
|
(route/not-found "Not Found"))
|
||||||
|
|
||||||
|
|
||||||
(defn init
|
(defn init
|
||||||
"init will be called once when
|
"init will be called once when
|
||||||
app is deployed as a servlet on
|
app is deployed as a servlet on
|
||||||
an app server such as Tomcat
|
an app server such as Tomcat
|
||||||
put any initialization code here"
|
put any initialization code here"
|
||||||
[]
|
[]
|
||||||
(timbre/merge-config!
|
(timbre/set-config!
|
||||||
{:appenders
|
[:appenders :rotor]
|
||||||
{:rotor (rotor/rotor-appender
|
{:min-level :info
|
||||||
{:path "mw-ui.log"
|
:enabled? true
|
||||||
:max-size (* 512 1024)
|
:async? false ; should be always false for rotor
|
||||||
:backlog 10})}
|
:max-message-per-msecs nil
|
||||||
:level (or
|
:fn rotor/appender-fn})
|
||||||
(if (env :dev) :debug)
|
|
||||||
:info)})
|
|
||||||
|
|
||||||
|
(timbre/set-config!
|
||||||
|
[:shared-appender-config :rotor]
|
||||||
|
{:path "mw_ui.log" :max-size (* 512 1024) :backlog 10})
|
||||||
|
|
||||||
(if (env :dev) (parser/cache-off!))
|
(if (env :dev) (parser/cache-off!))
|
||||||
(timbre/info "mw-ui started successfully"))
|
(timbre/info "mw-ui started successfully"))
|
||||||
|
|
||||||
|
|
||||||
(defn destroy
|
(defn destroy
|
||||||
"destroy will be called when your application
|
"destroy will be called when your application
|
||||||
shuts down, put any clean up code here"
|
shuts down, put any clean up code here"
|
||||||
|
@ -68,6 +42,7 @@
|
||||||
(timbre/info "mw-ui is shutting down..."))
|
(timbre/info "mw-ui is shutting down..."))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(def app (app-handler
|
(def app (app-handler
|
||||||
;; add your application routes here
|
;; add your application routes here
|
||||||
[home-routes app-routes]
|
[home-routes app-routes]
|
||||||
|
|
|
@ -1,47 +1,16 @@
|
||||||
(ns ^{:doc "Layout content as HTML."
|
(ns mw-ui.layout
|
||||||
:author "Simon Brooke"}
|
|
||||||
mw-ui.layout
|
|
||||||
(:require [selmer.parser :as parser]
|
(:require [selmer.parser :as parser]
|
||||||
[clojure.string :as s]
|
[clojure.string :as s]
|
||||||
[ring.util.anti-forgery :refer [anti-forgery-field]]
|
|
||||||
[ring.util.response :refer [content-type response]]
|
[ring.util.response :refer [content-type response]]
|
||||||
[compojure.response :refer [Renderable]]))
|
[compojure.response :refer [Renderable]]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
;;;;
|
|
||||||
;;;; mw-ui: a servlet user/visualisation interface for MicroWorld.
|
|
||||||
;;;;
|
|
||||||
;;;; This program is free software; you can redistribute it and/or
|
|
||||||
;;;; modify it under the terms of the GNU General Public License
|
|
||||||
;;;; as published by the Free Software Foundation; either version 2
|
|
||||||
;;;; of the License, or (at your option) any later version.
|
|
||||||
;;;;
|
|
||||||
;;;; This program is distributed in the hope that it will be useful,
|
|
||||||
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
;;;; GNU General Public License for more details.
|
|
||||||
;;;;
|
|
||||||
;;;; You should have received a copy of the GNU General Public License
|
|
||||||
;;;; along with this program; if not, write to the Free Software
|
|
||||||
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
||||||
;;;; USA.
|
|
||||||
;;;;
|
|
||||||
;;;; Copyright (C) 2014 Simon Brooke
|
|
||||||
;;;;
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
|
|
||||||
|
|
||||||
(def template-path "templates/")
|
(def template-path "templates/")
|
||||||
|
|
||||||
|
|
||||||
(parser/add-tag! :csrf-field (fn [_ _] (anti-forgery-field)))
|
|
||||||
|
|
||||||
|
|
||||||
(deftype RenderableTemplate [template params]
|
(deftype RenderableTemplate [template params]
|
||||||
Renderable
|
Renderable
|
||||||
(render [this request]
|
(render [this request]
|
||||||
(content-type
|
(content-type
|
||||||
(->> (assoc (merge params {:version (System/getProperty "mw-ui.version")})
|
(->> (assoc params
|
||||||
(keyword (s/replace template #".html" "-selected")) "active"
|
(keyword (s/replace template #".html" "-selected")) "active"
|
||||||
:servlet-context
|
:servlet-context
|
||||||
(if-let [context (:servlet-context request)]
|
(if-let [context (:servlet-context request)]
|
||||||
|
@ -50,7 +19,6 @@
|
||||||
response)
|
response)
|
||||||
"text/html; charset=utf-8")))
|
"text/html; charset=utf-8")))
|
||||||
|
|
||||||
|
|
||||||
(defn render [template & [params]]
|
(defn render [template & [params]]
|
||||||
(RenderableTemplate. template params))
|
(RenderableTemplate. template params))
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
(ns ^{:doc "In truth, boilerplate from Luminus."
|
(ns mw-ui.middleware
|
||||||
:author "Simon Brooke"}
|
|
||||||
mw-ui.middleware
|
|
||||||
(:require [taoensso.timbre :as timbre]
|
(:require [taoensso.timbre :as timbre]
|
||||||
[selmer.parser :as parser]
|
[selmer.parser :as parser]
|
||||||
[environ.core :refer [env]]
|
[environ.core :refer [env]]
|
||||||
|
@ -8,46 +6,19 @@
|
||||||
[noir-exception.core
|
[noir-exception.core
|
||||||
:refer [wrap-internal-error wrap-exceptions]]))
|
:refer [wrap-internal-error wrap-exceptions]]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
;;;;
|
|
||||||
;;;; mw-ui: a servlet user/visualisation interface for MicroWorld.
|
|
||||||
;;;;
|
|
||||||
;;;; This program is free software; you can redistribute it and/or
|
|
||||||
;;;; modify it under the terms of the GNU General Public License
|
|
||||||
;;;; as published by the Free Software Foundation; either version 2
|
|
||||||
;;;; of the License, or (at your option) any later version.
|
|
||||||
;;;;
|
|
||||||
;;;; This program is distributed in the hope that it will be useful,
|
|
||||||
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
;;;; GNU General Public License for more details.
|
|
||||||
;;;;
|
|
||||||
;;;; You should have received a copy of the GNU General Public License
|
|
||||||
;;;; along with this program; if not, write to the Free Software
|
|
||||||
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
||||||
;;;; USA.
|
|
||||||
;;;;
|
|
||||||
;;;; Copyright (C) 2014 Simon Brooke
|
|
||||||
;;;;
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
|
|
||||||
|
|
||||||
(defn log-request [handler]
|
(defn log-request [handler]
|
||||||
(fn [req]
|
(fn [req]
|
||||||
(timbre/debug req)
|
(timbre/debug req)
|
||||||
(handler req)))
|
(handler req)))
|
||||||
|
|
||||||
|
|
||||||
(def development-middleware
|
(def development-middleware
|
||||||
[log-request
|
[log-request
|
||||||
wrap-error-page
|
wrap-error-page
|
||||||
wrap-exceptions])
|
wrap-exceptions])
|
||||||
|
|
||||||
|
|
||||||
(def production-middleware
|
(def production-middleware
|
||||||
[#(wrap-internal-error % :log (fn [e] (timbre/error e)))])
|
[#(wrap-internal-error % :log (fn [e] (timbre/error e)))])
|
||||||
|
|
||||||
|
|
||||||
(defn load-middleware []
|
(defn load-middleware []
|
||||||
(concat (when (env :dev) development-middleware)
|
(concat (when (env :dev) development-middleware)
|
||||||
production-middleware))
|
production-middleware))
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
(ns ^{:doc "Render the state of the world as an HTML table."
|
(ns mw-ui.render-world
|
||||||
:author "Simon Brooke"}
|
|
||||||
mw-ui.render-world
|
|
||||||
(:require [clojure.java.io :as jio]
|
(:require [clojure.java.io :as jio]
|
||||||
[mw-engine.core :as engine]
|
[mw-engine.core :as engine]
|
||||||
[mw-engine.world :as world]
|
[mw-engine.world :as world]
|
||||||
|
@ -10,47 +8,21 @@
|
||||||
[noir.io :as io]
|
[noir.io :as io]
|
||||||
[noir.session :as session]))
|
[noir.session :as session]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
;;;;
|
|
||||||
;;;; mw-ui: a servlet user/visualisation interface for MicroWorld.
|
|
||||||
;;;;
|
|
||||||
;;;; This program is free software; you can redistribute it and/or
|
|
||||||
;;;; modify it under the terms of the GNU General Public License
|
|
||||||
;;;; as published by the Free Software Foundation; either version 2
|
|
||||||
;;;; of the License, or (at your option) any later version.
|
|
||||||
;;;;
|
|
||||||
;;;; This program is distributed in the hope that it will be useful,
|
|
||||||
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
;;;; GNU General Public License for more details.
|
|
||||||
;;;;
|
|
||||||
;;;; You should have received a copy of the GNU General Public License
|
|
||||||
;;;; along with this program; if not, write to the Free Software
|
|
||||||
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
||||||
;;;; USA.
|
|
||||||
;;;;
|
|
||||||
;;;; Copyright (C) 2014 Simon Brooke
|
|
||||||
;;;;
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
|
|
||||||
|
|
||||||
(defn format-css-class [statekey]
|
(defn format-css-class [statekey]
|
||||||
"Format this statekey, assumed to be a keyword indicating a state in the
|
"Format this statekey, assumed to be a keyword indicating a state in the
|
||||||
world, into a CSS class"
|
world, into a CSS class"
|
||||||
(subs (str statekey) 1))
|
(subs (str statekey) 1))
|
||||||
|
|
||||||
|
|
||||||
(defn format-image-path
|
(defn format-image-path
|
||||||
"Render this statekey, assumed to be a keyword indicating a state in the
|
"Render this statekey, assumed to be a keyword indicating a state in the
|
||||||
world, into a path which should recover the corresponding image file."
|
world, into a path which should recover the corresponding image file."
|
||||||
[statekey]
|
[statekey]
|
||||||
(format "img/tiles/%s.png" (format-css-class statekey)))
|
(format "img/tiles/%s.png" (format-css-class statekey)))
|
||||||
|
|
||||||
|
|
||||||
(defn format-mouseover [cell]
|
(defn format-mouseover [cell]
|
||||||
(str cell))
|
(str cell))
|
||||||
|
|
||||||
|
|
||||||
(defn render-cell
|
(defn render-cell
|
||||||
"Render this world cell as a Hiccup table cell."
|
"Render this world cell as a Hiccup table cell."
|
||||||
[cell]
|
[cell]
|
||||||
|
@ -59,13 +31,11 @@
|
||||||
[:a {:href (format "inspect?x=%d&y=%d" (:x cell) (:y cell))}
|
[:a {:href (format "inspect?x=%d&y=%d" (:x cell) (:y cell))}
|
||||||
[:img {:alt (:state cell) :src (format-image-path state)}]]]))
|
[:img {:alt (:state cell) :src (format-image-path state)}]]]))
|
||||||
|
|
||||||
|
|
||||||
(defn render-world-row
|
(defn render-world-row
|
||||||
"Render this world row as a Hiccup table row."
|
"Render this world row as a Hiccup table row."
|
||||||
[row]
|
[row]
|
||||||
(apply vector (cons :tr (map render-cell row))))
|
(apply vector (cons :tr (map render-cell row))))
|
||||||
|
|
||||||
|
|
||||||
(defn render-world-table
|
(defn render-world-table
|
||||||
"Render the world implied by the current session as a complete HTML table in a DIV."
|
"Render the world implied by the current session as a complete HTML table in a DIV."
|
||||||
[]
|
[]
|
||||||
|
@ -78,7 +48,8 @@
|
||||||
(io/get-resource "/rulesets/basic.txt")))
|
(io/get-resource "/rulesets/basic.txt")))
|
||||||
(session/get :rules)))
|
(session/get :rules)))
|
||||||
generation (inc (or (session/get :generation) 0))
|
generation (inc (or (session/get :generation) 0))
|
||||||
w2 (engine/transform-world world rules)]
|
w2 (engine/transform-world world rules)
|
||||||
|
]
|
||||||
(session/put! :world w2)
|
(session/put! :world w2)
|
||||||
(session/put! :generation generation)
|
(session/put! :generation generation)
|
||||||
[:div {:class "world"}
|
[:div {:class "world"}
|
||||||
|
@ -88,7 +59,6 @@
|
||||||
[:p
|
[:p
|
||||||
(str "Generation " generation)]]))
|
(str "Generation " generation)]]))
|
||||||
|
|
||||||
|
|
||||||
(defn render-inspector
|
(defn render-inspector
|
||||||
"Render in Hiccup format the HTML content of an inspector on this cell."
|
"Render in Hiccup format the HTML content of an inspector on this cell."
|
||||||
[cell table]
|
[cell table]
|
||||||
|
|
|
@ -1,34 +1,9 @@
|
||||||
(ns ^{:doc "In truth, boilerplate from Luminus."
|
(ns mw-ui.repl
|
||||||
:author "Simon Brooke"}
|
|
||||||
mw-ui.repl
|
|
||||||
(:use mw-ui.handler
|
(:use mw-ui.handler
|
||||||
ring.server.standalone
|
ring.server.standalone
|
||||||
[ring.middleware file-info file])
|
[ring.middleware file-info file])
|
||||||
(:gen-class))
|
(:gen-class)
|
||||||
|
)
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
;;;;
|
|
||||||
;;;; mw-ui: a servlet user/visualisation interface for MicroWorld.
|
|
||||||
;;;;
|
|
||||||
;;;; This program is free software; you can redistribute it and/or
|
|
||||||
;;;; modify it under the terms of the GNU General Public License
|
|
||||||
;;;; as published by the Free Software Foundation; either version 2
|
|
||||||
;;;; of the License, or (at your option) any later version.
|
|
||||||
;;;;
|
|
||||||
;;;; This program is distributed in the hope that it will be useful,
|
|
||||||
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
;;;; GNU General Public License for more details.
|
|
||||||
;;;;
|
|
||||||
;;;; You should have received a copy of the GNU General Public License
|
|
||||||
;;;; along with this program; if not, write to the Free Software
|
|
||||||
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
||||||
;;;; USA.
|
|
||||||
;;;;
|
|
||||||
;;;; Copyright (C) 2014 Simon Brooke
|
|
||||||
;;;;
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
|
|
||||||
|
|
||||||
(defonce server (atom nil))
|
(defonce server (atom nil))
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
(ns ^{:doc "Routes which serve the main pages of the application."
|
(ns mw-ui.routes.home
|
||||||
:author "Simon Brooke"}
|
|
||||||
mw-ui.routes.home
|
|
||||||
(:use clojure.walk
|
(:use clojure.walk
|
||||||
compojure.core)
|
compojure.core)
|
||||||
(:require [clojure.pprint :only [pprint]]
|
(:require [clojure.pprint :only [pprint]]
|
||||||
|
@ -17,29 +15,6 @@
|
||||||
[noir.session :as session]
|
[noir.session :as session]
|
||||||
[ring.util.response :as response]))
|
[ring.util.response :as response]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
;;;;
|
|
||||||
;;;; mw-ui: a servlet user/visualisation interface for MicroWorld.
|
|
||||||
;;;;
|
|
||||||
;;;; This program is free software; you can redistribute it and/or
|
|
||||||
;;;; modify it under the terms of the GNU General Public License
|
|
||||||
;;;; as published by the Free Software Foundation; either version 2
|
|
||||||
;;;; of the License, or (at your option) any later version.
|
|
||||||
;;;;
|
|
||||||
;;;; This program is distributed in the hope that it will be useful,
|
|
||||||
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
;;;; GNU General Public License for more details.
|
|
||||||
;;;;
|
|
||||||
;;;; You should have received a copy of the GNU General Public License
|
|
||||||
;;;; along with this program; if not, write to the Free Software
|
|
||||||
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
||||||
;;;; USA.
|
|
||||||
;;;;
|
|
||||||
;;;; Copyright (C) 2014 Simon Brooke
|
|
||||||
;;;;
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
|
|
||||||
|
|
||||||
(defn list-states []
|
(defn list-states []
|
||||||
(sort
|
(sort
|
||||||
|
@ -52,22 +27,19 @@
|
||||||
(layout/render "trusted-content.html"
|
(layout/render "trusted-content.html"
|
||||||
{:title "About MicroWorld"
|
{:title "About MicroWorld"
|
||||||
:about-selected "active"
|
:about-selected "active"
|
||||||
:content (util/md->html "/md/about.md")
|
:content (util/md->html "/md/about.md")}))
|
||||||
:version (System/getProperty "mw-ui.version")}))
|
|
||||||
|
|
||||||
(defn docs-page []
|
(defn docs-page []
|
||||||
(layout/render "docs.html" {:title "Documentation"
|
(layout/render "docs.html" {:title "Documentation"
|
||||||
:parser (util/md->html "/md/mw-parser.md" )
|
:parser (util/md->html "/md/mw-parser.md" )
|
||||||
:states (util/list-resources "/img/tiles" #"([0-9a-z-_]+).png")
|
:states (util/list-resources "/img/tiles" #"([0-9a-z-_]+).png")
|
||||||
:lessons (util/list-resources "/md/lesson-plans" #"([0-9a-z-_]+).md")
|
:lessons (util/list-resources "/md/lesson-plans" #"([0-9a-z-_]+).md")
|
||||||
:components ["mw-engine" "mw-parser" "mw-ui"]
|
:components ["mw-engine" "mw-parser" "mw-ui"]}))
|
||||||
:version (System/getProperty "mw-ui.version")}))
|
|
||||||
|
|
||||||
(defn home-page []
|
(defn home-page []
|
||||||
"Render the home page."
|
"Render the home page."
|
||||||
(layout/render "trusted-content.html" {:title "Welcome to MicroWorld"
|
(layout/render "trusted-content.html" {:title "Welcome to MicroWorld"
|
||||||
:content (util/md->html "/md/mw-ui.md")
|
:content (util/md->html "/md/mw-ui.md")}))
|
||||||
:version (System/getProperty "mw-ui.version")}))
|
|
||||||
|
|
||||||
(defn inspect-page [request]
|
(defn inspect-page [request]
|
||||||
"Open an inspector on the cell at the co-ordinates specified in this request"
|
"Open an inspector on the cell at the co-ordinates specified in this request"
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
(ns ^{:doc "Route which handles the upload of worlds/rules from the client."
|
(ns mw-ui.routes.load
|
||||||
:author "Simon Brooke"}
|
|
||||||
mw-ui.routes.load
|
|
||||||
(:use clojure.walk
|
(:use clojure.walk
|
||||||
compojure.core)
|
compojure.core)
|
||||||
(:require [hiccup.core :refer [html]]
|
(:require [hiccup.core :refer [html]]
|
||||||
|
@ -10,29 +8,6 @@
|
||||||
[mw-ui.layout :as layout]
|
[mw-ui.layout :as layout]
|
||||||
))
|
))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
;;;;
|
|
||||||
;;;; mw-ui: a servlet user/visualisation interface for MicroWorld.
|
|
||||||
;;;;
|
|
||||||
;;;; This program is free software; you can redistribute it and/or
|
|
||||||
;;;; modify it under the terms of the GNU General Public License
|
|
||||||
;;;; as published by the Free Software Foundation; either version 2
|
|
||||||
;;;; of the License, or (at your option) any later version.
|
|
||||||
;;;;
|
|
||||||
;;;; This program is distributed in the hope that it will be useful,
|
|
||||||
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
;;;; GNU General Public License for more details.
|
|
||||||
;;;;
|
|
||||||
;;;; You should have received a copy of the GNU General Public License
|
|
||||||
;;;; along with this program; if not, write to the Free Software
|
|
||||||
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
||||||
;;;; USA.
|
|
||||||
;;;;
|
|
||||||
;;;; Copyright (C) 2014 Simon Brooke
|
|
||||||
;;;;
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
|
|
||||||
|
|
||||||
(defn- upload [file]
|
(defn- upload [file]
|
||||||
(io/upload-file "/tmp/" file)
|
(io/upload-file "/tmp/" file)
|
||||||
|
@ -41,7 +16,6 @@
|
||||||
(with-open [eddi (java.io.FileReader. (:tempfile file))] (read)))
|
(with-open [eddi (java.io.FileReader. (:tempfile file))] (read)))
|
||||||
(str "Successfully loaded your world from " (:filename file))))
|
(str "Successfully loaded your world from " (:filename file))))
|
||||||
|
|
||||||
|
|
||||||
(defn load-page
|
(defn load-page
|
||||||
"If no args, show the load form; with args, load a world file from the client.
|
"If no args, show the load form; with args, load a world file from the client.
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
(ns ^{:doc "Route which serves and handles the parameters page."
|
(ns mw-ui.routes.params
|
||||||
:author "Simon Brooke"}
|
|
||||||
mw-ui.routes.params
|
|
||||||
(:use clojure.walk
|
(:use clojure.walk
|
||||||
clojure.java.io
|
clojure.java.io
|
||||||
compojure.core)
|
compojure.core)
|
||||||
|
@ -13,30 +11,6 @@
|
||||||
[noir.io :as io]
|
[noir.io :as io]
|
||||||
[noir.session :as session]))
|
[noir.session :as session]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
;;;;
|
|
||||||
;;;; mw-ui: a servlet user/visualisation interface for MicroWorld.
|
|
||||||
;;;;
|
|
||||||
;;;; This program is free software; you can redistribute it and/or
|
|
||||||
;;;; modify it under the terms of the GNU General Public License
|
|
||||||
;;;; as published by the Free Software Foundation; either version 2
|
|
||||||
;;;; of the License, or (at your option) any later version.
|
|
||||||
;;;;
|
|
||||||
;;;; This program is distributed in the hope that it will be useful,
|
|
||||||
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
;;;; GNU General Public License for more details.
|
|
||||||
;;;;
|
|
||||||
;;;; You should have received a copy of the GNU General Public License
|
|
||||||
;;;; along with this program; if not, write to the Free Software
|
|
||||||
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
||||||
;;;; USA.
|
|
||||||
;;;;
|
|
||||||
;;;; Copyright (C) 2014 Simon Brooke
|
|
||||||
;;;;
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
|
|
||||||
|
|
||||||
(defn- send-params []
|
(defn- send-params []
|
||||||
{:title "Choose your world"
|
{:title "Choose your world"
|
||||||
:heightmaps (util/list-resources "/img/heightmaps" #"([0-9a-z-_]+).png")
|
:heightmaps (util/list-resources "/img/heightmaps" #"([0-9a-z-_]+).png")
|
||||||
|
@ -44,7 +18,6 @@
|
||||||
:rulesets (util/list-resources "/rulesets" #"([0-9a-z-_]+).txt")
|
:rulesets (util/list-resources "/rulesets" #"([0-9a-z-_]+).txt")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
(defn params-page
|
(defn params-page
|
||||||
"Handler for params request. If no `request` passed, show empty params form.
|
"Handler for params request. If no `request` passed, show empty params form.
|
||||||
If `request` is passed, put parameters from request into session and show
|
If `request` is passed, put parameters from request into session and show
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
(ns ^{:doc "Route which serves and handles the rules page."
|
(ns mw-ui.routes.rules
|
||||||
:author "Simon Brooke"}
|
|
||||||
mw-ui.routes.rules
|
|
||||||
(:use clojure.walk
|
(:use clojure.walk
|
||||||
compojure.core)
|
compojure.core)
|
||||||
(:require [hiccup.core :refer [html]]
|
(:require [hiccup.core :refer [html]]
|
||||||
|
@ -12,30 +10,6 @@
|
||||||
[noir.session :as session]
|
[noir.session :as session]
|
||||||
[ring.util.response :as response]))
|
[ring.util.response :as response]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
;;;;
|
|
||||||
;;;; mw-ui: a servlet user/visualisation interface for MicroWorld.
|
|
||||||
;;;;
|
|
||||||
;;;; This program is free software; you can redistribute it and/or
|
|
||||||
;;;; modify it under the terms of the GNU General Public License
|
|
||||||
;;;; as published by the Free Software Foundation; either version 2
|
|
||||||
;;;; of the License, or (at your option) any later version.
|
|
||||||
;;;;
|
|
||||||
;;;; This program is distributed in the hope that it will be useful,
|
|
||||||
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
;;;; GNU General Public License for more details.
|
|
||||||
;;;;
|
|
||||||
;;;; You should have received a copy of the GNU General Public License
|
|
||||||
;;;; along with this program; if not, write to the Free Software
|
|
||||||
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
||||||
;;;; USA.
|
|
||||||
;;;;
|
|
||||||
;;;; Copyright (C) 2014 Simon Brooke
|
|
||||||
;;;;
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
|
|
||||||
|
|
||||||
(defn process-rules-request
|
(defn process-rules-request
|
||||||
[request]
|
[request]
|
||||||
(let [src (:src (keywordize-keys (:form-params request)))]
|
(let [src (:src (keywordize-keys (:form-params request)))]
|
||||||
|
@ -56,7 +30,6 @@
|
||||||
:message "An error occurred during compilation"
|
:message "An error occurred during compilation"
|
||||||
:error (str (.getName (.getClass e)) ": " (.getMessage e))}))))
|
:error (str (.getName (.getClass e)) ": " (.getMessage e))}))))
|
||||||
|
|
||||||
|
|
||||||
(defn rules-page
|
(defn rules-page
|
||||||
"Request handler for the `rules` request. If the `request` contains a value
|
"Request handler for the `rules` request. If the `request` contains a value
|
||||||
for `:src`, treat that as rule source and try to compile it. If compilation
|
for `:src`, treat that as rule source and try to compile it. If compilation
|
||||||
|
|
|
@ -1,40 +1,15 @@
|
||||||
(ns ^{:doc "Route which handles the saving of world state the client."
|
(ns mw-ui.routes.save
|
||||||
:author "Simon Brooke"}
|
|
||||||
mw-ui.routes.save
|
|
||||||
(:require [clojure.pprint :as pretty :only [pprint]]
|
(:require [clojure.pprint :as pretty :only [pprint]]
|
||||||
[noir.session :as session]
|
[noir.session :as session]
|
||||||
[noir.response :as response]))
|
[ring.util.response :as response]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
;;;;
|
|
||||||
;;;; mw-ui: a servlet user/visualisation interface for MicroWorld.
|
|
||||||
;;;;
|
|
||||||
;;;; This program is free software; you can redistribute it and/or
|
|
||||||
;;;; modify it under the terms of the GNU General Public License
|
|
||||||
;;;; as published by the Free Software Foundation; either version 2
|
|
||||||
;;;; of the License, or (at your option) any later version.
|
|
||||||
;;;;
|
|
||||||
;;;; This program is distributed in the hope that it will be useful,
|
|
||||||
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
;;;; GNU General Public License for more details.
|
|
||||||
;;;;
|
|
||||||
;;;; You should have received a copy of the GNU General Public License
|
|
||||||
;;;; along with this program; if not, write to the Free Software
|
|
||||||
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
||||||
;;;; USA.
|
|
||||||
;;;;
|
|
||||||
;;;; Copyright (C) 2014 Simon Brooke
|
|
||||||
;;;;
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
|
|
||||||
|
|
||||||
(defn save-page []
|
(defn save-page []
|
||||||
"Save the current world to the browser, using our own custom mime-type in
|
"Save the current world to the browser, using our own custom mime-type in
|
||||||
an attempt to prevent the browser trying to do anything clever with it.
|
an attempt to prevent the browser trying to do anything clever with it.
|
||||||
Note that it is saved as a raw Clojure data structure, not as XML or
|
Note that it is saved as a raw Clojure data structure, not as XML or
|
||||||
any proprietary format."
|
any proprietary format."
|
||||||
(response/content-type
|
(response/header
|
||||||
"application/journeyman-mwm; charset=utf-8"
|
(response/response
|
||||||
(with-out-str (pretty/pprint (session/get :world)))))
|
(with-out-str (pretty/pprint (session/get :world))))
|
||||||
|
"Content-Type" "application/journeyman-mwm; charset=utf-8"))
|
||||||
|
|
||||||
|
|
|
@ -1,34 +1,8 @@
|
||||||
(ns ^{:doc "Utility functions used by other namespaces in this package."
|
(ns mw-ui.util
|
||||||
:author "Simon Brooke"}
|
|
||||||
mw-ui.util
|
|
||||||
(:require [noir.io :as io]
|
(:require [noir.io :as io]
|
||||||
[noir.session :as session]
|
[noir.session :as session]
|
||||||
[markdown.core :as md]))
|
[markdown.core :as md]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
;;;;
|
|
||||||
;;;; mw-ui: a servlet user/visualisation interface for MicroWorld.
|
|
||||||
;;;;
|
|
||||||
;;;; This program is free software; you can redistribute it and/or
|
|
||||||
;;;; modify it under the terms of the GNU General Public License
|
|
||||||
;;;; as published by the Free Software Foundation; either version 2
|
|
||||||
;;;; of the License, or (at your option) any later version.
|
|
||||||
;;;;
|
|
||||||
;;;; This program is distributed in the hope that it will be useful,
|
|
||||||
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
;;;; GNU General Public License for more details.
|
|
||||||
;;;;
|
|
||||||
;;;; You should have received a copy of the GNU General Public License
|
|
||||||
;;;; along with this program; if not, write to the Free Software
|
|
||||||
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
||||||
;;;; USA.
|
|
||||||
;;;;
|
|
||||||
;;;; Copyright (C) 2014 Simon Brooke
|
|
||||||
;;;;
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
|
|
||||||
|
|
||||||
(defn md->html
|
(defn md->html
|
||||||
"reads a markdown file from public/md and returns an HTML string"
|
"reads a markdown file from public/md and returns an HTML string"
|
||||||
[filename]
|
[filename]
|
||||||
|
@ -36,10 +10,8 @@
|
||||||
(io/slurp-resource filename)
|
(io/slurp-resource filename)
|
||||||
(md/md-to-html-string)))
|
(md/md-to-html-string)))
|
||||||
|
|
||||||
|
(defn list-resources [directory pattern]
|
||||||
(defn list-resources
|
|
||||||
"List resource files matching `pattern` in `directory`."
|
"List resource files matching `pattern` in `directory`."
|
||||||
[directory pattern]
|
|
||||||
(let
|
(let
|
||||||
[path (str (io/resource-path) directory)]
|
[path (str (io/resource-path) directory)]
|
||||||
(session/put! :list-resources-path path)
|
(session/put! :list-resources-path path)
|
||||||
|
|
Loading…
Reference in a new issue