Skip to content

Commit

Permalink
updated the serialized.db with the latest examples, now no longer usi…
Browse files Browse the repository at this point in the history
…ng read-string on the results gained via the sandbox as this is very dangerous: (read-string \"#=(println "foo")\"
  • Loading branch information
devn committed May 3, 2010
1 parent dee2430 commit 1bd4ecb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion serialized.db

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/walton/core.clj
Expand Up @@ -121,7 +121,7 @@
conj [sexp (pr-str r)])))
(catch java.lang.Throwable t
(dosync (alter sexps update-in [:bad]
conj sexp))))))
conj [sexp (pr-str "This is not runnable in the sandbox.")]))))))

(defn categorize-sexps
"Runs the expressions in a try/catch and categorizes them as :good or :bad."
Expand All @@ -133,7 +133,7 @@
conj [code (pr-str r)]))
(catch java.lang.Throwable t
(update-in result [:bad]
conj code))))
[conj code (pr-str "This is not runnable in the sandbox.")]))))
cats
sexps))
([sexps] (categorize-sexps sexps {})))
Expand Down Expand Up @@ -164,7 +164,7 @@
(if (not (empty? g))
g
(filter
(fn [#^String c] (< 0 (.indexOf c s)))
(fn [[#^String c]] (< 0 (.indexOf c s)))
(:bad @sexps)))))

(defn truncate
Expand Down
34 changes: 28 additions & 6 deletions src/walton/layout.clj
Expand Up @@ -19,29 +19,51 @@
[:b "Macro"])
[:p (str (:doc (meta v)))]]))

(defn handle-leftangle [#^String s]
(if (re-find #".*#<.*" s)
(defn handle-leftangle
"If "
[#^String s]
(if (re-find #".*#<.*" s)
(str "\"" s "\"")
s))

(defn format-code
(defn format-code*
[& codes]
(apply str (map
(fn [code]
(if (string? code)
(with-out-str
(pprint
(read-string
(handle-leftangle code))))))
(try
(read-string code)
(catch Exception _
(identity code)))))))
codes)))

(defn format-code
[& codes]
(apply str (map
(fn [code]
(if (string? code)
(str code "\n")
(with-out-str
(pprint code))))
codes)))

(defn one-liner?
[s]
(if s
(< (count (remove empty? (s/split s #"\s*\n\s*"))) 2)
true))

(defn code*
"Show codes (literal strings or forms) in a pre/code block."
[& codes]
(let [code-string (apply format-code* codes)
class-string "brush: clojure; toolbar: true;"]
[:script {:type "syntaxhighlighter" :class class-string}
(str "<![CDATA[" code-string "]]>")]))

(defn code
"Show codes (literal strings or forms) in a pre/code block."
[& codes]
(let [code-string (apply format-code codes)
Expand All @@ -55,7 +77,7 @@
[:h1 (str n ". ")]]
[:div.right
[:div.code (code* (first s))]
[:div.return (code* (second s))]]])
[:div.return (code (second s))]]])

(defn google-api []
(html
Expand Down

0 comments on commit 1bd4ecb

Please sign in to comment.