Skip to content

Commit 1a053bd

Browse files
ericholscheragjohnson
authored andcommitted
Integrate Embed API where we expect it. (readthedocs#3356)
* Integrate Embed where we expect it. * Re-enable ImportedFile creation * Filter files to only HTML. * Fix tests * Update media files
1 parent d4c21b9 commit 1a053bd

File tree

8 files changed

+28
-18
lines changed

8 files changed

+28
-18
lines changed

readthedocs/projects/static-src/projects/js/tools.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,15 @@ function EmbedView (config) {
110110
self.api_example = ko.observable(null);
111111

112112
self.show_help = function () {
113-
var embed = new rtd.Embed();
113+
var embed = new rtd.Embed(self.config);
114114
embed.section(
115115
'docs', 'latest', 'features/embed', 'Content Embedding',
116116
_show_modal
117117
);
118118
};
119119

120120
self.show_embed = function () {
121-
var embed = new rtd.Embed();
121+
var embed = new rtd.Embed(self.config);
122122
_show_modal(self.response());
123123
};
124124
}

readthedocs/projects/static/projects/js/tools.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readthedocs/projects/tasks.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -786,20 +786,17 @@ def fileify(version_pk, commit):
786786
"""
787787
Create ImportedFile objects for all of a version's files.
788788
789-
This is a prereq for indexing the docs for search.
790-
It also causes celery-haystack to kick off an index of the file.
789+
This is so we have an idea of what files we have in the database.
791790
"""
792791
version = Version.objects.get(pk=version_pk)
793792
project = version.project
794793

795-
if not project.cdn_enabled:
796-
return
797-
798794
if not commit:
799795
log.info(LOG_TEMPLATE
800796
.format(project=project.slug, version=version.slug,
801797
msg=('Imported File not being built because no commit '
802798
'information')))
799+
return
803800

804801
path = project.rtd_build_path(version.slug)
805802
if path:
@@ -848,12 +845,12 @@ def _manage_imported_files(version, path, commit):
848845
version=version
849846
).exclude(commit=commit).delete()
850847
# Purge Cache
851-
changed_files = [resolve_path(
852-
version.project, filename=fname, version_slug=version.slug,
853-
) for fname in changed_files]
854848
cdn_ids = getattr(settings, 'CDN_IDS', None)
855849
if cdn_ids:
856850
if version.project.slug in cdn_ids:
851+
changed_files = [resolve_path(
852+
version.project, filename=fname, version_slug=version.slug,
853+
) for fname in changed_files]
857854
purge(cdn_ids[version.project.slug], changed_files)
858855

859856

readthedocs/projects/urls/public.py

+5
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
public.project_embed,
4646
name='project_embed'),
4747

48+
# url((r'^(?P<project_slug>{project_slug})/tools/analytics/$'
49+
# .format(**pattern_opts)),
50+
# public.project_analytics,
51+
# name='project_analytics'),
52+
4853
url(r'^(?P<project_slug>{project_slug})/search/$'.format(**pattern_opts),
4954
public.elastic_project_search,
5055
name='elastic_project_search'),

readthedocs/projects/views/public.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -420,15 +420,15 @@ def project_embed(request, project_slug):
420420
project = get_object_or_404(Project.objects.protected(request.user),
421421
slug=project_slug)
422422
version = project.versions.get(slug=LATEST)
423-
files = version.imported_files.order_by('path')
423+
files = version.imported_files.filter(name__endswith='.html').order_by('path')
424424

425425
return render_to_response(
426426
'projects/project_embed.html',
427427
{
428428
'project': project,
429429
'files': files,
430430
'settings': {
431-
'GROK_API_HOST': settings.GROK_API_HOST,
431+
'PUBLIC_API_URL': settings.PUBLIC_API_URL,
432432
'URI': request.build_absolute_uri(location='/').rstrip('/')
433433
}
434434
},

readthedocs/settings/base.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
from readthedocs.core.settings import Settings
1010

1111
try:
12-
import readthedocsext.donate # noqa
13-
donate = True
12+
import readthedocsext # noqa
13+
ext = True
1414
except ImportError:
15-
donate = False
15+
ext = False
1616

1717

1818
_ = gettext = lambda s: s
@@ -113,9 +113,10 @@ def INSTALLED_APPS(self): # noqa
113113
'allauth.socialaccount.providers.bitbucket',
114114
'allauth.socialaccount.providers.bitbucket_oauth2',
115115
]
116-
if donate:
116+
if ext:
117117
apps.append('django_countries')
118118
apps.append('readthedocsext.donate')
119+
apps.append('readthedocsext.embed')
119120
return apps
120121

121122
TEMPLATE_LOADERS = (

readthedocs/templates/projects/project_embed.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
var project_tools = require('projects/tools');
2323
$(document).ready(function () {
2424
project_tools.init_embed({
25-
api_host: '{{ settings.GROK_API_HOST }}',
25+
api_host: '{{ settings.PUBLIC_API_URL }}',
2626
uri: '{{ settings.URI }}',
2727
project: '{{ project.slug }}'
2828
});

readthedocs/urls.py

+7
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@
8989
groups.append([
9090
url(r'^sustainability/', include('readthedocsext.donate.urls')),
9191
])
92+
93+
if 'readthedocsext.embed' in settings.INSTALLED_APPS:
94+
api_urls.insert(
95+
0,
96+
url(r'^api/v1/embed/', include('readthedocsext.embed.urls'))
97+
)
98+
9299
if not getattr(settings, 'USE_SUBDOMAIN', False) or settings.DEBUG:
93100
groups.insert(0, docs_urls)
94101
if getattr(settings, 'ALLOW_ADMIN', True):

0 commit comments

Comments
 (0)