Skip to content

Commit

Permalink
Doc and example tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcgrana committed Feb 23, 2010
1 parent 7271607 commit f2f4229
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2009 Mark McGranaghan Copyright (c) 2009-2010 Mark McGranaghan


Permission is hereby granted, free of charge, to any person Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation obtaining a copy of this software and associated documentation
Expand Down
14 changes: 7 additions & 7 deletions README.markdown
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ A Ring handler:


Adding simple middleware: Adding simple middleware:


(defn with-upcase [app] (defn wrap-upcase [app]
(fn [req] (fn [req]
(let [orig-resp (app req)] (let [orig-resp (app req)]
(assoc orig-resp :body (.toUpperCase (:body orig-resp)))))) (assoc orig-resp :body (.toUpperCase (:body orig-resp))))))


(def upcase-app (with-upcase app)) (def upcase-app (wrap-upcase app))


(run-jetty upcase-app {:port 8080}) (run-jetty upcase-app {:port 8080})


Expand All @@ -36,15 +36,15 @@ First, pull in Ring's dependencies using [Leiningen](http://github.com/technoman


To see a live "Hello World" Ring app, run: To see a live "Hello World" Ring app, run:


$ clj src/ring/example/hello_world.clj $ clj example/hello_world.clj


Now visit `http://localhost:8080/` in your browser; the Ring app will respond to your request with a simple HTML page indicating the time of day. Now visit `http://localhost:8080/` in your browser; the Ring app will respond to your request with a simple HTML page indicating the time of day.


Note that your `clj` script needs to add the `src` directory and the jars in `lib` to your classpath. Note that your `clj` script needs to add the `src` directory and the jars in `lib` to your classpath.


To see a more sophisticated Ring app, run: To see a more sophisticated Ring app, run:


$ clj src/ring/example/wrapping.clj $ clj example/wrapping.clj


* If you request `http://localhost:8080/` in your browser the `ring.handler.dump` handler will respond with an HTML page representing the request map that it received (see the `SPEC` for details on the request map). * If you request `http://localhost:8080/` in your browser the `ring.handler.dump` handler will respond with an HTML page representing the request map that it received (see the `SPEC` for details on the request map).
* If you request `http://localhost:8080/clojure.png`, the `ring.middleware.file` middleware will detect that there is a `clojure.png` file in the app's `public` directory and return that image as a response. * If you request `http://localhost:8080/clojure.png`, the `ring.middleware.file` middleware will detect that there is a `clojure.png` file in the app's `public` directory and return that image as a response.
Expand All @@ -68,11 +68,11 @@ Included Libs
Development Development
----------- -----------


Ring is being actively developed; you can track its progress and contribute at the project's [GitHub](http://github.com/mmcgrana/ring) page. Ring is being actively developed; you can track its progress and contribute at the project's [GitHub page](http://github.com/mmcgrana/ring) and [Google Group](http://groups.google.com/group/ring-clojure).


To run all the Ring unit tests: To run all the Ring unit tests:


$ clj test/ring/run.clj $ lein test


Thanks Thanks
------ ------
Expand All @@ -82,6 +82,6 @@ This project borrows heavily from Ruby's Rack and Python's WSGI, and I thank the
License License
------- -------


Copyright (c) 2009 Mark McGranaghan and released under an MIT license. Copyright (c) 2009-2010 Mark McGranaghan and released under an MIT license.


Clojure logo by Tom Hickey. Clojure logo by Tom Hickey.
5 changes: 2 additions & 3 deletions example/hello_world.clj
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
(:use ring.adapter.jetty) (:use ring.adapter.jetty)
(:import java.util.Date java.text.SimpleDateFormat)) (:import java.util.Date java.text.SimpleDateFormat))


(def formatter (SimpleDateFormat. "HH:mm:ss"));

(defn app (defn app
[req] [req]
{:status 200 {:status 200
:headers {"Content-Type" "text/html"} :headers {"Content-Type" "text/html"}
:body (str "<h3>Hello World from Ring</h3>" :body (str "<h3>Hello World from Ring</h3>"
"<p>The current time is " "<p>The current time is "
(.format formatter (Date.)) ".</p>")}) (.format (SimpleDateFormat. "HH:mm:ss") (Date.))
".</p>")})


(run-jetty app {:port 8080}) (run-jetty app {:port 8080})
8 changes: 4 additions & 4 deletions example/linted.clj
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
wrap-lint wrap-lint
wrap-file-info wrap-file-info
wrap-lint wrap-lint
(wrap-file "src/ring/example/public") (wrap-file "example/public")
wrap-lint wrap-lint
(wrap-reload '(ring.dump) (wrap-reload '(ring.handler.dump))
wrap-lint))) wrap-lint))


(run-jetty app {:port 8080}) (run-jetty app {:port 8080})
Binary file modified example/public/clojure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion example/wrapping.clj
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
(def app (def app
(-> handle-dump (-> handle-dump
wrap-error wrap-error
(wrap-file "src/ring/example/public") (wrap-file "example/public")
wrap-file-info wrap-file-info
wrap-stacktrace)) wrap-stacktrace))


Expand Down
2 changes: 1 addition & 1 deletion src/ring/middleware/file_info.clj
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@


(defn- get-extension (defn- get-extension
"Returns the file extension of a file." "Returns the file extension of a file."
[file] [#^File file]
(second (re-find #"\.([^./\\]+)$" (.getPath file)))) (second (re-find #"\.([^./\\]+)$" (.getPath file))))


(defn- guess-mime-type (defn- guess-mime-type
Expand Down

0 comments on commit f2f4229

Please sign in to comment.