Skip to content

Instantly share code, notes, and snippets.

@tyler-johnson
Created December 10, 2013 18:34
Show Gist options
  • Save tyler-johnson/7895640 to your computer and use it in GitHub Desktop.
Save tyler-johnson/7895640 to your computer and use it in GitHub Desktop.
nunjucks async issue
(function() {(window.nunjucksPrecompiled = window.nunjucksPrecompiled || {})["./views/question.html"] = (function() {function root(env, context, frame, runtime, cb) {
var lineno = null;
var colno = null;
var output = "";
try {
env.getTemplate("layout.html", true, function(t_2,parentTemplate) {
if(t_2) { cb(t_2); return; }
for(var t_1 in parentTemplate.blocks) {
context.addBlock(t_1, parentTemplate.blocks[t_1]);
}
output += "\n\n";
output += "\n\n";
parentTemplate.rootRenderFunc(env, context, frame, runtime, cb);
});
} catch (e) {
cb(runtime.handleError(e, lineno, colno));
}
}
function b_bodyclass(env, context, frame, runtime, cb) {
var lineno = null;
var colno = null;
var output = "";
try {
output += "question";
cb(null, output);
;
} catch (e) {
cb(runtime.handleError(e, lineno, colno));
}
}
function b_body(env, context, frame, runtime, cb) {
var lineno = null;
var colno = null;
var output = "";
try {
output += "\n\n<script type=\"text/javascript\">\n\t$(document).ready(function() {\n\t\tvar editBtn = $(\"#editBtn\"),\n\t\t\tcancelBtn = $(\"#cancelBtn\"),\n\t\t\tdeleteBtn = $(\"#deleteBtn\"),\n\t\t\tcontent = $(\"#questionContent\"),\n\t\t\teditForm = $(\"#editQuestion\");\n\n\t\teditBtn.click(function(e) {\n\t\t\te.preventDefault();\n\t\t\teditBtn.hide();\n\t\t\tcontent.hide();\n\t\t\teditForm.show();\n\t\t});\n\n\t\tcancelBtn.click(function(e) {\n\t\t\te.preventDefault();\n\t\t\teditForm.hide().get(0).reset();\n\t\t\teditBtn.show();\n\t\t\tcontent.show();\n\t\t});\n\n\t\tdeleteBtn.click(function(e) {\n\t\t\te.preventDefault();\n\t\t\tif (confirm(\"Are you sure you want to delete this question?\"))\n\t\t\t\tlocation.href = $(e.target).closest(\"a\").attr(\"href\");\n\t\t});\n\t});\n</script>\n\n";
var t_3;
t_3 = (lineno = 36, colno = 31, runtime.callWrap(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "$util")),"permission", env.autoesc), "$util[\"permission\"]", ["admin",runtime.contextOrFrameLookup(context, frame, "user")]));
frame.set("isAdmin", t_3);
if(!frame.parent) {
context.setVariable("isAdmin", t_3);
context.addExport("isAdmin");
}
output += "\n\n<div class=\"question-header\">\n\t";
if(t_3 || ((lineno = 39, colno = 34, runtime.callWrap(runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "user")),"_id", env.autoesc)),"toString", env.autoesc), "user[\"_id\"][\"toString\"]", [])) == (lineno = 39, colno = 63, runtime.callWrap(runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "question")),"owner", env.autoesc)),"toString", env.autoesc), "question[\"owner\"][\"toString\"]", [])) && !runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "question")),"answer", env.autoesc))) {
output += "\n\t<a href=\"#\"";
if(runtime.contextOrFrameLookup(context, frame, "error")) {
output += " style=\"display: none;\"";
;
}
output += " id=\"editBtn\" class=\"btn btn-primary pull-right\">\n\t\t";
if(t_3) {
if(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "question")),"answer", env.autoesc)) {
output += "Edit ";
;
}
output += "Answer\n\t\t";
;
}
else {
output += "Edit";
;
}
output += "\n\t</a>\n\t";
;
}
output += "\n\t<h1>";
output += runtime.suppressValue(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "question")),"question", env.autoesc), env.autoesc);
output += "</h1>\n\t<div class=\"details\">\n\t\tAsked by ";
output += runtime.suppressValue(env.getFilter("username").call(context, runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "question")),"owner", env.autoesc)), env.autoesc);
output += " ";
output += runtime.suppressValue((lineno = 47, colno = 65, runtime.callWrap(runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "question")),"created", env.autoesc)),"relative", env.autoesc), "question[\"created\"][\"relative\"]", [])), env.autoesc);
output += "\n\t\t";
if(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "question")),"answer", env.autoesc)) {
output += "\n\t\t&bullet;\n\t\tAnswered by ";
output += runtime.suppressValue(env.getFilter("username").call(context, runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "question")),"answered_by", env.autoesc)), env.autoesc);
output += " ";
output += runtime.suppressValue((lineno = 50, colno = 78, runtime.callWrap(runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "question")),"answered_on", env.autoesc)),"relative", env.autoesc), "question[\"answered_o\"][\"relative\"]", [])), env.autoesc);
output += "\n\t\t";
;
}
output += "\n\t\t";
if(runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "question")),"tags", env.autoesc)),"length", env.autoesc)) {
output += "\n\t\t&bullet;\n\t\t";
frame = frame.push();
var t_6 = runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "question")),"tags", env.autoesc);
if(t_6) {for(var t_4=0; t_4 < t_6.length; t_4++) {
var t_7 = t_6[t_4];
frame.set("tag", t_7);
frame.set("loop.last", t_4 === t_6.length - 1);
output += "\n\t\t\t<a href=\"/tag/";
output += runtime.suppressValue(t_7, env.autoesc);
output += "\">";
output += runtime.suppressValue(t_7, env.autoesc);
output += "</a>";
if(!runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "loop")),"last", env.autoesc)) {
output += ",";
;
}
output += "\n\t\t";
;
}
}
frame = frame.pop();
output += "\n\t\t";
;
}
output += "\n\t</div>\n</div>\n\n<div class=\"content\"";
if(runtime.contextOrFrameLookup(context, frame, "error")) {
output += " style=\"display: none;\"";
;
}
output += " id=\"questionContent\">\n\t";
if(runtime.contextOrFrameLookup(context, frame, "success")) {
output += "<div class=\"alert alert-success\">Question was saved successfully.</div>";
;
}
output += "\n\n\t";
if(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "question")),"details", env.autoesc)) {
output += "\n\t<div class=\"well\">\n\t\t";
output += runtime.suppressValue(env.getFilter("markdown").call(context, runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "question")),"details", env.autoesc)), env.autoesc);
output += "\n\t</div>\n\t";
;
}
output += "\n\n\t";
if(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "question")),"answer", env.autoesc)) {
output += "\n\t";
output += runtime.suppressValue(env.getFilter("markdown").call(context, runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "question")),"answer", env.autoesc)), env.autoesc);
output += "\n\t";
;
}
else {
output += "\n\t<p>This question hasn't been answered yet. Please allow us 48 hours to post a response.</p>\n\t";
;
}
output += "\n</div>\n\n<form class=\"form-horizontal\"";
if(!runtime.contextOrFrameLookup(context, frame, "error")) {
output += " style=\"display: none;\"";
;
}
output += " id=\"editQuestion\" method=\"post\" action=\"";
output += runtime.suppressValue(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "$req")),"url", env.autoesc), env.autoesc);
output += "\">\n\t";
if(runtime.contextOrFrameLookup(context, frame, "error")) {
output += "<div class=\"alert alert-danger\">";
output += runtime.suppressValue(runtime.contextOrFrameLookup(context, frame, "error"), env.autoesc);
output += "</div>";
;
}
output += "\n\t<div class=\"form-group\">\n\t\t<label class=\"col-lg-12 col-md-12\" for=\"inputQuestion\">Question</label>\n\t\t<div class=\"col-lg-6 col-md-6\">\n\t\t\t<input type=\"text\" class=\"form-control\" id=\"inputQuestion\" name=\"question\" value=\"";
output += runtime.suppressValue(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "data")),"question", env.autoesc) || runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "question")),"question", env.autoesc), env.autoesc);
output += "\" />\n\t\t</div>\n\t\t<div class=\"col-lg-6 col-md-6 help-block\">Less specific questions are generally easier (and faster) to answer.</div>\n\t</div>\n\t<div class=\"form-group\">\n\t\t<label class=\"col-lg-12 col-md-12\" for=\"inputDetails\">Details</label>\n\t\t<div class=\"col-lg-6 col-md-6\">\n\t\t\t<textarea class=\"form-control\" rows=\"5\" id=\"inputDetails\" name=\"details\">";
output += runtime.suppressValue(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "data")),"details", env.autoesc) || runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "question")),"details", env.autoesc), env.autoesc);
output += "</textarea>\n\t\t</div>\n\t\t<div class=\"col-lg-6 col-md-6 help-block\">Please provide specific details about your question to help the support agent give a more accurate answer. For example, if you are having issues with something, please provide the exact steps you used. All content is formatted with <a href=\"http://daringfireball.net/projects/markdown/syntax\" target=\"_blank\">markdown</a>.</div>\n\t</div>\n\t";
if(t_3) {
output += "\n\t<div class=\"form-group\">\n\t\t<label class=\"col-lg-12 col-md-12\" for=\"inputAnswer\">Answer</label>\n\t\t<div class=\"col-lg-12 col-md-12\">\n\t\t\t<textarea class=\"form-control\" id=\"inputAnswer\" name=\"answer\" rows=\"15\">";
output += runtime.suppressValue(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "data")),"answer", env.autoesc) || runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "question")),"answer", env.autoesc), env.autoesc);
output += "</textarea>\n\t\t</div>\n\t</div>\n\t<div class=\"form-group\">\n\t\t<label class=\"col-lg-12 col-md-12\" for=\"inputTags\">Tags</label>\n\t\t<div class=\"col-lg-6 col-md-6\">\n\t\t\t<input type=\"text\" class=\"form-control\" id=\"inputTags\" name=\"tags\" value=\"";
output += runtime.suppressValue(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "data")),"tags", env.autoesc) || (lineno = 103, colno = 109, runtime.callWrap(runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "question")),"tags", env.autoesc)),"join", env.autoesc), "question[\"tags\"][\"join\"]", [", "])), env.autoesc);
output += "\" />\n\t\t</div>\n\t\t<div class=\"col-lg-6 col-md-6 help-block\">Comma separated. Direct terms associated with this question.</div>\n\t</div>\n\t<div class=\"form-group\">\n\t\t<div class=\"col-lg-12 col-md-12\">\n\t\t\t<div class=\"checkbox\">\n\t\t\t\t<label><input type=\"checkbox\" name=\"public\"";
if(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "data")),"public", env.autoesc) || runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "question")),"public", env.autoesc)) {
output += " checked";
;
}
output += " /> Display Publicly</label>\n\t\t\t\t<div class=\"help-block\">Available in search results and on the home page.</div>\n\t\t\t</div>\n\t\t</div>\n\t</div>\n\t<a href=\"/question/";
output += runtime.suppressValue(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "question")),"shortid", env.autoesc), env.autoesc);
output += "/";
output += runtime.suppressValue(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "question")),"handle", env.autoesc), env.autoesc);
output += "/delete\" id=\"deleteBtn\" class=\"btn btn-danger pull-right\">Delete Question</a>\n\t";
;
}
output += "\n\t<button type=\"submit\" class=\"btn btn-success\">Save</button>\n\t<a href=\"#\" class=\"btn btn-default\" ";
if(runtime.contextOrFrameLookup(context, frame, "error")) {
output += "onclick=\"location.reload(); return false;\"";
;
}
else {
output += "id=\"cancelBtn\"";
;
}
output += ">Cancel</a>\n</form>\n\n";
cb(null, output);
;
} catch (e) {
cb(runtime.handleError(e, lineno, colno));
}
}
return {
b_bodyclass: b_bodyclass,
b_body: b_body,
root: root
};
})();
})();
{% extends "layout.html" %}
{% block bodyclass %}question{% endblock %}
{% block body %}
<script type="text/javascript">
$(document).ready(function() {
var editBtn = $("#editBtn"),
cancelBtn = $("#cancelBtn"),
deleteBtn = $("#deleteBtn"),
content = $("#questionContent"),
editForm = $("#editQuestion");
editBtn.click(function(e) {
e.preventDefault();
editBtn.hide();
content.hide();
editForm.show();
});
cancelBtn.click(function(e) {
e.preventDefault();
editForm.hide().get(0).reset();
editBtn.show();
content.show();
});
deleteBtn.click(function(e) {
e.preventDefault();
if (confirm("Are you sure you want to delete this question?"))
location.href = $(e.target).closest("a").attr("href");
});
});
</script>
{% set isAdmin = $util.permission("admin", user) %}
<div class="question-header">
{% if isAdmin or (user._id.toString() == question.owner.toString() and not question.answer) %}
<a href="#"{% if error %} style="display: none;"{% endif %} id="editBtn" class="btn btn-primary pull-right">
{% if isAdmin %}{% if question.answer %}Edit {% endif %}Answer
{% else %}Edit{% endif %}
</a>
{% endif %}
<h1>{{ question.question }}</h1>
<div class="details">
Asked by {{ question.owner | username }} {{ question.created.relative() }}
{% if question.answer %}
&bullet;
Answered by {{ question.answered_by | username }} {{ question.answered_on.relative() }}
{% endif %}
{% if question.tags.length %}
&bullet;
{% for tag in question.tags %}
<a href="/tag/{{ tag }}">{{ tag }}</a>{% if not loop.last %},{% endif %}
{% endfor %}
{% endif %}
</div>
</div>
<div class="content"{% if error %} style="display: none;"{% endif %} id="questionContent">
{% if success %}<div class="alert alert-success">Question was saved successfully.</div>{% endif %}
{% if question.details %}
<div class="well">
{{ question.details | markdown }}
</div>
{% endif %}
{% if question.answer %}
{{ question.answer | markdown }}
{% else %}
<p>This question hasn't been answered yet. Please allow us 48 hours to post a response.</p>
{% endif %}
</div>
<form class="form-horizontal"{% if not error %} style="display: none;"{% endif %} id="editQuestion" method="post" action="{{ $req.url }}">
{% if error %}<div class="alert alert-danger">{{ error }}</div>{% endif %}
<div class="form-group">
<label class="col-lg-12 col-md-12" for="inputQuestion">Question</label>
<div class="col-lg-6 col-md-6">
<input type="text" class="form-control" id="inputQuestion" name="question" value="{{ data.question or question.question }}" />
</div>
<div class="col-lg-6 col-md-6 help-block">Less specific questions are generally easier (and faster) to answer.</div>
</div>
<div class="form-group">
<label class="col-lg-12 col-md-12" for="inputDetails">Details</label>
<div class="col-lg-6 col-md-6">
<textarea class="form-control" rows="5" id="inputDetails" name="details">{{ data.details or question.details }}</textarea>
</div>
<div class="col-lg-6 col-md-6 help-block">Please provide specific details about your question to help the support agent give a more accurate answer. For example, if you are having issues with something, please provide the exact steps you used. All content is formatted with <a href="http://daringfireball.net/projects/markdown/syntax" target="_blank">markdown</a>.</div>
</div>
{% if isAdmin %}
<div class="form-group">
<label class="col-lg-12 col-md-12" for="inputAnswer">Answer</label>
<div class="col-lg-12 col-md-12">
<textarea class="form-control" id="inputAnswer" name="answer" rows="15">{{ data.answer or question.answer }}</textarea>
</div>
</div>
<div class="form-group">
<label class="col-lg-12 col-md-12" for="inputTags">Tags</label>
<div class="col-lg-6 col-md-6">
<input type="text" class="form-control" id="inputTags" name="tags" value="{{ data.tags or question.tags.join(", ") }}" />
</div>
<div class="col-lg-6 col-md-6 help-block">Comma separated. Direct terms associated with this question.</div>
</div>
<div class="form-group">
<div class="col-lg-12 col-md-12">
<div class="checkbox">
<label><input type="checkbox" name="public"{% if data.public or question.public %} checked{% endif %} /> Display Publicly</label>
<div class="help-block">Available in search results and on the home page.</div>
</div>
</div>
</div>
<a href="/question/{{ question.shortid }}/{{ question.handle }}/delete" id="deleteBtn" class="btn btn-danger pull-right">Delete Question</a>
{% endif %}
<button type="submit" class="btn btn-success">Save</button>
<a href="#" class="btn btn-default" {% if error %}onclick="location.reload(); return false;"{% else %}id="cancelBtn"{% endif %}>Cancel</a>
</form>
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment