Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Commit b2036f7

Browse files
committed
Add pdb for now
1 parent 34e9502 commit b2036f7

File tree

1 file changed

+97
-6
lines changed

1 file changed

+97
-6
lines changed

readthedocs_ext/comments/translator.py

Lines changed: 97 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# -*- coding: utf-8 -*-
22

3-
# From sphinx.writers.websupport
3+
import json
44

5+
from docutils import nodes
56
from sphinx.writers.html import HTMLTranslator
67

78
import hasher
@@ -40,6 +41,89 @@ def is_commentable(node):
4041

4142
return False
4243

44+
kong_comments = """
45+
{
46+
"count": 2,
47+
"next": null,
48+
"previous": null,
49+
"results": [
50+
{
51+
"date": "2015-02-24T19:03:53.992703",
52+
"user": 1,
53+
"text": "simple comment",
54+
"node": {
55+
"id": 619,
56+
"version": {
57+
"id": 104,
58+
"project": {
59+
"id": 2,
60+
"name": "Kong",
61+
"slug": "woot-kong",
62+
"description": "",
63+
"language": "en",
64+
"repo": "http://github.com/ericholscher/django-kong",
65+
"repo_type": "git",
66+
"default_version": "latest",
67+
"default_branch": null,
68+
"documentation_type": "sphinx",
69+
"users": [
70+
1
71+
]
72+
},
73+
"slug": "latest",
74+
"identifier": "master",
75+
"verbose_name": "latest",
76+
"active": true,
77+
"built": true,
78+
"downloads": "{'htmlzip': '//localhost:8000/projects/woot-kong/downloads/htmlzip/latest/', 'epub': '//localhost:8000/projects/woot-kong/downloads/epub/latest/'}"
79+
},
80+
"current_hash": "nil-45fcb0188968b1be015a13a44508377b140a1639d872fcc7ee09639e7eb5eb71",
81+
"last_commit": "fac9e2868d8fe86c2e7fcc3d4f02a43fe015f9b3",
82+
"snapshots_count": "1",
83+
"page": "index",
84+
"project": 2
85+
}
86+
},
87+
{
88+
"date": "2015-02-24T19:04:00.174457",
89+
"user": 1,
90+
"text": "Another coment",
91+
"node": {
92+
"id": 620,
93+
"version": {
94+
"id": 104,
95+
"project": {
96+
"id": 2,
97+
"name": "Kong",
98+
"slug": "woot-kong",
99+
"description": "",
100+
"language": "en",
101+
"repo": "http://github.com/ericholscher/django-kong",
102+
"repo_type": "git",
103+
"default_version": "latest",
104+
"default_branch": null,
105+
"documentation_type": "sphinx",
106+
"users": [
107+
1
108+
]
109+
},
110+
"slug": "latest",
111+
"identifier": "master",
112+
"verbose_name": "latest",
113+
"active": true,
114+
"built": true,
115+
"downloads": "{'htmlzip': '//localhost:8000/projects/woot-kong/downloads/htmlzip/latest/', 'epub': '//localhost:8000/projects/woot-kong/downloads/epub/latest/'}"
116+
},
117+
"current_hash": "nil-1a8ea4600ed6309a4a13a8b18380606b81485927d07247544270cecaec34c509",
118+
"last_commit": "fac9e2868d8fe86c2e7fcc3d4f02a43fe015f9b3",
119+
"snapshots_count": "1",
120+
"page": "index",
121+
"project": 2
122+
}
123+
}
124+
]
125+
}
126+
"""
43127

44128
class UUIDTranslator(HTMLTranslator):
45129

@@ -51,6 +135,7 @@ class UUIDTranslator(HTMLTranslator):
51135
def __init__(self, builder, *args, **kwargs):
52136
HTMLTranslator.__init__(self, builder, *args, **kwargs)
53137
self.comment_class = 'sphinx-has-comment'
138+
self.metadata = json.loads(kong_comments)['results']
54139

55140
def dispatch_visit(self, node):
56141
if is_commentable(node):
@@ -61,13 +146,19 @@ def handle_visit_commentable(self, node):
61146
# We will place the node in the HTML id attribute. If the node
62147
# already has an id (for indexing purposes) put an empty
63148
# span with the existing id directly before this node's HTML.
64-
self.update_hash(node, builder=self.builder)
149+
hash_digest = self.update_hash(node, builder=self.builder)
65150
if node.attributes['ids']:
66151
self.body.append('<span id="%s"></span>'
67152
% node.attributes['ids'][0])
68-
node.attributes['ids'] = ['%s' % hasher.hash_node(node)]
153+
node.attributes['ids'] = ['%s' % hash_digest]
69154
node.attributes['classes'].append(self.comment_class)
70155

156+
for obj in self.metadata:
157+
if obj['node']['current_hash'] == hash_digest:
158+
print "ADDING COMMEWNT"
159+
comment = "[COMMENT] %s: %s" % (obj['user'], obj['text'])
160+
node.insert(1, nodes.paragraph(comment, comment))
161+
71162
def update_hash(self, node, builder):
72163
"""
73164
Take a node and compare it against existing hashes for this page.
@@ -79,11 +170,11 @@ def update_hash(self, node, builder):
79170
if hash_digest not in hash_list:
80171
match = hasher.compare_hash(hash_obj, hash_list)
81172
if match:
82-
resp = builder.storage.update_node(old_hash=match, new_hash=hasher.hash_node(node), commit='foobar')
83-
return resp
173+
builder.storage.update_node(old_hash=match, new_hash=hasher.hash_node(node), commit='foobar')
174+
return hash_digest
84175
# else:
85176
# resp = builder.storage.add_node(id=hasher.hash_node(node),
86177
# document=builder.current_docname,
87178
# source=node.rawsource or node.astext())
88179

89-
return None
180+
return hash_digest

0 commit comments

Comments
 (0)