Skip to content
Browse files

Initial commit

  • Loading branch information...
0 parents commit a915176c94ee4ef50447d0a9ed5bce6641f4eb37 @michaelklishin committed May 26, 2012
13 .gitignore
@@ -0,0 +1,13 @@
+pom.xml
+*jar
+/lib/
+/classes/
+/target/
+tmp/*
+.lein-deps-sum
+.lein-failures
+checkouts/*
+
+config/development.clj
+resources/log4j.properties
+test/resources/blobs/test/*
33 README.md
@@ -0,0 +1,33 @@
+# Example Noir 1.3 web app
+
+This is an example Noir 1.3 project with a bunch of common dependencies (database clients, templating libraries) added.
+
+
+## Usage
+
+With [Leiningen 2]()
+
+``` bash
+lein2 test
+```
+
+It will download all dependencies to the local Maven repository and run a single test there is. To run the app,
+
+``` bash
+lein2 run
+```
+
+and visit [http://localhost:8080](http://localhost:8080) in the browser to see HTML responses. For a sample JSON API response,
+run
+
+``` bash
+curl -H "Accept: application/json" http://localhost:8080/api/ping
+```
+
+
+## License
+
+Copyright (C) 2012 Michael S. Klishin
+
+Distributed under the Eclipse Public License, the same as Clojure.
+
36 project.clj
@@ -0,0 +1,36 @@
+(defproject webapp "0.1.0-SNAPSHOT"
+ :min-lein-version "2.0.0"
+ :description "Just an example of a Noir project with a bunch of database clients, templating libraries and Leiningen plugins"
+ :test-selectors {:default (constantly true)
+ :focus :focus
+ :all (constantly true)}
+ :dependencies [[org.clojure/clojure "1.4.0"]
+ ;; See http://webnoir.com
+ [noir "1.3.0-beta7"]
+ ;; PostgreSQL, JDBC, Korma.
+ ;; See http://sqlkorma.com
+ [korma "0.3.0-beta9"]
+ [postgresql "9.1-901.jdbc4"]
+ ;; selector-based templates, see https://github.com/cgrand/enlive
+ [enlive "1.0.0"]
+ ;; moustache templates
+ [stencil "0.2.0"] ;; or [de.ubercode.clostache/clostache "1.3.0"]
+ ;; see http://clojuremongodb.info
+ [com.novemberain/monger "1.0.0-beta5"]
+ ;; see http://clojureriak.info
+ [com.novemberain/welle "1.0.0"]]
+ ;; commonly used plugins. Typically this would be in ~/.lein/profiles.clj.
+ :profiles {:user {:plugins [[lein-swank "1.4.3"]
+ [lein-difftest "1.3.8"]
+ [lein-pprint "1.0.0"]
+ [lein-ring "0.7.1"]]}}
+ ;; Additional Maven repositories
+ :repositories {"sonatype" {:url "http://oss.sonatype.org/content/repositories/releases"
+ :snapshots false
+ :releases {:checksum :fail :update :always}}
+ "sonatype-snapshots" {:url "http://oss.sonatype.org/content/repositories/snapshots"
+ :snapshots true
+ :releases {:checksum :fail :update :always}}}
+ ;; where to find the -main function
+ :main webapp.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; }*/
+
+
+
11 src/webapp/server.clj
@@ -0,0 +1,11 @@
+(ns webapp.server
+ (:require [noir.server :as server]))
+
+(server/load-views-ns 'webapp.views)
+
+(defn -main [& m]
+ (let [mode (keyword (or (first m) :dev))
+ port (Integer. (get (System/getenv) "PORT" "8080"))]
+ (server/start port {:mode mode
+ :ns 'webapp})))
+
12 src/webapp/views/common.clj
@@ -0,0 +1,12 @@
+(ns webapp.views.common
+ (:use [noir.core :only [defpartial]]
+ [hiccup.page :only [include-css html5]]))
+
+(defpartial layout [& content]
+ (html5
+ [:head
+ [:title "webapp"]
+ (include-css "/css/reset.css")]
+ [:body
+ [:div#wrapper
+ content]]))
8 src/webapp/views/ping.clj
@@ -0,0 +1,8 @@
+(ns webapp.views.ping
+ (:require [noir.response :as r])
+ (:use noir.core))
+
+
+(defpage "/api/ping"
+ []
+ (r/json {:pong true}))
8 src/webapp/views/welcome.clj
@@ -0,0 +1,8 @@
+(ns webapp.views.welcome
+ (:require [webapp.views.common :as common]
+ [noir.content.getting-started])
+ (:use [noir.core :only [defpage]]))
+
+(defpage "/welcome" []
+ (common/layout
+ [:p "Welcome to webapp"]))
11 test/webapp/basic_test.clj
@@ -0,0 +1,11 @@
+(ns webapp.basic-test
+ (:use clojure.test
+ webapp.server
+ noir.util.test))
+
+
+
+(deftest test-ping
+ (-> (send-request "/api/ping" {})
+ (has-status 200)
+ (has-content-type "application/json; charset=utf-8")))

0 comments on commit a915176

Please sign in to comment.
Something went wrong with that request. Please try again.