Skip to content

Commit 0df0fc4

Browse files
committed
Merge commit 'e4fb5ab'
2 parents 6cece2e + e4fb5ab commit 0df0fc4

File tree

8 files changed

+71
-79
lines changed

8 files changed

+71
-79
lines changed

Procfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
web: java -Djava.security.policy=example.policy $JVM_OPTS -cp target/tryclojure-standalone.jar clojure.main -m tryclojure.server
1+
web: java -Djava.security.policy=example.policy $JVM_OPTS -cp target/tryclojure-standalone.jar clojure.main -m tryclojure.server $PORT

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ TryClojure is a online Clojure REPL written using Noir and Chris Done's jquery c
88

99
http://tryclj.com
1010

11-
To run it locally, use `lein run`.
11+
To run it locally, use `lein ring server`.
1212

1313
## Credits
1414

project.clj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
(defproject tryclojure "0.1.0-SNAPSHOT"
22
:description "A simple web-based Clojure REPL for trying out Clojure without having to install it."
33
:dependencies [[org.clojure/clojure "1.4.0"]
4-
[noir "1.3.0-beta10"]
4+
[lib-noir "0.8.1"]
5+
[compojure "1.1.6"]
6+
[ring-server "0.3.1"]
57
[commons-lang/commons-lang "2.5"]
68
[clojail "1.0.6"]]
79
:jvm-opts ["-Djava.security.policy=example.policy" "-Xmx80M"]
810
:min-lein-version "2.0.0"
911
:uberjar-name "tryclojure-standalone.jar"
10-
:main tryclojure.server)
12+
:plugins [[lein-ring "0.8.10"]]
13+
:ring {:handler tryclojure.server/app :port 8801})

resources/public/css/tryclojure.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ body {
2020
#header h1 {
2121
height: 72px;
2222
line-height: 72px;
23-
background: url(/resources/public/clojure-logo.png) no-repeat;
23+
background: url(../clojure-logo.png) no-repeat;
2424
margin: 0;
2525
padding: 0;
2626
padding-left: 75px;

src/tryclojure/server.clj

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
(ns tryclojure.server
2-
(:require [noir.server :as server]
3-
[ring.middleware.file :refer [wrap-file]]))
2+
(:use compojure.core)
3+
(:require [compojure.route :as route]
4+
[noir.util.middleware :as nm]
5+
[ring.adapter.jetty :as jetty]
6+
[tryclojure.views.home :as home]
7+
[tryclojure.views.tutorial :as tutorial]
8+
[tryclojure.views.eval :as eval]))
49

5-
(server/add-middleware wrap-file (System/getProperty "user.dir"))
6-
(server/load-views "src/tryclojure/views")
10+
(def app-routes
11+
[(GET "/" [] (home/root-html))
12+
(GET "/about" [] (home/about-html))
13+
(GET "/links" [] (home/links-html))
14+
(POST "/tutorial" [:as {args :params}] (tutorial/tutorial-html (args :page)))
15+
(POST "/eval.json" [:as {args :params}] (eval/eval-json (args :expr) (args :jsonp)))
16+
(GET "/eval.json" [:as {args :params}] (eval/eval-json (args :expr) (args :jsonp)))
17+
(route/resources "/")
18+
(route/not-found "Not Found")])
719

8-
(defn to-port [s]
9-
(when-let [port s] (Long. port)))
20+
(def app (nm/app-handler app-routes))
1021

11-
(defn tryclj [& [port]]
12-
(server/start
13-
(or (to-port port)
14-
(to-port (System/getenv "PORT")) ;; For deploying to Heroku
15-
8801)
16-
{:session-cookie-attrs {:max-age 600}}))
17-
18-
(defn -main [& args] (tryclj (first args)))
22+
(defn -main [port]
23+
(jetty/run-jetty app {:port (Long. port) :join? false}))

