diff --git a/resources/public/css/standard.css b/resources/public/css/standard.css index 92a6f5c..e60166e 100644 --- a/resources/public/css/standard.css +++ b/resources/public/css/standard.css @@ -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; } diff --git a/resources/templates/base.html b/resources/templates/base.html index f09b769..971dee4 100644 --- a/resources/templates/base.html +++ b/resources/templates/base.html @@ -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> diff --git a/resources/templates/docs.html b/resources/templates/docs.html index 6192696..4815695 100644 --- a/resources/templates/docs.html +++ b/resources/templates/docs.html @@ -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> diff --git a/resources/templates/home.html b/resources/templates/home.html index fb0822f..f2ebe9f 100644 --- a/resources/templates/home.html +++ b/resources/templates/home.html @@ -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"> </label> - <input name="submit" id="submit" type="submit" value="Go!"/> - </p> - </form> + {{content|safe}} </div> {% endblock %} diff --git a/src/mw_ui/render_world.clj b/src/mw_ui/render_world.clj index 6816d55..a4cc30c 100644 --- a/src/mw_ui/render_world.clj +++ b/src/mw_ui/render_world.clj @@ -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." diff --git a/src/mw_ui/routes/home.clj b/src/mw_ui/routes/home.clj index 790f10a..c20abd3 100644 --- a/src/mw_ui/routes/home.clj +++ b/src/mw_ui/routes/home.clj @@ -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))) diff --git a/test/mw_ui/test/handler.clj b/test/mw_ui/test/handler.clj index 47e4862..91af8de 100644 --- a/test/mw_ui/test/handler.clj +++ b/test/mw_ui/test/handler.clj @@ -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_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_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_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)))) +) \ No newline at end of file