Once again, fixed tests so they pass, although they don't actually

test anything useful.
This commit is contained in:
Simon Brooke 2014-07-07 19:55:14 +01:00
parent 257d306d5d
commit c0e5729c81
7 changed files with 75 additions and 34 deletions

View file

@ -64,9 +64,11 @@ body {
margin: 0;
display: inline;
}
.nav-item a { color: rgb(64, 64, 64);
#nav ul li a {
color: white;
text-decoration: none;
font-weight: normal;
font-weight: bold;
padding: 0.25em 0.75em;
margin: 0;
}

View file

@ -19,13 +19,11 @@
<meta content="{{seconds}}" http-equiv="{{maybe-refresh}}" />
</head>
<body>
<div id="header" style=" background-image: url( '{{servlet-context}}/img/earth-space-strip.jpg');"
>
<div id="header" style=" background-image: url( '{{servlet-context}}/img/earth-space-strip.jpg');">
<div id="nav">
<ul class="nav">
<li class="{{home-selected}}"><a href="{{servlet-context}}/">Home</a></li>
<li class="{{about-selected}}"><a href="{{servlet-context}}/about">About</a></li>
<li class="{{world-selected}}"><a href="{{servlet-context}}/world">World</a></li>
<li class="{{docs-selected}}"><a href="{{servlet-context}}/docs">Documentation</a></li>
</ul>
<h1>{{title}}</h1>

View file

@ -1,6 +1,54 @@
{% extends "templates/base.html" %}
{% block content %}
<div>
<a name="top"/>
<menu>
<li><a href="#top">Top</a></li>
<li><a href="#parser">Rule language</a></li>
<li><a href="#states">Implemented states</a></li>
<li><a href="#api">API documentation</a></li>
</menu>
<hr/>
<a name="parser"/>
{{parser|safe}}
<hr/>
<menu>
<li><a href="#top">Top</a></li>
<li><a href="#parser">Rule language</a></li>
<li><a href="#states">Implemented states</a></li>
<li><a href="#api">API documentation</a></li>
</menu>
<hr/>
<h2><a name="states">Implemented states</h2>
<p>As it says in the rule language documentation, above, you can use
any sequence of alphanumeric characters you want as the name of a state
&emdash; you can call it whatever you like. However, if you use state
names that there aren't already tiles for, and aren't already classes
for in the CSS file, your states won't be displayed nicely in the
<a href="{{servlet-context}}/">World</a> display. The states for which
there are already tiles are:</p>
<ul>
{% for state in states %}
<li>
{{state}}
<img src="{{servlet-context}}/img/tiles/{{state}}.png"/>
</li>
{% endfor %}
</ul>
<hr/>
<menu>
<li><a href="#top">Top</a></li>
<li><a href="#parser">Rule language</a></li>
<li><a href="#states">Implemented states</a></li>
<li><a href="#api">API documentation</a></li>
</menu>
<hr/>
<h2><a name="api">API documentation</a></h2>
<p>If you're adventurous you may want to modify the MicroWorld engine
itself. To do that you'll need this documentation.
<ul>
{% for component in components %}
<li>

View file

@ -1,19 +1,6 @@
{% extends "templates/base.html" %}
{% block content %}
<div>
<form action="world">
<p class="widget">
<label for="y">Size of your world: rows</label>
<input name="y" type="range" min="5" max="100" value="{{y}}" required/>
</p>
<p class="widget">
<label for="y">Size of your world: columns</label>
<input name="x" type="range" min="5" max="100" value="{{x}}" required/>
</p>
<p class="widget">
<label for="submit">&nbsp;</label>
<input name="submit" id="submit" type="submit" value="Go!"/>
</p>
</form>
{{content|safe}}
</div>
{% endblock %}

View file

@ -18,11 +18,14 @@
[statekey]
(format "img/tiles/%s.png" (format-css-class statekey)))
(defn format-mouseover [cell]
(str "State " (:state cell) "; altitude: " (:altitude cell) "; fertility: " (:fertility cell)))
(defn render-cell
"Render this world cell as a Hiccup table cell."
[cell]
(let [state (:state cell)]
[:td {:class (format-css-class state)}
[:td {:class (format-css-class state) :title (format-mouseover cell)}
[:img {:alt (world/format-cell cell) :src (format-image-path state)}]]))
(defn render-world-row
@ -46,10 +49,11 @@
(session/put! :world w2)
(session/put! :generation generation)
[:div {:class "world"}
[:p (str "Generation " generation)]
(apply vector
(cons :table
(map render-world-row w2)))]))
(map render-world-row w2)))
[:p (str "Generation " generation)]]))
(defn render-world
"Render the world implied by the session as a complete HTML page."

View file

@ -7,24 +7,27 @@
[noir.session :as session]))
(defn home-page []
(layout/render
"home.html" {:title "Welcome to MicroWorld" :content (util/md->html "/md/docs.md")}))
(defn about-page []
(layout/render "about.html" {:title "About MicroWorld" :content (util/md->html "/md/about.md")}))
(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")}))
(defn list-states []
(sort
(filter #(not (nil? %))
(map #(first (rest (re-matches #"([0-9a-z-]+).png" (.getName %))))
(file-seq (clojure.java.io/file "resources/public/img/tiles"))))))
(defn docs-page []
(layout/render "docs.html" {:title "Documentation"
:parser (util/md->html "/md/parser.md")
:states (list-states)
:components ["mw-engine" "mw-parser" "mw-ui"]}))
(defroutes home-routes
(GET "/" [] (home-page))
(GET "/about" [] (about-page))
(GET "/world" [] (world-page))
(GET "/docs" [] (docs-page)))

View file

@ -6,10 +6,9 @@
(deftest test-app
(testing "main route"
(let [response (app (request :get "/"))]
(is (= (:status response) 200))
(is (= (:body response)
"<html>\n <head>\n <title>Welcome to mw-ui</title>\n <link href=\"/css/screen.css\" rel=\"stylesheet\" type=\"text/css\"></link>\n </head>\n <body>\n <div class=\"navbar navbar-fixed-top navbar-inverse\">\n <ul class=\"nav\">\n <li>\n <a href=\"/\">Home</a>\n </li>\n <li>\n <a href=\"/about\">About</a>\n </li>\n </ul>\n </div>\n <div id=\"content\">\n <h1>Welcome to mw-ui</h1>\n \n<h2>Some links to get started</h2><ol><li><a href='http://www.luminusweb.net/docs/html&#95;templating.md'>HTML templating</a></li><li><a href='http://www.luminusweb.net/docs/database.md'>Accessing the database</a></li><li><a href='http://www.luminusweb.net/docs/static&#95;resources.md'>Serving static resources</a></li><li><a href='http://www.luminusweb.net/docs/responses.md'>Setting response types</a></li><li><a href='http://www.luminusweb.net/docs/routes.md'>Defining routes</a></li><li><a href='http://www.luminusweb.net/docs/middleware.md'>Adding middleware</a></li><li><a href='http://www.luminusweb.net/docs/sessions&#95;cookies.md'>Sessions and cookies</a></li><li><a href='http://www.luminusweb.net/docs/security.md'>Security</a></li><li><a href='http://www.luminusweb.net/docs/deployment.md'>Deploying the application</a></li></ol>\n\n </div> \n <footer>Copyright ...</footer>\n </body>\n</html>\n\n\n"))))
(is (= (:status response) 200))))
(testing "not-found route"
(let [response (app (request :get "/invalid"))]
(is (= (:status response) 404)))))
(is (= (:status response) 404))))
)