Tweak the commenting interface a bit.

This commit is contained in:
Georg Brandl committed 2010-11-21 11:13:11 +01:00
1 parent 7e3f9d866a
commit e05137417a
4 files changed
+83 -78

No files matched your search

+13 -6
View File
@@ -78,8 +78,7 @@ class WebSupportBuilder(PickleHTMLBuilder, VersioningBuilderMixin):
self.indexer = self.search
self.indexer.init_indexing(changed=docnames)
def handle_page(self, pagename, addctx, templatename='page.html',
outfilename=None, event_arg=None):
def _render_page(self, pagename, addctx, templatename, event_arg=None):
# This is mostly copied from StandaloneHTMLBuilder. However, instead
# of rendering the template and saving the html, create a context
# dict and pickle it.
@@ -116,10 +115,13 @@ class WebSupportBuilder(PickleHTMLBuilder, VersioningBuilderMixin):
for item in ['sidebar', 'relbar', 'script', 'css']:
if hasattr(template_module, item):
doc_ctx[item] = getattr(template_module, item)()
if 'script' not in self.globalcontext:
self.globalcontext['script'] = doc_ctx['script']
if 'css' not in self.globalcontext:
self.globalcontext['css'] = doc_ctx['css']
return ctx, doc_ctx
def handle_page(self, pagename, addctx, templatename='page.html',
outfilename=None, event_arg=None):
ctx, doc_ctx = self._render_page(pagename, addctx,
templatename, event_arg)
if not outfilename:
outfilename = path.join(self.outdir, 'pickles',
@@ -136,6 +138,11 @@ class WebSupportBuilder(PickleHTMLBuilder, VersioningBuilderMixin):
copyfile(self.env.doc2path(pagename), source_name)
def handle_finish(self):
# get global values for css and script files
_, doc_ctx = self._render_page('tmp', {}, 'page.html')
self.globalcontext['css'] = doc_ctx['css']
self.globalcontext['script'] = doc_ctx['script']
PickleHTMLBuilder.handle_finish(self)
VersioningBuilderMixin.finish(self)
+63 -68
View File
@@ -431,6 +431,10 @@
}
var id = link.attr('id');
if (!id) {
// Didn't click on one of the voting arrows.
return;
}
// If it is an unvote, the new vote value is 0,
// Otherwise it's 1 for an upvote, or -1 for a downvote.
var value = 0;
@@ -535,21 +539,18 @@
ul.children().children("[id^='cd']")
.each(function() {
var comment = $(this).data('comment');
if (recursive) {
if (recursive)
comment.children = getChildren($(this).find('#cl' + comment.id), true);
}
children.push(comment);
});
return children;
}
/**
* Create a div to display a comment in.
*/
/** Create a div to display a comment in. */
function createCommentDiv(comment) {
// Prettify the comment rating.
comment.pretty_rating = comment.rating + ' point' +
(comment.rating == 1 ? '' : 's');
(comment.rating == 1 ? '' : 's');
// Create a div for this comment.
var context = $.extend({}, opts, comment);
var div = $(renderTemplate(commentTemplate, context));
@@ -563,15 +564,12 @@
if (comment.text != '[deleted]') {
div.find('a.reply').show();
if (comment.proposal_diff) {
if (comment.proposal_diff)
div.find('#sp' + comment.id).show();
}
if (opts.moderator && !comment.displayed) {
if (opts.moderator && !comment.displayed)
div.find('#cm' + comment.id).show();
}
if (opts.moderator || (opts.username == comment.username)) {
if (opts.moderator || (opts.username == comment.username))
div.find('#dc' + comment.id).show();
}
}
return div;
}
@@ -597,6 +595,7 @@
});
}
/** Flash an error message briefly. */
function showError(message) {
$(document.createElement('div')).attr({'class': 'popup-error'})
.append($(document.createElement('div'))
@@ -607,9 +606,7 @@
.fadeOut("slow");
}
/**
* Add a link the user uses to open the comments popup.
*/
/** Add a link the user uses to open the comments popup. */
$.fn.comment = function() {
return this.each(function() {
var id = $(this).attr('id').substring(1);
@@ -621,7 +618,7 @@
.append(
$(document.createElement('a')).attr({
href: '#',
'class': 'sphinx-comment' + addcls,
'class': 'sphinx-comment-open' + addcls,
id: 'ao' + id
})
.append($(document.createElement('img')).attr({
@@ -676,34 +673,53 @@
opts = jQuery.extend(opts, COMMENT_OPTIONS);
}
var replyTemplate = '\
<li>\
<div class="reply-div" id="rd<%id%>">\
<form id="rf<%id%>">\
<textarea name="comment" cols="80"></textarea>\
<input type="submit" value="add reply" />\
<input type="hidden" name="parent" value="<%id%>" />\
<input type="hidden" name="node" value="" />\
</form>\
</div>\
</li>';
var popupTemplate = '\
<div class="sphinx-comments" id="sc<%id%>">\
<p class="sort-options">\
Sort by:\
<a href="#" class="sort-option byrating">top</a>\
<a href="#" class="sort-option byascage">newest</a>\
<a href="#" class="sort-option byage">oldest</a>\
</p>\
<div class="comment-header">Comments</div>\
<div class="comment-loading" id="cn<%id%>">\
loading comments... <img src="<%loadingImage%>" alt="" /></div>\
<ul id="cl<%id%>" class="comment-ul"></ul>\
<p class="add-a-comment">Add a comment:</p>\
<form method="post" id="cf<%id%>" class="comment-form" action="">\
<textarea name="comment" cols="80"></textarea>\
<p class="propose-button">\
<a href="#" id="pc<%id%>" class="show-propose-change">\
Propose a change &#9657;\
</a>\
<a href="#" id="hc<%id%>" class="hide-propose-change">\
Propose a change &#9663;\
</a>\
</p>\
<textarea name="proposal" id="pt<%id%>" cols="80"\
spellcheck="false"></textarea>\
<input type="submit" value="Add comment" />\
<input type="hidden" name="node" value="<%id%>" />\
<input type="hidden" name="parent" value="" />\
</form>\
</div>';
var commentTemplate = '\
<div id="cd<%id%>" class="sphinx-comment-div">\
<div id="cd<%id%>" class="sphinx-comment">\
<div class="vote">\
<div class="arrow">\
<a href="#" id="uv<%id%>" class="vote">\
<a href="#" id="uv<%id%>" class="vote" title="vote up">\
<img src="<%upArrow%>" />\
</a>\
<a href="#" id="uu<%id%>" class="un vote">\
<a href="#" id="uu<%id%>" class="un vote" title="vote up">\
<img src="<%upArrowPressed%>" />\
</a>\
</div>\
<div class="arrow">\
<a href="#" id="dv<%id%>" class="vote">\
<a href="#" id="dv<%id%>" class="vote" title="vote down">\
<img src="<%downArrow%>" id="da<%id%>" />\
</a>\
<a href="#" id="du<%id%>" class="un vote">\
<a href="#" id="du<%id%>" class="un vote" title="vote down">\
<img src="<%downArrowPressed%>" />\
</a>\
</div>\
@@ -718,15 +734,9 @@
<p class="comment-opts comment">\
<a href="#" class="reply hidden" id="rl<%id%>">reply &#9657;</a>\
<a href="#" class="close-reply" id="cr<%id%>">reply &#9663;</a>\
<a href="#" id="sp<%id%>" class="show-proposal">\
proposal &#9657;\
</a>\
<a href="#" id="hp<%id%>" class="hide-proposal">\
proposal &#9663;\
</a>\
<a href="#" id="dc<%id%>" class="delete-comment hidden">\
delete\
</a>\
<a href="#" id="sp<%id%>" class="show-proposal">proposal &#9657;</a>\
<a href="#" id="hp<%id%>" class="hide-proposal">proposal &#9663;</a>\
<a href="#" id="dc<%id%>" class="delete-comment hidden">delete</a>\
<span id="cm<%id%>" class="moderation hidden">\
<a href="#" id="ac<%id%>" class="accept-comment">accept</a>\
<a href="#" id="rc<%id%>" class="reject-comment">reject</a>\
@@ -741,33 +751,17 @@
</div>\
</div>';
var popupTemplate = '\
<div class="sphinx-comments" id="sc<%id%>">\
<div class="comment-header">Comments</div>\
<form method="post" id="cf<%id%>" class="comment-form" action="/docs/add_comment">\
<textarea name="comment" cols="80"></textarea>\
<p class="propose-button">\
<a href="#" id="pc<%id%>" class="show-propose-change">\
Propose a change &#9657;\
</a>\
<a href="#" id="hc<%id%>" class="hide-propose-change">\
Propose a change &#9663;\
</a>\
</p>\
<textarea name="proposal" id="pt<%id%>" cols="80" spellcheck="false"></textarea>\
<input type="submit" value="add comment" />\
<input type="hidden" name="node" value="<%id%>" />\
<input type="hidden" name="parent" value="" />\
<p class="sort-options">\
Sort by:\
<a href="#" class="sort-option byrating">top</a>\
<a href="#" class="sort-option byascage">newest</a>\
<a href="#" class="sort-option byage">oldest</a>\
</p>\
</form>\
<div class="comment-loading" id="cn<%id%>">loading comments... <img src="<%loadingImage%>" alt="" /></div>\
<ul id="cl<%id%>" class="comment-ul"></ul>\
</div>';
var replyTemplate = '\
<li>\
<div class="reply-div" id="rd<%id%>">\
<form id="rf<%id%>">\
<textarea name="comment" cols="80"></textarea>\
<input type="submit" value="Add reply" />\
<input type="hidden" name="parent" value="<%id%>" />\
<input type="hidden" name="node" value="" />\
</form>\
</div>\
</li>';
$(document).ready(function() {
init();
@@ -775,6 +769,7 @@
})(jQuery);
$(document).ready(function() {
/** Add comment anchors for all paragraphs that are commentable. */
$('.sphinx-has-comment').comment();
/** Highlight search words in search results. */
+6 -3
View File
@@ -213,9 +213,12 @@ class WebSupport(object):
'search_results': results,
'docroot': '../', # XXX
}
document = self.get_document('search')
document['body'] = self.results_template.render(ctx)
document['title'] = 'Search Results'
document = {
'body': self.results_template.render(ctx),
'title': 'Search Results',
'sidebar': '',
'relbar': ''
}
return document
def get_data(self, node_id, username=None, moderator=False):
+1 -1
View File
@@ -58,7 +58,7 @@ class CombinedHtmlDiff(object):
if next is not None and next[0] == '?':
tag = 'ins' if prefix == '+' else 'del'
text = self._highlight_text(text, next, tag)
css_class = 'prop_added' if prefix == '+' else 'prop_removed'
css_class = 'prop-added' if prefix == '+' else 'prop-removed'
return '<span class="%s">%s</span>\n' % (css_class, text.rstrip())