src/tryclojure/views/eval.clj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
(ns tryclojure.views.eval
2-
(:require [noir.core :refer [defpage]]
3-
[tryclojure.models.eval :refer [eval-request]]
2+
(:require [tryclojure.models.eval :refer [eval-request]]
43
[noir.response :as resp]))
54

6-
(defpage "/eval.json" {:keys [expr jsonp]}
5+
(defn eval-json [expr jsonp]
76
(let [{:keys [expr result error message] :as res} (eval-request expr)
87
data (if error
98
res

src/tryclojure/views/home.clj

Lines changed: 40 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,55 @@
11
(ns tryclojure.views.home
2-
(:require [noir.core :refer [defpartial defpage]]
3-
[hiccup.element :refer [javascript-tag link-to unordered-list]]
4-
[hiccup.page :refer [include-css include-js html5]]))
2+
(:require [hiccup.element :refer [javascript-tag link-to unordered-list]]
3+
[hiccup.page :refer [include-css include-js html5]]
4+
[hiccup.core :refer [html]]))
55

6-
(defpartial links-html []
7-
(unordered-list
8-
[(link-to "http://clojure.org" "The official Clojure website")
9-
(link-to "http://clojure-doc.org/" "Clojure tutorials and documentation")
10-
(link-to "http://groups.google.com/group/clojure" "Clojure mailing list")
11-
(link-to "http://joyofclojure.com/" "The Joy of Clojure: a book by Michael Fogus and Chris Houser")
12-
(link-to "http://disclojure.org" "Disclojure")
13-
(link-to "http://planet.clojure.in" "Planet Clojure")]))
6+
(defn links-html []
7+
(html
8+
(unordered-list
9+
[(link-to "http://clojure.org" "The official Clojure website")
10+
(link-to "http://clojure-doc.org/" "Clojure tutorials and documentation")
11+
(link-to "http://groups.google.com/group/clojure" "Clojure mailing list")
12+
(link-to "http://joyofclojure.com/" "The Joy of Clojure: a book by Michael Fogus and Chris Houser")
13+
(link-to "http://disclojure.org" "Disclojure")
14+
(link-to "http://planet.clojure.in" "Planet Clojure")])))
1415

15-
(defpartial about-html []
16-
[:p.bottom
17-
"Welcome to Try Clojure - a quick tour of Clojure for absolute beginners."
18-
]
19-
[:p.bottom
20-
"Here is our only disclaimer: this site is an introduction to Clojure, not a generic Clojure REPL. "
21-
"You won't be able to do everything in it that you could do in your local interpreter. "
22-
"Also, the interpreter deletes the data that you enter if you define too many things, or after 15 minutes."]
23-
[:p.bottom
24-
"TryClojure is written in Clojure and JavaScript with "
25-
(link-to "http://webnoir.org" "Noir") ", "
26-
(link-to "https://github.com/flatland/clojail" "clojail") ", and Chris Done's "
27-
(link-to "https://github.com/chrisdone/jquery-console" "jquery-console") ". "
28-
" The design is by " (link-to "http://apgwoz.com" "Andrew Gwozdziewycz") "."
29-
])
16+
(defn about-html []
17+
(html
18+
[:p.bottom
19+
"Welcome to Try Clojure - a quick tour of Clojure for absolute beginners."]
20+
[:p.bottom
21+
"Here is our only disclaimer: this site is an introduction to Clojure, not a generic Clojure REPL. "
22+
"You won't be able to do everything in it that you could do in your local interpreter. "
23+
"Also, the interpreter deletes the data that you enter if you define too many things, or after 15 minutes."]
24+
[:p.bottom
25+
"TryClojure is written in Clojure and JavaScript with "
26+
(link-to "https://github.com/weavejester/compojure" "Compojure") ", "
27+
(link-to "https://github.com/noir-clojure/lib-noir" "lib-noir") ", "
28+
(link-to "https://github.com/flatland/clojail" "clojail") ", and Chris Done's "
29+
(link-to "https://github.com/chrisdone/jquery-console" "jquery-console") ". "
30+
" The design is by " (link-to "http://apgwoz.com" "Andrew Gwozdziewycz") "."]))
3031

31-
(defpartial home-html []
32-
[:p.bottom
33-
"Welcome to Clojure! "
34-
"You can see a Clojure interpreter above - we call it a <em>REPL</em>."
35-
]
36-
[:p.bottom
37-
"Type <code>next</code> in the REPL to begin."
38-
])
32+
(defn home-html []
33+
(html
34+
[:p.bottom
35+
"Welcome to Clojure! "
36+
"You can see a Clojure interpreter above - we call it a <em>REPL</em>."]
37+
[:p.bottom "Type <code>next</code> in the REPL to begin." ]))
3938

4039
(defn root-html []
4140
(html5
4241
[:head
43-
(include-css "/resources/public/css/tryclojure.css"
44-
"/resources/public/css/gh-fork-ribbon.css")
42+
(include-css "/css/tryclojure.css"
43+
"/css/gh-fork-ribbon.css")
4544
(include-js "http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"
46-
"/resources/public/javascript/jquery-console/jquery.console.js"
47-
"/resources/public/javascript/tryclojure.js")
45+
"/javascript/jquery-console/jquery.console.js"
46+
"/javascript/tryclojure.js")
4847
[:title "Try Clojure"]]
4948
[:body
5049
[:div#wrapper
51-
[:div.github-fork-ribbon-wrapper.right
52-
[:div.github-fork-ribbon
53-
(link-to "https://github.com/Raynes/tryclojure" "Fork me on GitHub")
54-
]
55-
]
50+
[:div.github-fork-ribbon-wrapper.right
51+
[:div.github-fork-ribbon
52+
(link-to "https://github.com/Raynes/tryclojure" "Fork me on GitHub")]]
5653
[:div#content
5754
[:div#header
5855
[:h1
@@ -77,14 +74,3 @@
7774
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
7875
})();")]]]))
7976

80-
(defpage "/" []
81-
(root-html))
82-
83-
(defpage "/home" []
84-
(home-html))
85-
86-
(defpage "/about" []
87-
(about-html))
88-
89-
(defpage "/links" []
90-
(links-html))

src/tryclojure/views/tutorial.clj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
(ns tryclojure.views.tutorial
2-
(:require [noir.core :refer [defpage]]))
1+
(ns tryclojure.views.tutorial)
32

4-
(defpage [:post "/tutorial"] {page :page}
3+
(defn tutorial-html [page]
54
(slurp (str "resources/public/tutorial/" page ".html")))

0 commit comments

Comments
 (0)