Skip to content

Commit

Permalink
Fixed traling whitespaces and misplaced newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronsa committed Jan 15, 2012
1 parent 4ac12ae commit d81700f
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 93 deletions.
12 changes: 4 additions & 8 deletions src/noir/content/defaults.clj
@@ -1,4 +1,4 @@
(ns
(ns
#^{:skip-wiki true}
noir.content.defaults
(:use noir.core
Expand Down Expand Up @@ -29,8 +29,7 @@
(min-noir-layout
[:div#not-found
[:h1 "We seem to have lost that one."]
[:p "Since we couldn't find the page you were looking for, check to make sure the address is correct."]]
))
[:p "Since we couldn't find the page you were looking for, check to make sure the address is correct."]]))

(defpartial exception-item [{nams :ns in-ns? :in-ns? fq :fully-qualified f :file line :line :as ex}]
[:tr {:class (when in-ns?
Expand All @@ -48,14 +47,11 @@
(try
[:h3 "Caused by: " (:class cause) " - " (:message cause)]
[:table (map exception-item (:trimmed-elems cause))]
(catch Throwable e))])]
))
(catch Throwable e))])]))

(defpartial internal-error []
(min-noir-layout
[:div#not-found
[:h1 "Something very bad has happened."]
[:p "We've dispatched a team of highly trained gnomes to take
[:p "We've dispatched a team of highly trained gnomes to take
care of the problem."]]))


21 changes: 9 additions & 12 deletions src/noir/content/getting_started.clj
@@ -1,4 +1,4 @@
(ns
(ns
#^{:skip-wiki true}
noir.content.getting-started
(:use noir.core
Expand All @@ -20,7 +20,7 @@
(link-to "http://www.webnoir.org/" (image "/img/noir-logo.png" "Noir")))

(defpartial header []
[:div#header
[:div#header
[:h1 (logo)]
[:ul
(map link-item header-links)]])
Expand All @@ -33,36 +33,36 @@
[:li
[:div.right
[:pre
[:code
[:code
"(defpage \"/my-page\" []
(html
[:h1 \"This is my first page!\"]))"]]]
[:div.left
[:p "Time to get going with our first page. Let's open views/welcome.clj
[:p "Time to get going with our first page. Let's open views/welcome.clj
and use (defpage) to add a new page to our site. With that we can go to "
(link-to "http://localhost:8080/my-page" "http://localhost:8080/my-page")
" and see our handiwork."]]]

[:li
[:div.right
[:pre
[:code
[:code
"(defpartial site-layout [& content]
(html5
[:head
[:title \"my site\"]]
[:body
[:div#wrapper
content]]))"] ]]
content]]))"]]]
[:div.left
[:p "We really need a layout for all our pages, so let's create a
[:p "We really need a layout for all our pages, so let's create a
partial (a function that returns html). We'll do that
in views/common.clj since all your views will use it."]]]

[:li
[:div.right
[:pre
[:code
[:code
"(defpage \"/my-page\" []
(common/site-layout
[:h1 \"Welcome to my site!\"]
Expand All @@ -76,7 +76,4 @@
[:code "[noir.content.getting-started]"]]
[:div.left
[:p "That's it! You've created your own page. Now get rid of this one simply by
removing the require for getting-started at the top."]]]

]
))
removing the require for getting-started at the top."]]]]))
10 changes: 5 additions & 5 deletions src/noir/cookies.clj
Expand Up @@ -7,7 +7,7 @@
(declare ^:dynamic *cur-cookies*)
(declare ^:dynamic *new-cookies*)

(defn put!
(defn put!
"Add a new cookie whose name is k and has the value v. If v is a string
a cookie map is created with :path '/'. To set custom attributes, such as
\"expires\", provide a map as v. Stores all keys as strings."
Expand All @@ -22,9 +22,9 @@
If this is a signed cookie, use get-signed, otherwise the signature will not be
checked."
([k] (get k nil))
([k default]
([k default]
(let [str-k (name k)]
(if-let [v (or (get-in @*new-cookies* [str-k :value])
(if-let [v (or (get-in @*new-cookies* [str-k :value])
(get-in *cur-cookies* [str-k :value]))]
v
default))))
Expand All @@ -39,10 +39,10 @@
should be a secret that's user-wide, session-wide or site wide (worst)."
[sign-key k v]
(let [actual-v (if (map? v) (:value v) v)]
(put! k v)
(put! k v)
(put! (signed-name k)
(let [signed-v (crypt/sha1-sign-hex sign-key actual-v)]
(if (map? v) ;; If previous value was a map with other attributes,
(if (map? v) ;; If previous value was a map with other attributes,
(assoc v :value signed-v) ;; Place the signed value in a similar map,
signed-v))))) ;; Otherwise just signed value.

Expand Down
14 changes: 7 additions & 7 deletions src/noir/core.clj
Expand Up @@ -26,15 +26,15 @@

(defn- parse-fn-name [[cur :as all]]
(let [[fn-name remaining] (if (and (symbol? cur)
(or (@route-funcs (keyword (name cur)))
(or (@route-funcs (keyword (name cur)))
(not (resolve cur))))
[cur (rest all)]
[nil all])]
[{:fn-name fn-name} remaining]))

(defn- parse-route [[{:keys [fn-name] :as result} [cur :as all]] default-action]
(let [cur (if (symbol? cur)
(try
(try
(deref (resolve cur))
(catch Exception e
(throwf "Symbol given for route has no value")))
Expand All @@ -59,7 +59,7 @@
(assoc :destruct cur)
(assoc :body (rest all))))

(defn ^{:skip-wiki true} parse-args
(defn ^{:skip-wiki true} parse-args
"parses the arguments to defpage. Returns a map containing the keys :name :action :url :destruct :body"
[args & [default-action]]
(-> args
Expand All @@ -68,7 +68,7 @@
(parse-destruct-body)))

(defn ^{:skip-wiki true} route->name
"Parses a set of route args into the keyword name for the route"
"Parses a set of route args into the keyword name for the route"
[route]
(cond
(keyword? route) route
Expand Down Expand Up @@ -106,7 +106,7 @@
(html
~@body)))

(defn ^{:skip-wiki true} route-arguments
(defn ^{:skip-wiki true} route-arguments
"returns the list of route arguments in a route"
[route]
(let [args (re-seq #"/(:([^\/]+)|\*)" route)]
Expand All @@ -121,7 +121,7 @@
(throwf "Missing route-args %s" (vec (filter #(not (contains? route-args %)) route-arg-names))))
(reduce (fn [path [k v]]
(if (= k :*)
(string/replace path "*" (str v))
(string/replace path "*" (str v))
(string/replace path (str k) (str v))))
url
route-args)))
Expand Down Expand Up @@ -170,7 +170,7 @@
(pre-route '/admin/*' {} (when-not (is-admin?) (redirect '/login')))"
[& args]
(let [{:keys [action destruct url body]} (parse-args args 'compojure.core/ANY)
safe-url (if (vector? url)
safe-url (if (vector? url)
(first url)
url)]
`(swap! pre-routes assoc ~safe-url (~action ~url {:as request#} ((fn [~destruct] ~@body) request#)))))
Expand Down
12 changes: 5 additions & 7 deletions src/noir/exception.clj
Expand Up @@ -5,7 +5,7 @@
(:require [clojure.string :as string]
[noir.options :as options]
[noir.statuses :as statuses]
[noir.content.defaults :as defaults]))
[noir.content.defaults :as defaults]))

(defn- route-fn? [k]
(and k
Expand Down Expand Up @@ -33,8 +33,7 @@
(str (:method ex) "." (:class ex)))
in-ns? (and nams (re-seq
(re-pattern (str (options/get :ns)))
nams))
]
nams))]
{:fn func-name
:ns nams
:in-ns? in-ns?
Expand All @@ -43,15 +42,14 @@
:clj? clj?
:file f
:line line}))

(defn parse-ex [ex]
(let [clj-parsed (iterate :cause (parse-exception ex))
exception (first clj-parsed)
causes (rest clj-parsed)]
{:exception (assoc exception :trace-elems (map ex-item (:trace-elems exception)))
:causes (for [cause causes :while cause]
(assoc cause :trimmed-elems (map ex-item (:trimmed-elems cause))))}
))
(assoc cause :trimmed-elems (map ex-item (:trimmed-elems cause))))}))

(defn wrap-exceptions [handler]
(fn [request]
Expand All @@ -60,7 +58,7 @@
(catch Exception e
(.printStackTrace e)
(let [content (if (options/dev-mode?)
(try
(try
(defaults/stack-trace (parse-ex e))
(catch Throwable e
(statuses/get-page 500)))
Expand Down
5 changes: 2 additions & 3 deletions src/noir/options.clj
Expand Up @@ -12,7 +12,7 @@
(merge default-opts opts)
default-opts))

(defn get
(defn get
"Get an option from the noir options map"
([k default]
(clojure.core/get *options* k default))
Expand All @@ -22,7 +22,7 @@
(defn resolve-url [url]
(str (get :base-url "") url))

(defn dev-mode?
(defn dev-mode?
"Returns if the server is currently in development mode"
[]
(= (get :mode) :dev))
Expand All @@ -32,4 +32,3 @@
(fn [request]
(binding [*options* final-opts]
(handler request)))))

2 changes: 1 addition & 1 deletion src/noir/request.clj
Expand Up @@ -3,7 +3,7 @@

(declare ^{:dynamic true} *request*)

(defn ring-request
(defn ring-request
"Returns back the current ring request map"
[]
*request*)
Expand Down
11 changes: 5 additions & 6 deletions src/noir/response.clj
Expand Up @@ -4,7 +4,7 @@
(:require [cheshire.core :as json]
[noir.options :as options]))

(defn xml
(defn xml
"Wraps the response with the content type for xml and sets the body to the content."
[content]
{:headers {"Content-Type" "text/xml"}
Expand All @@ -16,20 +16,20 @@
{:headers {"Content-Type" ctype}
:body content})

(defn json
(defn json
"Wraps the response in the json content type and generates JSON from the content"
[content]
{:headers {"Content-Type" "application/json"}
:body (json/generate-string content)})

(defn jsonp
"Generates JSON for the given content and creates a javascript response for calling
"Generates JSON for the given content and creates a javascript response for calling
func-name with it."
[func-name content]
{:headers {"Content-Type" "application/javascript"}
:body (str func-name "(" (json/generate-string content) ");")})

(defn status
(defn status
"Wraps the content in the given status code"
[code content]
{:status code
Expand All @@ -42,9 +42,8 @@
:headers {"Location" (options/resolve-url url)}
:body ""})

(defn empty
(defn empty
"Return a successful, but completely empty response"
[]
{:status 200
:body ""})

4 changes: 2 additions & 2 deletions src/noir/server.clj
Expand Up @@ -49,7 +49,7 @@
use for defpage, func is a ring middleware function, and args are any additional args
to pass to the middleware function. You can wrap the resources and catch-all routes by
supplying the routes :resources and :catch-all respectively:
(wrap-route :resources some-caching-middleware)"
[route middleware & args]
(apply handler/wrap-route route middleware args))
Expand All @@ -61,7 +61,7 @@
:mode - either :dev or :prod
:ns - the root namepace of your project
:jetty-options - any extra options you want to send to jetty like :ssl?
:base-url - the root url to prepend to generated links and resources
:base-url - the root url to prepend to generated links and resources
:resource-root - an alternative name for the public folder
:session-store - an alternate store for session handling
:session-cookie-attrs - custom session cookie attributes"
Expand Down
8 changes: 4 additions & 4 deletions src/noir/session.clj
Expand Up @@ -13,24 +13,24 @@
(declare ^:dynamic *noir-session*)
(defonce mem (atom {}))

(defn put!
(defn put!
"Associates the key with the given value in the session"
[k v]
(clojure.core/swap! *noir-session* assoc k v))

(defn get
(defn get
"Get the key's value from the session, returns nil if it doesn't exist."
([k] (get k nil))
([k default]
(clojure.core/get @*noir-session* k default)))

(defn swap!
(defn swap!
"Replace the current session's value with the result of executing f with
the current value and args."
[f & args]
(apply clojure.core/swap! *noir-session* f args))

(defn clear!
(defn clear!
"Remove all data from the session and start over cleanly."
[]
(reset! *noir-session* {}))
Expand Down
7 changes: 3 additions & 4 deletions src/noir/statuses.clj
Expand Up @@ -8,12 +8,12 @@
(def status-pages (atom {404 (defaults/not-found)
500 (defaults/internal-error)}))

(defn get-page
(defn get-page
"Gets the content to display for the given status code"
[code]
(get @status-pages code))

(defn set-page!
(defn set-page!
"Sets the content to be displayed if there is a response with the given status
code. This is used for custom 404 pages, for example."
[code content]
Expand All @@ -32,10 +32,9 @@
(defn wrap-status-pages [handler]
(fn [request]
(let [{status :status body :body :as resp} (handler request)]
(if (and
(if (and
resp
(not= status 200)
(not body))
(status-response resp)
resp))))

0 comments on commit d81700f

Please sign in to comment.