From 33713eed688dcdfa0ccfa8defaba1b436fbe98a4 Mon Sep 17 00:00:00 2001 From: Eric Holscher Date: Mon, 28 Oct 2013 20:08:37 -0700 Subject: [PATCH] Pass docroot to badge endpoint. --- media/javascript/readthedocs-doc-embed.js | 3 ++- readthedocs/builds/models.py | 10 ++++++---- readthedocs/restapi/views.py | 5 +++-- readthedocs/templates/sphinx/layout.html | 1 + 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/media/javascript/readthedocs-doc-embed.js b/media/javascript/readthedocs-doc-embed.js index a941503d8..95877d8ad 100644 --- a/media/javascript/readthedocs-doc-embed.js +++ b/media/javascript/readthedocs-doc-embed.js @@ -10,11 +10,12 @@ $(document).ready(function () { }, dataType: "jsonp", data: { - "format": "jsonp", project: READTHEDOCS_DATA['project'], version: READTHEDOCS_DATA['version'], page: READTHEDOCS_DATA['page'], theme: READTHEDOCS_DATA['theme'], + docroot: READTHEDOCS_DATA['docroot'] + format: "jsonp", }, success: function (data) { if (READTHEDOCS_DATA['theme'] != "sphinx_rtd_theme") { diff --git a/readthedocs/builds/models.py b/readthedocs/builds/models.py index 2ff110b78..775f86aa0 100644 --- a/readthedocs/builds/models.py +++ b/readthedocs/builds/models.py @@ -188,7 +188,7 @@ class Version(models.Model): return conf_py_path.replace('conf.py', '') - def get_github_url(self, filename): + def get_github_url(self, docroot, filename): GITHUB_REGEXS = [ re.compile('github.com/(.+)/(.+)(?:\.git){1}'), re.compile('github.com/(.+)/(.+)'), @@ -199,6 +199,8 @@ class Version(models.Model): repo_url = self.project.repo if 'github' not in repo_url: return '' + if not docroot: + return '' for regex in GITHUB_REGEXS: match = regex.search(repo_url) @@ -207,7 +209,6 @@ class Version(models.Model): break else: return '' - docroot = self.get_conf_py_path() repo = repo.rstrip('/') return GITHUB_URL.format( @@ -218,7 +219,7 @@ class Version(models.Model): path=filename, ) - def get_bitbucket_url(self, filename): + def get_bitbucket_url(self, docroot, filename): BB_REGEXS = [ re.compile('bitbucket.org/(.+)/(.+).git'), re.compile('bitbucket.org/(.+)/(.+)/'), @@ -229,6 +230,8 @@ class Version(models.Model): repo_url = self.project.repo if 'bitbucket' not in repo_url: return '' + if not docroot: + return '' for regex in BB_REGEXS: match = regex.search(repo_url) @@ -237,7 +240,6 @@ class Version(models.Model): break else: return '' - docroot = self.get_conf_py_path() repo = repo.rstrip('/') return BB_URL.format( diff --git a/readthedocs/restapi/views.py b/readthedocs/restapi/views.py index 8960fb82f..2b2c0b8a5 100644 --- a/readthedocs/restapi/views.py +++ b/readthedocs/restapi/views.py @@ -197,6 +197,7 @@ def footer_html(request): version_slug = request.GET.get('version', None) page_slug = request.GET.get('page', None) theme = request.GET.get('theme', False) + docroot = request.GET.get('docroot', '') new_theme = (theme == "sphinx_rtd_theme") using_theme = (theme == "default") project = get_object_or_404(Project, slug=project_slug) @@ -209,8 +210,8 @@ def footer_html(request): 'using_theme': using_theme, 'new_theme': new_theme, 'settings': settings, - 'github_url': version.get_github_url(page_slug), - 'bitbucket_url': version.get_bitbucket_url(page_slug), + 'github_url': version.get_github_url(docroot, page_slug), + 'bitbucket_url': version.get_bitbucket_url(docroot, page_slug), }) html = Template(TEMPLATE).render(context) return Response({"html": html}) diff --git a/readthedocs/templates/sphinx/layout.html b/readthedocs/templates/sphinx/layout.html index 5197a0a3d..0537a6abd 100644 --- a/readthedocs/templates/sphinx/layout.html +++ b/readthedocs/templates/sphinx/layout.html @@ -10,6 +10,7 @@ version: "{{ current_version }}", page: "{{ pagename }}", theme: "{{ html_theme }}" + docroot: "{{ conf_py_path }}", } // Old variables var doc_version = "{{ current_version }}";