Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Pull in pydoctheme's layout and static assets
  • Loading branch information
Jon Wayne Parrott
Jon Wayne Parrott committed Jun 13, 2017
commit 9ade588f26e932147cc8d78b0e6bdfb9cc576a08
64 changes: 64 additions & 0 deletions pypa-theme/pypa_theme/layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{% extends "classic/layout.html" %}

{% block rootrellink %}
<li><img src="{{ pathto('_static/py.png', 1) }}" alt=""
style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.pypa.io/">PyPA</a>{{ reldelim1 }}</li>
<li>
{%- if versionswitcher is defined %}
<span class="version_switcher_placeholder">{{ release }}</span>
{%- endif %}
<a href="{{ pathto('index') }}">{{ shorttitle }}</a>{{ reldelim1 }}
</li>
{% endblock %}

{%- macro searchbox() %}
{# modified from sphinx/themes/basic/searchbox.html #}
{%- if builder != "htmlhelp" %}
<div class="inline-search" style="display: none" role="search">
<form class="inline-search" action="{{ pathto('search') }}" method="get">
<input placeholder="{{ _('Quick search') }}" type="text" name="q" />
<input type="submit" value="{{ _('Go') }}" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('.inline-search').show(0);</script>
{%- endif %}
{%- endmacro %}

{% block relbar1 %} {% if builder != 'qthelp' %} {{ relbar() }} {% endif %} {% endblock %}
{% block relbar2 %} {% if builder != 'qthelp' %} {{ relbar() }} {% endif %} {% endblock %}
{% block relbaritems %}
{%- if pagename != "search" and builder != "singlehtml" and builder != "htmlhelp" %}
<li class="right">
{{ searchbox() }}
{{ reldelim2 }}
</li>
{%- endif %}
{% endblock %}

{% block extrahead %}
<link rel="shortcut icon" type="image/png" href="{{ pathto('_static/py.png', 1) }}" />
{% if builder != "htmlhelp" %}
{% if not embedded %}
<script type="text/javascript" src="{{ pathto('_static/copybutton.js', 1) }}"></script>
{% endif %}
{% if versionswitcher is defined and not embedded %}<script type="text/javascript" src="{{ pathto('_static/version_switch.js', 1) }}"></script>{% endif %}
{% endif %}
{{ super() }}
{% endblock %}

{% block footer %}
<div class="footer">
&copy; <a href="{{ pathto('copyright') }}">{% trans %}Copyright{% endtrans %}</a> {{ copyright|e }}.
<br />
{% trans %}The Python Software Foundation is a non-profit corporation.{% endtrans %}
<a href="https://www.python.org/psf/donations/">{% trans %}Please donate.{% endtrans %}</a>
<br />
{% trans last_updated=last_updated|e %}Last updated on {{ last_updated }}.{% endtrans %}
{% if theme_issues_url %}{% trans pathto_bugs=theme_issues_url %}<a href="{{ theme_issues_url }}">Found a bug</a>?{% endtrans %}{% endif %}
<br />
{% trans sphinx_version=sphinx_version|e %}Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> {{ sphinx_version }}.{% endtrans %}
</div>
{% endblock %}
62 changes: 62 additions & 0 deletions pypa-theme/pypa_theme/static/copybutton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
$(document).ready(function() {
/* Add a [>>>] button on the top-right corner of code samples to hide
* the >>> and ... prompts and the output and thus make the code
* copyable. */
var div = $('.highlight-python .highlight,' +
'.highlight-python3 .highlight')
var pre = div.find('pre');

// get the styles from the current theme
pre.parent().parent().css('position', 'relative');
var hide_text = 'Hide the prompts and output';
var show_text = 'Show the prompts and output';
var border_width = pre.css('border-top-width');
var border_style = pre.css('border-top-style');
var border_color = pre.css('border-top-color');
var button_styles = {
'cursor':'pointer', 'position': 'absolute', 'top': '0', 'right': '0',
'border-color': border_color, 'border-style': border_style,
'border-width': border_width, 'color': border_color, 'text-size': '75%',
'font-family': 'monospace', 'padding-left': '0.2em', 'padding-right': '0.2em',
'border-radius': '0 3px 0 0'
}

// create and add the button to all the code blocks that contain >>>
div.each(function(index) {
var jthis = $(this);
if (jthis.find('.gp').length > 0) {
var button = $('<span class="copybutton">&gt;&gt;&gt;</span>');
button.css(button_styles)
button.attr('title', hide_text);
button.data('hidden', 'false');
jthis.prepend(button);
}
// tracebacks (.gt) contain bare text elements that need to be
// wrapped in a span to work with .nextUntil() (see later)
jthis.find('pre:has(.gt)').contents().filter(function() {
return ((this.nodeType == 3) && (this.data.trim().length > 0));
}).wrap('<span>');
});

// define the behavior of the button when it's clicked
$('.copybutton').click(function(e){
e.preventDefault();
var button = $(this);
if (button.data('hidden') === 'false') {
// hide the code output
button.parent().find('.go, .gp, .gt').hide();
button.next('pre').find('.gt').nextUntil('.gp, .go').css('visibility', 'hidden');
button.css('text-decoration', 'line-through');
button.attr('title', show_text);
button.data('hidden', 'true');
} else {
// show the code output
button.parent().find('.go, .gp, .gt').show();
button.next('pre').find('.gt').nextUntil('.gp, .go').css('visibility', 'visible');
button.css('text-decoration', 'none');
button.attr('title', hide_text);
button.data('hidden', 'false');
}
});
});

Binary file added pypa-theme/pypa_theme/static/py.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 67 additions & 0 deletions pypa-theme/pypa_theme/static/version_switch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
(function() {
'use strict';

var all_versions = {
'3.7': 'dev (3.7)',
'3.6': '3.6',
'3.5': '3.5',
'3.4': '3.4',
'3.3': '3.3',
'2.7': '2.7',
};

function build_select(current_version, current_release) {
var buf = ['<select>'];

$.each(all_versions, function(version, title) {
buf.push('<option value="' + version + '"');
if (version == current_version)
buf.push(' selected="selected">' + current_release + '</option>');
else
buf.push('>' + title + '</option>');
});

buf.push('</select>');
return buf.join('');
}

function patch_url(url, new_version) {
var url_re = /\.org\/(\d|py3k|dev|((release\/)?\d\.\d[\w\d\.]*))\//,
new_url = url.replace(url_re, '.org/' + new_version + '/');

if (new_url == url && !new_url.match(url_re)) {
// python 2 url without version?
new_url = url.replace(/\.org\//, '.org/' + new_version + '/');
}
return new_url;
}

function on_switch() {
var selected = $(this).children('option:selected').attr('value');

var url = window.location.href,
new_url = patch_url(url, selected);

if (new_url != url) {
// check beforehand if url exists, else redirect to version's start page
$.ajax({
url: new_url,
success: function() {
window.location.href = new_url;
},
error: function() {
window.location.href = 'https://docs.python.org/' + selected;
}
});
}
}

$(document).ready(function() {
var release = DOCUMENTATION_OPTIONS.VERSION;
var version = release.substr(0, 3);
var select = build_select(version, release);

$('.version_switcher_placeholder').html(select);
$('.version_switcher_placeholder select').bind('change', on_switch);
});
})();
1 change: 1 addition & 0 deletions pypa-theme/pypa_theme/theme.conf
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ visitedlinkcolor = #00608f
headtextcolor = #1a1a1a
headbgcolor = white
headlinkcolor = #aaaaaa
issues_url =
5 changes: 3 additions & 2 deletions source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
html_theme_options = {
'collapsiblesidebar': True,
'externalrefs': True,
'issues_url': 'https://github.com/pypa/python-packaging-user-guide/issues'
}

# Add any paths that contain custom themes here, relative to this directory.
Expand All @@ -138,7 +139,7 @@
# The name for this set of Sphinx documents.
# "<project> v<release> documentation" by default.
#
# html_title = 'python-packaging-user-guide'
html_title = 'Python Packaging User Guide'

# A shorter title for the navigation bar. Default is the same as html_title.
#
Expand Down Expand Up @@ -170,7 +171,7 @@
# bottom, using the given strftime format.
# The empty string is equivalent to '%b %d, %Y'.
#
# html_last_updated_fmt = None
html_last_updated_fmt = ''

# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
Expand Down