Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add injection of HTML to a signal #13

Merged
merged 44 commits into from
Feb 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
3dfe962
Add injection of HTML to a signal
ericholscher Jan 19, 2016
3f39361
Move media insertion to injection
ericholscher Jan 19, 2016
cc36a4f
Move CSS to injection too
ericholscher Jan 19, 2016
e508942
Clean up extension
ericholscher Jan 19, 2016
9c297a1
Finish cleaning up refactor
ericholscher Jan 20, 2016
0a1e1c3
Merge branch 'master' into remove-layout-html
ericholscher Jan 20, 2016
2d6813b
Fix linting and single line comments
ericholscher Jan 20, 2016
da097ad
One more
ericholscher Jan 20, 2016
3e70a18
Fix linting once more :)
ericholscher Jan 20, 2016
98b5a34
Add basic integration test
ericholscher Jan 21, 2016
3f5067b
Merge branch 'remove-layout-html' into add-tests
ericholscher Jan 22, 2016
3223293
Test media insertion
ericholscher Jan 22, 2016
5bcbef2
Kill makefile
ericholscher Jan 22, 2016
1164c29
Add a couple more tests
ericholscher Jan 22, 2016
d1c0389
Monkey patch template renderer to include our HTML
ericholscher Feb 27, 2016
a466558
Properly check for truthyness
ericholscher Feb 27, 2016
b724d28
Small bit
ericholscher Feb 27, 2016
756a514
Properly set source_suffix on page
ericholscher Feb 27, 2016
413779f
Fix setup.py
ericholscher Feb 27, 2016
8e0719f
Only monkey patch our builder
ericholscher Feb 27, 2016
feeed3a
Gate builder type properly
ericholscher Feb 27, 2016
b502da8
Fix syntax :)
ericholscher Feb 27, 2016
2fd2054
Committing for dev is annoying :)
ericholscher Feb 27, 2016
a6e87ee
Fix script closing
ericholscher Feb 27, 2016
7fce49c
Don't bail on non-HTML files
ericholscher Feb 27, 2016
4c394a6
Fix reporter
ericholscher Feb 27, 2016
f52b46a
Really fix it this time
ericholscher Feb 27, 2016
9d6980d
Fix tests and enable on py2/3
ericholscher Feb 27, 2016
802bd7e
Fix review feedback
ericholscher Feb 27, 2016
5063324
Merge remote-tracking branch 'origin/master' into remove-layout-html
ericholscher Feb 27, 2016
978de13
Consistent quoting
ericholscher Feb 27, 2016
6013ed5
Output the theme_css
ericholscher Feb 27, 2016
a7c0ba1
Do case insensitive find
ericholscher Feb 27, 2016
586c034
Fix LaTeX errors
ericholscher Feb 27, 2016
b2a3264
Fix logic
ericholscher Feb 27, 2016
1252856
Account for dirhtml builder too
ericholscher Feb 27, 2016
eec0ea5
Include page in local data, not global as well
ericholscher Feb 27, 2016
6e5d52b
Fix conditional around page_source_suffix
ericholscher Feb 27, 2016
453ed9e
Fix monkeypatch
ericholscher Feb 27, 2016
3c08387
Fix lint
ericholscher Feb 27, 2016
4241c88
Put content in head not body
ericholscher Feb 27, 2016
d2f4c52
Move RTD content creation into the closure
ericholscher Feb 27, 2016
0e63ae0
Small additions to monkey patch closure
agjohnson Feb 27, 2016
4762869
Move rtd javascript to script_files addition from head addition
agjohnson Feb 28, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ python:
sudo: false
env:
- TOX_ENV=lint
- TOX_ENV=py27
- TOX_ENV=py34
install:
- pip install tox
script:
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
recursive-include readthedocs_ext *.css
recursive-include readthedocs_ext *.js_t
recursive-include readthedocs_ext *.js
recursive-include readthedocs_ext *.tmpl
include *.rst
7 changes: 0 additions & 7 deletions readthedocs_ext/_static/readthedocs-data.js_t
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@
project: "{{ slug }}",
version: "{{ current_version }}",
language: "{{ rtd_language }}",
page: "{{ pagename }}",
theme: "{{ html_theme }}",
builder: "sphinx",
docroot: "{{ conf_py_path }}",
source_suffix: "{{ source_suffix }}",
api_host: "{{ api_host }}",
commit: "{{ commit }}"
}

