Skip to content

Commit

Permalink
refactored error template to a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
yogthos committed Sep 4, 2014
1 parent 685fef2 commit 63a7305
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 85 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Expand Up @@ -12,4 +12,6 @@ pom.xml.asc
.lein-plugins
.lein-repl-history
.nrepl-port
test/readme.clj
test/readme.clj
.idea
*.iml
2 changes: 1 addition & 1 deletion project.clj
@@ -1,4 +1,4 @@
(defproject selmer "0.6.9"
(defproject selmer "0.7.0"
:description "Django templates for Clojure"
:url "https://github.com/yogthos/Selmer"
:license {:name "Eclipse Public License"
Expand Down
78 changes: 78 additions & 0 deletions resources/selmer-error-template.html
@@ -0,0 +1,78 @@
<html>
<head>
<font face='arial'>
<style type='text/css'>
body {
margin: 0px;
background: #ececec;
}
#header {
padding-top: 5px;
padding-left: 25px;
color: white;
background: #a32306;
text-shadow: 1px 1px #33333;
border-bottom: 1px solid #710000;
}
#error-wrap {
border-top: 5px solid #d46e6b;
}
#error-message {
color: #800000;
background: #f5a29f;
padding: 10px;
text-shadow: 1px 1px #FFBBBB;
border-top: 1px solid #f4b1ae;
}
#file-wrap {
border-top: 5px solid #2a2a2a;
}
#file {
color: white;
background: #333333;
padding: 10px;
padding-left: 20px;
text-shadow: 1px 1px #555555;
border-top: 1px solid #444444;
}
#line-number {
width=20px;
color: #8b8b8b;
background: #d6d6d6;
float: left;
padding: 5px;
text-shadow: 1px 1px #EEEEEE;
border-right: 1px solid #b6b6b6;
}
#line-content {
float: left;
padding: 5px;
}
#error-content {
float: left;
width: 100%;
border-top: 5px solid #cdcdcd;
border-bottom: 5px solid #cdcdcd;
}
</style>
</head>
<body>
<div id='header'>
<h1>Template Compilation Error</h1>
</div>
<div id='error-wrap'>
<div id='error-message'>{{error}}.</div>
</div>
{% if template %}
<div id='file-wrap'>
<div id='file'>In {{template}}{% if line %} on line {{line}}{% endif %}.</div>
</div>
{% for error in validation-errors %}
<div id='error-content'>
<div id='line-number'>{{error.line}}</div>
<div id='line-content'>{{error.tag}}</div>
</div>
{% endfor %}
{% endif %}
</body>
</html>
9 changes: 6 additions & 3 deletions src/selmer/util.clj
Expand Up @@ -126,6 +126,11 @@
(.append buf ch)
(recur items (read-char rdr) open?))))))

(defn get-resource [resource]
(-> (Thread/currentThread)
(.getContextClassLoader)
(.getResource resource)))

(def in-jar?
(memoize
(fn [^String file-path]
Expand All @@ -139,9 +144,7 @@
(defn resource-path [template]
(if-let [path @custom-resource-path]
(java.net.URL. (str "file:///" path template))
(-> (Thread/currentThread)
(.getContextClassLoader)
(.getResource template))))
(get-resource template)))

(defn check-template-exists [^String file-path]
(when-not (or (in-jar? file-path)
Expand Down
81 changes: 1 addition & 80 deletions src/selmer/validator.clj
Expand Up @@ -6,86 +6,7 @@
[clojure.java.io :only [reader]]))

(def error-template
"
<html>
<head>
<font face='arial'>
<style type='text/css'>
body {
margin: 0px;
background: #ececec;
}
#header {
padding-top: 5px;
padding-left: 25px;
color: white;
background: #a32306;
text-shadow: 1px 1px #33333;
border-bottom: 1px solid #710000;
}
#error-wrap {
border-top: 5px solid #d46e6b;
}
#error-message {
color: #800000;
background: #f5a29f;
padding: 10px;
text-shadow: 1px 1px #FFBBBB;
border-top: 1px solid #f4b1ae;
}
#file-wrap {
border-top: 5px solid #2a2a2a;
}
#file {
color: white;
background: #333333;
padding: 10px;
padding-left: 20px;
text-shadow: 1px 1px #555555;
border-top: 1px solid #444444;
}
#line-number {
width=20px;
color: #8b8b8b;
background: #d6d6d6;
float: left;
padding: 5px;
text-shadow: 1px 1px #EEEEEE;
border-right: 1px solid #b6b6b6;
}
#line-content {
float: left;
padding: 5px;
}
#error-content {
float: left;
width: 100%;
border-top: 5px solid #cdcdcd;
border-bottom: 5px solid #cdcdcd;
}
</style>
</head>
<body>
<div id='header'>
<h1>Template Compilation Error</h1>
</div>
<div id='error-wrap'>
<div id='error-message'>{{error}}.</div>
</div>
{% if template %}
<div id='file-wrap'>
<div id='file'>In {{template}}{% if line %} on line {{line}}{% endif %}.</div>
</div>
{% for error in validation-errors %}
<div id='error-content'>
<div id='line-number'>{{error.line}}</div>
<div id='line-content'>{{error.tag}}</div>
</div>
{% endfor %}
{% endif %}
</body>
</html>
")
(slurp (get-resource "selmer-error-template.html")))

(def validate? (atom true))

Expand Down

0 comments on commit 63a7305

Please sign in to comment.