Skip to content

Commit

Permalink
Merge branch 'release/1.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
amalloy committed Aug 7, 2011
2 parents d44f9bd + 11f0480 commit 4525281
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 31 deletions.
2 changes: 1 addition & 1 deletion 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"]
Expand Down
35 changes: 23 additions & 12 deletions resources/public/script/foreclojure.js
Expand Up @@ -35,7 +35,7 @@ function configureDataTables(){
null,
null,
null,
null
{ "sType": "string" }
]
} );

Expand Down Expand Up @@ -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
Expand All @@ -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");

Expand All @@ -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({
Expand All @@ -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";
},
Expand All @@ -126,7 +134,7 @@ function configureCodeBox(){
$("#golfgraph").html(data.golfChart);
$("#golfscore").html(data.golfScore);
configureGolf();
}
},
stopAnimation = function() {
cont = false;
images.stop(true);
Expand Down Expand Up @@ -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);
});
}
}

Expand All @@ -183,8 +196,6 @@ function configureGolf(){
} else {
$('#graph-link').html("View Chart");
}


});
});

}
4 changes: 2 additions & 2 deletions src/foreclojure/login.clj
Expand Up @@ -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!"
Expand Down
25 changes: 14 additions & 11 deletions src/foreclojure/problems.clj
Expand Up @@ -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]
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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)
Expand All @@ -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)))

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions src/foreclojure/ring.clj
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/foreclojure/utils.clj
Expand Up @@ -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']);
Expand Down

0 comments on commit 4525281

Please sign in to comment.