Skip to content
Browse files

Merge branch 'release/1.1.3'

  • Loading branch information...
2 parents d44f9bd + 11f0480 commit 452528169f58b92621aade5c6a97d79353c61b79 @amalloy amalloy committed Aug 7, 2011
View
2 project.clj
@@ -1,4 +1,4 @@
-(defproject foreclojure "1.1.2"
+(defproject foreclojure "1.1.3"
:description "4clojure - a website for lisp beginners"
:dependencies [[clojure "1.2.1"]
[clojure-contrib "1.2.0"]
View
35 resources/public/script/foreclojure.js
@@ -35,7 +35,7 @@ function configureDataTables(){
null,
null,
null,
- null
+ { "sType": "string" }
]
} );
@@ -67,6 +67,12 @@ function setIconColor(element, color, timeOut) {
}, timeOut);
}
+function changeToCodeView() {
+ $('#code-div').show('fast');
+ $('#golfgraph').hide('fast');
+ $('#graph-link').html("View Chart");
+}
+
function configureCodeBox(){
//For no javascript version we have the code-box text area
//If we have javascript on then we remove it and replace it with
@@ -75,7 +81,7 @@ function configureCodeBox(){
var hiddenCodeInput = "<input type=\"hidden\" value=\"blank\" name=\"code\" id=\"code\">";
oldBox.replaceWith("<div id=\"code-div\"> <pre id=\"editor\">" + oldBox.val() + "</pre></div>"+hiddenCodeInput);
- if ($("#run-button").length){
+ if ($("#run-button").length || $("#submission-button").length){
var editor = ace.edit("editor");
editor.setTheme("ace/theme/textmate");
@@ -93,10 +99,6 @@ function configureCodeBox(){
waitTime = waitTimePerItem,
beforeSendCallback = function(data) {
- $("#message-text").text("Executing unit tests...");
- images.each( function(index, element) {
- setIconColor(element, "blue");
- });
var anim = function() {
if(cont) {
images.animate({
@@ -106,10 +108,16 @@ function configureCodeBox(){
setTimeout(anim,animationTime);
}
};
- anim();
+
+ $("#message-text").text("Executing unit tests...");
+ images.each( function(index, element) {
+ setIconColor(element, "blue");
+ });
+ setTimeout(changeToCodeView,0);
+ setTimeout(anim,0);
},
successCallback = function(data) {
- var failingTest = data.failingTest
+ var failingTest = data.failingTest,
getColorFor = function(index) {
return index === failingTest ? "red" : "green";
},
@@ -126,7 +134,7 @@ function configureCodeBox(){
$("#golfgraph").html(data.golfChart);
$("#golfscore").html(data.golfScore);
configureGolf();
- }
+ },
stopAnimation = function() {
cont = false;
images.stop(true);
@@ -164,6 +172,11 @@ function configureCodeBox(){
var text = editor.getSession().getValue();
$('#code').val(text);
});
+
+ $("#submission-button").click(function(){
+ var text = editor.getSession().getValue();
+ $('#code').val(text);
+ });
}
}
@@ -183,8 +196,6 @@ function configureGolf(){
} else {
$('#graph-link').html("View Chart");
}
-
-
-});
+ });
}
View
4 src/foreclojure/login.clj
@@ -127,12 +127,12 @@
(if-let [{id :_id, name :user} (fetch-one :users
:where {:email email}
:only [:_id :user])]
- (let [{:keys [success] :as diagnostics} (? (try-to-email email name id))]
+ (let [{:keys [success] :as diagnostics} (try-to-email email name id)]
(if success
(do (session/session-put! :login-to "/login/update")
(flash-msg "Your password has been reset! You should receive an email soon."
(login-url "/login/update")))
- (do (spit (? (str name ".pwd")) (? diagnostics))
+ (do (spit (str name ".pwd") diagnostics)
(flash-error (str "Something went wrong emailing your new password! Please contact <a href='mailto:team@4clojure.com?subject=Password Reset: " name "'>team@4clojure.com</a> - we'll reset it manually and look into the problem. When you do, please mention your username.")
"/login/reset"))))
(flash-error "We don't know anyone with that email address!"
View
25 src/foreclojure/problems.clj
@@ -22,9 +22,9 @@
(from-mongo
(fetch-one :problems :where {:_id x})))
-(defn get-problem-list
+(defn get-problem-list
([] (get-problem-list {:approved true}))
- ([criteria]
+ ([criteria]
(from-mongo
(fetch :problems
:only [:_id :title :tags :times-solved :user]
@@ -76,6 +76,9 @@
[id]
keyword str int)
+(defn trim-code [code]
+ (when code (.trim code)))
+
(defn code-length [code]
(count (remove #(Character/isWhitespace %)
code)))
@@ -159,10 +162,9 @@
specified id.
Return a map, {:message, :url, :num-tests-passed}."
- [id raw-code]
+ [id code]
(try
- (let [code (.trim raw-code)
- {:keys [tests restricted] :as problem} (get-problem id)
+ (let [{:keys [tests restricted] :as problem} (get-problem id)
sb-tester (get-tester restricted)
user-forms (s/join " " (map pr-str (read-string-safely code)))
results (if (empty? user-forms)
@@ -184,10 +186,11 @@ Return a map, {:message, :url, :num-tests-passed}."
(catch Throwable t {:message (.getMessage t), :url *url*
:num-tests-passed 0})))
-(defn static-run-code [id raw-code]
+(defn static-run-code [id code]
+ (session/flash-put! :code code)
(let [{:keys [message url num-tests-passed]}
(binding [*url* (str *url* "#prob-desc")]
- (run-code id raw-code))]
+ (run-code id code))]
(session/flash-put! :failing-test num-tests-passed)
(flash-msg message url)))
@@ -356,7 +359,7 @@ Return a map, {:message, :url, :num-tests-passed}."
(text-area {:id "code-box" :spellcheck "false"}
:code (session/flash-get :tests))
[:p
- [:button.large {:id "run-button" :type "submit"} "Submit"]]))
+ [:button.large {:id "submission-button" :type "submit"} "Submit"]]))
(defn create-problem
"create a user submitted problem"
@@ -430,7 +433,7 @@ Return a map, {:message, :url, :num-tests-passed}."
:to [email]
:subject "Problem rejected"
:body
- (str "A problem you've submitted has been rejected, but don't get discouraged! Check out the reason below, and try again.\n\n"
+ (str "A problem you've submitted has been rejected, but don't get discouraged! Check out the reason below, and try again.\n\n"
"Title: " title "\n"
"Tags: " tags "\n"
"Description: " description "\n"
@@ -453,10 +456,10 @@ Return a map, {:message, :url, :num-tests-passed}."
(POST "/problem/reject" [id]
(reject-problem (Integer. id) "We didn't like your problem."))
(POST "/problem/:id" [id code]
- (static-run-code (Integer. id) code))
+ (static-run-code (Integer. id) (trim-code code)))
(POST "/rest/problem/:id" [id code]
{:headers {"Content-Type" "application/json"}}
- (rest-run-code (Integer. id) code))
+ (rest-run-code (Integer. id) (trim-code code)))
(GET "/problems/rss" [] (create-feed
"4Clojure: Recent Problems"
"http://4clojure.com/problems"
View
8 src/foreclojure/ring.clj
@@ -11,10 +11,10 @@
keys:
:root - the root prefix to get the resources from. Defaults to 'public'."
[path & [options]]
- (-> (GET path {{resource-path :*} :route-params}
- (let [root (:root options "public")]
- (when-let [res (io/resource (str root "/" resource-path))]
- (response (io/as-file res)))))))
+ (GET path {{resource-path :*} :route-params}
+ (let [root (:root options "public")]
+ (when-let [res (io/resource (str root "/" resource-path))]
+ (response (io/as-file res))))))
(defn wrap-url-as-file [handler]
(fn [request]
View
2 src/foreclojure/utils.clj
@@ -174,7 +174,7 @@
(let [email "team@4clojure.com"]
[:span
[:a#contact {:href (str "mailto:" email)} "Contact us"]
- (str `(~email))])]
+ (str " (" email ")")])]
(javascript-tag
" var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22844856-1']);

0 comments on commit 4525281

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