Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Simplest mongo web app possible.

  • Loading branch information...
commit 8fd36ea305aa336365b9c6b7929198e6fcf7b4e7 0 parents
@pstillman authored
7 .gitignore
@@ -0,0 +1,7 @@
+pom.xml
+*jar
+/lib/
+/classes/
+.lein-deps-sum
+*.swp
+\#.*#
19 README.md
@@ -0,0 +1,19 @@
+# trivial-noir
+
+A trivial web app written in noir, mostly for playing with congomongo a
+bit.
+
+## Usage
+
+```bash
+lein deps
+lein ring server
+```
+
+## License
+
+Copyright (C) 2011 Peter Stillman
+
+Distributed under the [Gnu Public License version 2.0][gplv2].
+
+[gplv2]: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html "Gnu Public License version 2.0"
17 blah.html
@@ -0,0 +1,17 @@
+<h1>trivial-noir</h1>
+
+<p>A trivial web app written in noir, mostly for playing with congomongo a
+bit. </p>
+
+<h2>Usage</h2>
+
+<p><code>bash
+lein deps
+lein ring server
+</code></p>
+
+<h2>License</h2>
+
+<p>Copyright (C) 2011 Peter Stillman</p>
+
+<p>Distributed under the <a href="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html" title="Gnu Public License version 2.0">Gnu Public License version 2.0</a>.</p>
10 project.clj
@@ -0,0 +1,10 @@
+(defproject trivial-noir "0.1.0-SNAPSHOT"
+ :description "this is a very simple test of noir"
+ :dependencies [[org.clojure/clojure "1.3.0"]
+ [noir "1.2.1"]
+ [congomongo "0.1.7"]]
+ :dev-dependencies [[lein-ring "0.4.6"]]
+ :ring {:handler trivial-noir.server/handler}
+ :main trivial-noir.server)
+
+
57 resources/public/css/reset.css
@@ -0,0 +1,57 @@
+html {
+ margin:0;
+ padding:0;
+ border:0;
+}
+
+body, div, span, object, iframe,
+h1, h2, h3, h4, h5, h6, p, blockquote, pre,
+a, abbr, acronym, address, code,
+del, dfn, em, img, q, dl, dt, dd, ol, ul, li,
+fieldset, form, label, legend,
+table, caption, tbody, tfoot, thead, tr, th, td,
+article, aside, dialog, figure, footer, header,
+hgroup, nav, section {
+ margin: 0;
+ padding: 0;
+ border: 0;
+ font-weight: inherit;
+ font-style: inherit;
+ font-size: 100%;
+ font-family: inherit;
+ vertical-align: baseline;
+}
+
+article, aside, dialog, figure, footer, header,
+hgroup, nav, section {
+ display:block;
+}
+
+body {
+ line-height: 1.5;
+ background: white;
+}
+
+table {
+ border-collapse: separate;
+ border-spacing: 0;
+}
+
+caption, th, td {
+ text-align: left;
+ font-weight: normal;
+ float:none !important;
+}
+table, th, td {
+ vertical-align: middle;
+}
+
+blockquote:before, blockquote:after, q:before, q:after { content: ''; }
+blockquote, q { quotes: "" ""; }
+
+a img { border: none; }
+
+/*:focus { outline: 0; }*/
+
+
+
18 src/trivial_noir/db/mongo.clj
@@ -0,0 +1,18 @@
+(ns trivial-noir.db.mongo
+ (:use somnium.congomongo)
+ (:use [somnium.congomongo.config :only [*mongo-config*]]))
+
+(defn maybe-init []
+ "Checks if connection and collection exist, otherwise initialize."
+ (when (not (connection? *mongo-config*))
+ (let [config {:db "yoctoplasm_development"
+ :host "localhost"
+ :port "27017"}]
+ (mongo! :db (:db config) :host (:host config) :port (Integer. (:port config)))
+ (if (not (or (nil? (:user config)) (nil? (:pass config))))
+ (authenticate (:user config) (:pass config))))))
+
+(defmacro with-db-conn [& body]
+ `(do
+ (maybe-init)
+ ~@body))
14 src/trivial_noir/server.clj
@@ -0,0 +1,14 @@
+(ns trivial-noir.server
+ (:require [noir.server :as server]))
+
+(server/load-views "src/trivial_noir/views/")
+
+(def handler (server/gen-handler {:mode :dev
+ :ns 'trivial-noir}))
+
+;; (defn -main [& m]
+;; (let [mode (keyword (or (first m) :dev))
+;; port (Integer. (get (System/getenv) "PORT" "8080"))]
+;; (server/start port {:mode mode
+;; :ns 'trivial-noir})))
+
13 src/trivial_noir/views/common.clj
@@ -0,0 +1,13 @@
+(ns trivial-noir.views.common
+ (:use [noir.core :only [defpartial]]
+ [hiccup.page-helpers :only [include-css html5]]))
+
+(defpartial layout [& content]
+ (html5
+ [:head [:title "trivial-noir"] (include-css "/css/reset.css")]
+ [:body [:div#wrapper content]]))
+
+(defpartial site-layout [& content]
+ (html5
+ [:head [:title "Trivial Noir"]]
+ [:body [:div#wrapper content]]))
15 src/trivial_noir/views/welcome.clj
@@ -0,0 +1,15 @@
+(ns trivial-noir.views.welcome
+ (:require [trivial-noir.views.common :as common])
+ (:use [noir.core :only [defpage]]
+ [hiccup.core :only [html]]
+ [trivial-noir.db.mongo :only [with-db-conn]])
+ (:use somnium.congomongo))
+
+
+
+(defpage "/frontpage" []
+ (with-db-conn
+ (let [text ((fetch-one :docs :where { :slug "zombie" }) :text)]
+ (common/site-layout
+ [:h1 "Front Page!"]
+ [:p text]))))
Please sign in to comment.
Something went wrong with that request. Please try again.