Commits

yongchao li committed 10ee558

format code

Comments (0)

Files changed (7)

   :license {:name "Eclipse Public License"
             :url "http://www.eclipse.org/legal/epl-v10.html"}
   :dependencies [[org.clojure/clojure "1.4.0"]
-  							[mysql/mysql-connector-java "5.1.6"]
-  							[org.clojure/java.jdbc "0.2.2"]
-  							[ring/ring-jetty-adapter "1.1.0"]
-  							[compojure "1.1.0"]
-  							[hiccup "1.0.0"]])
+                 [mysql/mysql-connector-java "5.1.6"]
+                 [org.clojure/java.jdbc "0.2.2"]
+                 [ring/ring-jetty-adapter "1.1.0"]
+                 [compojure "1.1.0"]
+                 [hiccup "1.0.0"]])

src/shouter/controllers/shouts.clj

 (ns shouter.controllers.shouts
-	(:use [compojure.core :only [defroutes GET POST]])
-	(:require [clojure.string :as str]
-						[ring.util.response :as ring]
-						[shouter.views.shouts :as view]
-						[shouter.models.shout :as model]))
+  (:use [compojure.core :only [defroutes GET POST]])
+  (:require [clojure.string :as str]
+            [ring.util.response :as ring]
+            [shouter.views.shouts :as view]
+            [shouter.models.shout :as model]))
 
 (defn index []
-	(view/index (model/all)))
+  (view/index (model/all)))
 
 (defn create [params]
-	(let [shout (:shout params)]
-		(when-not (str/blank? shout)
-			(model/create shout)))
-	(ring/redirect "/"))
+  (let [shout (:shout params)]
+    (when-not (str/blank? shout)
+      (model/create shout)))
+  (ring/redirect "/"))
 
 (defroutes routes
-	(GET "/" [] (index))
-	(POST "/" {params :params} (create params)))
+           (GET "/" [] (index))
+           (POST "/" {params :params} (create params)))

src/shouter/core.clj

             [shouter.views.layout :as layout]))
 
 (defroutes routes
-  shouter.controllers.shouts/routes
-  (route/resources "/")
-  (route/not-found (layout/four-oh-four)))
+           shouter.controllers.shouts/routes
+           (route/resources "/")
+           (route/not-found (layout/four-oh-four)))
 
 (def application (handler/site routes))
 

src/shouter/models/migration.clj

 (ns shouter.models.migration
-	(:require [clojure.java.jdbc :as sql]))
+  (:require [clojure.java.jdbc :as sql]))
 
 (def db-spec "mysql://root:abc123@localhost:3306/test")
 
 (defn create-shouts []
 	(sql/with-connection db-spec
 		(sql/create-table :shouts
-											[:id :integer "PRIMARY KEY" "AUTO_INCREMENT"]
-											[:body "varchar(255)" "NOT NULL"]
-											[:created_at :timestamp "NOT NULL" "DEFAULT CURRENT_TIMESTAMP"])))
+                    [:id :integer "PRIMARY KEY" "AUTO_INCREMENT"]
+                    [:body "varchar(255)" "NOT NULL"]
+                    [:created_at :timestamp "NOT NULL" "DEFAULT CURRENT_TIMESTAMP"])))
 
 (defn -main []
-	(println "Migration database....") (flush)
-	(create-shouts)
-	(println "done"))
+  (println "Migration database....") (flush)
+  (create-shouts)
+  (println "done"))

src/shouter/models/shout.clj

 
 (defn all []
   (sql/with-connection db-spec
-    (sql/with-query-results results
-      ["select * from shouts order by id desc"]
-      (into [] results))))
+                       (sql/with-query-results results
+                                               ["select * from shouts order by id desc"]
+                                               (into [] results))))
 
 (defn create [shout]
-  (sql/with-connection db-spec
-    (sql/insert-values :shouts [:body] [shout])))
+  (sql/with-connection db-spec 
+                       (sql/insert-values :shouts [:body] [shout])))

src/shouter/views/layout.clj

 (ns shouter.views.layout
-	(:use [hiccup.page :only [html5]]))
+  (:use [hiccup.page :only [html5]]))
 
 (defn common [title & body]
-	(html5
-		[:head
-			[:meta {:http-equiv "Content-Type" :content "text/html; charset=utf-8"}]
-			[:title title]
-		]
-		[:body
-			[:div {:id "header"}
-				[:h1 "大喊"]]
-			[:div {:id "content"} body]]))
+  (html5
+    [:head
+     [:meta {:http-equiv "Content-Type" :content "text/html; charset=utf-8"}]
+     [:title title]]
+    [:body
+     [:div {:id "header"}
+      [:h1 "大喊"]]
+     [:div {:id "content"} body]]))
 
 (defn four-oh-four []
-	(common "Page Not Found"
-					[:div {:id "four-oh-four"}
-					"The page you requested could not be found"]))
+  (common "Page Not Found"
+          [:div {:id "four-oh-four"}
+           "The page you requested could not be found"]))

src/shouter/views/shouts.clj

 (ns shouter.views.shouts
-	(:use [hiccup.core :only [h]]
-				[hiccup.form :only [form-to label text-field submit-button]])
-	(:require [shouter.views.layout :as layout]))
+  (:use [hiccup.core :only [h]]
+        [hiccup.form :only [form-to label text-field submit-button]])
+  (:require [shouter.views.layout :as layout]))
 
 (defn shout-form []
   [:div {:id "shout-form"}
 
 (defn display-shouts [shouts]
   [:div {:id "shouts sixteen columns alpha omega"}
-   (map
-    (fn [shout] [:h2 (h (:body shout))])
-    shouts)])
+   (map (fn [shout] [:h2 (h (:body shout))]) shouts)])
 
 (defn index [shouts]
   (layout/common "大喊"