// Old variables
var doc_version = "{{ current_version }}";
var doc_slug = "{{ slug }}";
var page_name = "{{ pagename }}";
var html_theme = "{{ html_theme }}";
34 changes: 34 additions & 0 deletions readthedocs_ext/_templates/readthedocs-insert.html.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

<!-- RTD Extra Head -->

{%- if pagename == "index" %}
{%- set canonical_page = "" %}
{%- elif pagename.endswith("/index") %}
{%- set canonical_page = pagename[:-("/index"|length)] + "/" %}
{%- else %}
{%- set ending = "/" if builder == "readthedocsdirhtml" else ".html" %}
{%- set canonical_page = pagename + ending %}
{%- endif %}

<!--
Always link to the latest version, as canonical.
http://docs.readthedocs.org/en/latest/canonical.html
-->
<link rel="canonical" href="{{ canonical_url }}{{ canonical_page }}" />

<link rel="stylesheet" href="{{ theme_css }}" type="text/css" />
<link rel="stylesheet" href="{{ rtd_css_url }}" type="text/css" />

<script type="text/javascript" src="{{ pathto('_static/readthedocs-data.js', 1) }}"></script>

<!-- Add page-specific data, which must exist in the page js, not global -->
<script type="text/javascript">
READTHEDOCS_DATA['page'] = '{{ pagename }}'
{%- if page_source_suffix %}
READTHEDOCS_DATA['source_suffix'] = '{{ page_source_suffix }}'
{%- endif %}
</script>

<script type="text/javascript" src="{{ pathto('_static/readthedocs-dynamic-include.js', 1) }}"></script>

<!-- end RTD <extrahead> -->
70 changes: 70 additions & 0 deletions readthedocs_ext/comments/builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from __future__ import absolute_import

from collections import defaultdict

from sphinx.builders.html import StandaloneHTMLBuilder, DirectoryHTMLBuilder

from . import backend, translator


def finalize_comment_media(app):

if 'comments' not in app.builder.name:
return
builder = app.builder
# Pull project data from conf.py if it exists
builder.storage = backend.WebStorage(builder=builder)
builder.page_hash_mapping = defaultdict(list)
builder.metadata_mapping = defaultdict(list)
try:
builder.comment_metadata = builder.storage.get_project_metadata(
builder.config.html_context['slug'])['results']
for obj in builder.comment_metadata:
builder.metadata_mapping[obj['node']['page']].append(obj['node'])
except:
builder.comment_metadata = {}

context = builder.config.html_context
MEDIA_URL = context.get('MEDIA_URL', 'https://media.readthedocs.org/')

# add our custom bits
builder.script_files.append('_static/jquery.pageslide.js')
# builder.script_files.append('_static/websupport2-bundle.js')
builder.script_files.append(
'%sjavascript/websupport2-bundle.js' % MEDIA_URL)
builder.css_files.append('_static/websupport2.css')
builder.css_files.append('_static/sphinxweb.css')
builder.css_files.append('_static/jquery.pageslide.css')


class ReadtheDocsBuilderComments(StandaloneHTMLBuilder):

"""
Comment Builders.

Sets the translator class,
which handles adding a content-specific hash to each text node object.
"""
name = 'readthedocs-comments'
versioning_method = 'commentable'

def init(self):
StandaloneHTMLBuilder.init(self)
finalize_comment_media(self)

def init_translator_class(self):
self.translator_class = translator.UUIDTranslator


class ReadtheDocsDirectoryHTMLBuilderComments(DirectoryHTMLBuilder):

""" Adds specific media files to script_files and css_files. """
name = 'readthedocsdirhtml-comments'
versioning_method = 'commentable'

def init(self):
DirectoryHTMLBuilder.init(self)
finalize_comment_media(self)

def init_translator_class(self):
self.translator_class = translator.UUIDTranslator
Loading