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

Make template gallery #499

Merged
merged 39 commits into from Feb 16, 2020
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
08af336
add template file
mariaschuld Jan 30, 2020
f750ac4
Merge branch 'master' of github.com:XanaduAI/pennylane
mariaschuld Jan 30, 2020
e120d80
Merge branch 'master' of github.com:XanaduAI/pennylane
mariaschuld Feb 5, 2020
3c470ce
design gallery
mariaschuld Feb 5, 2020
3862ff6
use custom directive and add more pics
mariaschuld Feb 6, 2020
c3b3bc8
add overview links
mariaschuld Feb 6, 2020
dbc2955
remove unnecessary files
mariaschuld Feb 6, 2020
6ea7c0f
delete a <div>
mariaschuld Feb 6, 2020
183f518
Merge branch 'master' into make_template_gallery
mariaschuld Feb 6, 2020
01c731f
Merge branch 'master' of github.com:XanaduAI/pennylane
mariaschuld Feb 6, 2020
b9e2026
add sphinx_gallery to requirements
mariaschuld Feb 6, 2020
75a4f07
Merge branch 'make_template_gallery' of github.com:XanaduAI/pennylane…
mariaschuld Feb 6, 2020
8385dfc
fix css clashes
josh146 Feb 6, 2020
66dc128
remove sphinx gallery
josh146 Feb 6, 2020
204fac7
Merge branch 'master' into make_template_gallery
antalszava Feb 7, 2020
0ba8536
Merge branch 'master' into make_template_gallery
co9olguy Feb 7, 2020
2255460
Merge branch 'master' into make_template_gallery
antalszava Feb 7, 2020
d9edb9e
Merge branch 'master' into make_template_gallery
josh146 Feb 7, 2020
fcd89d4
Merge branch 'master' of github.com:XanaduAI/pennylane
mariaschuld Feb 10, 2020
f683c99
Merge branch 'master' into make_template_gallery
mariaschuld Feb 10, 2020
38ef542
delete commented out lines
mariaschuld Feb 10, 2020
961be7a
add item to changelog
mariaschuld Feb 10, 2020
10df45d
remove tooltip
mariaschuld Feb 10, 2020
9a00945
Update doc/introduction/templates.rst
mariaschuld Feb 10, 2020
3353bc0
Update doc/_static/xanadu_gallery.css
mariaschuld Feb 10, 2020
a4aebce
fix merge conflict
mariaschuld Feb 10, 2020
10f6c1b
Merge branch 'make_template_gallery' of github.com:XanaduAI/pennylane…
mariaschuld Feb 10, 2020
9e261cc
polish text
mariaschuld Feb 10, 2020
c82fef4
make gallery items bigger
mariaschuld Feb 10, 2020
2b0226c
fix path problem
mariaschuld Feb 10, 2020
465feb7
revert some unecessary changes
mariaschuld Feb 10, 2020
671192c
fix CSS and directives
josh146 Feb 10, 2020
43b6276
use cards for gallery
mariaschuld Feb 10, 2020
a1e939c
make cards look nice
mariaschuld Feb 10, 2020
d6f13ac
fix conflict
mariaschuld Feb 10, 2020
e62ffa8
Merge branch 'master' into make_template_gallery
josh146 Feb 13, 2020
9ef87a8
fix size problem
mariaschuld Feb 14, 2020
712b05b
Merge branch 'make_template_gallery' of github.com:XanaduAI/pennylane…
mariaschuld Feb 14, 2020
d41f18c
Merge branch 'master' into make_template_gallery
josh146 Feb 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3,909 changes: 3,909 additions & 0 deletions doc/_static/templates/diagrams.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/_static/templates/embeddings/amplitude.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/_static/templates/embeddings/angle.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/_static/templates/embeddings/basis.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/_static/templates/embeddings/displacement.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/_static/templates/embeddings/qaoa.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/_static/templates/embeddings/squeezing.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/_static/templates/layers/cvqnn.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/_static/templates/layers/random.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 24 additions & 50 deletions doc/_static/xanadu_gallery.css
Expand Up @@ -6,22 +6,31 @@ scrolls, agogo, traditional, nature, haiku, pyramid
Tested for Read the Docs theme 0.1.7 */
.sphx-glr-thumbcontainer {
background: #fff;
border: solid #dedede 1px;
border: solid #dedede 0px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
box-shadow: none;
box-shadow: 0 2px 5px 0 rgba(0,0,0,.04),0 2px 25px 2px rgba(0,0,0,.04);
float: left;
margin: 5px;
min-height: 230px;
padding-top: 5px;
position: relative;
text-align: center;
border-radius: 10px;
transition: 0.5s cubic-bezier(0.25, 0.1, 0.25, 1);
}
.sphx-glr-thumbcontainer:hover {
border: solid #b4ddfc 1px;
box-shadow: 0 0 15px rgba(142, 176, 202, 0.5);
border: solid #b4ddfc 0px;
box-shadow: 0 2px 5px 0 rgba(0,0,0,.09),0 2px 40px 2px rgba(0,0,0,.09);
transition: 0.5s cubic-bezier(0.25, 0.1, 0.25, 1);
}
/*.sphx-glr-thumbcontainer:hover > .figure > img {*/
/*transform: scale(1.08);*/
/*transition: 0.5s cubic-bezier(0.25, 0.1, 0.25, 1);*/
/*}*/


.sphx-glr-thumbcontainer a.internal {
bottom: 0;
display: block;
Expand All @@ -30,12 +39,15 @@ Tested for Read the Docs theme 0.1.7 */
position: absolute;
right: 0;
top: 0;
color: #575757;
}

/* Next one is to avoid Sphinx traditional theme to cover all the
thumbnail with its default link Background color */
.sphx-glr-thumbcontainer a.internal:hover {
background-color: transparent;
color: #575757;
text-decoration: none;
}

.sphx-glr-thumbcontainer p {
Expand Down Expand Up @@ -63,6 +75,7 @@ thumbnail with its default link Background color */
z-index: 98;
width: 220px;
bottom: 52%;
display: none;
}
.sphx-glr-thumbcontainer[tooltip]:hover:before {
border: solid;
Expand All @@ -73,6 +86,7 @@ thumbnail with its default link Background color */
left: 85%;
position: absolute;
z-index: 99;
display: none;
}

.highlight-pytb pre {
Expand Down Expand Up @@ -211,55 +225,15 @@ p.sphx-glr-signature a.reference.external {
display: none;
}

.pennylane-call-to-action-links {
padding-top: 25px;
display: flex;
align-items: end;
/* justify-content: center; */
}

@media (min-width: 1100px) and (max-width: 1239px) {
.pennylane-call-to-action-links {
padding-top: rem(40px);
}
}

.pennylane-call-to-action-links #tutorial-type {
display: none;
}

.pennylane-call-to-action-links a {
padding-right: 20px;
color: #000;
cursor: pointer;
}

.pennylane-call-to-action-links a:hover {
color: #fdb104;
text-decoration: none;
}

#download-python-link,
#download-notebook-link,
#github-view-link {
padding-bottom: 10px;
/*border-bottom: 1px solid #c3c3c3;*/
padding-right: 40px;
display: flex;
align-items: center;
color: #747474;
}

#download-python-link:hover,
#download-notebook-link:hover,
#github-view-link:hover {
/*border-bottom-color: #19b37b;*/
color: #19b37b;
}

.sphx-glr-download-link-note.admonition.note,
.reference.download.internal,
.sphx-glr-signature {
display: none;
}

.sphx-glr-timing {
margin-bottom: 40px;
margin-top: 20px;
text-align: center;
font-size: small;
}
mariaschuld marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 3 additions & 2 deletions doc/conf.py
Expand Up @@ -405,8 +405,9 @@ def __getattr__(cls, name):
# inheritance_diagram graphviz attributes
inheritance_node_attrs = dict(color='lightskyblue1', style='filled')

from directives import UsageDetails

from directives import UsageDetails, CustomGalleryItemDirective

def setup(app):
app.add_directive('customgalleryitem', CustomGalleryItemDirective)
app.add_directive("usagedetails", UsageDetails)
app.add_stylesheet('xanadu_gallery.css')
mariaschuld marked this conversation as resolved.
Show resolved Hide resolved
92 changes: 92 additions & 0 deletions doc/directives.py
Expand Up @@ -14,6 +14,8 @@
r"""
Custom sphinx directives
"""
import re
import os
from docutils.parsers.rst import Directive, directives
from docutils.statemachine import StringList
from docutils import nodes
Expand Down Expand Up @@ -53,3 +55,93 @@ def run(self):
node = nodes.section()
self.state.nested_parse(string_list, self.content_offset, node)
return [node]


GALLERY_TEMPLATE = """
.. raw:: html

<div class="sphx-glr-thumbcontainer" tooltip="{tooltip}">

.. only:: html

.. figure:: /{thumbnail}

{description}

.. raw:: html

</div>
"""


class CustomGalleryItemDirective(Directive):
"""Create a sphinx gallery style thumbnail.
tooltip and figure are self explanatory. Description could be a link to
a document like in below example.
Example usage:
.. customgalleryitem::
:tooltip: I am writing this tutorial to focus specifically on NLP for people who have never written code in any deep learning framework
:figure: /_static/img/thumbnails/babel.jpg
:description: :doc:`/beginner/deep_learning_nlp_tutorial`
:size: put image size here
If figure is specified, a thumbnail will be made out of it and stored in
_static/thumbs. Therefore, consider _static/thumbs as a 'built' directory.
"""

required_arguments = 0
optional_arguments = 1
final_argument_whitespace = True
option_spec = {'tooltip': directives.unchanged,
'figure': directives.unchanged,
'description': directives.unchanged,
'size': directives.unchanged}
mariaschuld marked this conversation as resolved.
Show resolved Hide resolved

has_content = False
add_index = False

def run(self):
try:
if 'tooltip' in self.options:
tooltip = self.options['tooltip'][:195]
else:
raise ValueError('tooltip not found')

if 'figure' in self.options:
env = self.state.document.settings.env
rel_figname, figname = env.relfn2path(self.options['figure'])
thumbnail = self.options['figure']
# thumbnail = os.path.join('_static/thumbs/', os.path.basename(figname))

# try:
# os.makedirs('_static/thumbs')
# except FileExistsError:
# pass

# x, y = (400, 280)
# if 'size' in self.options:
# x, y = self.options['size'].split(" ")

# sphinx_gallery.gen_rst.scale_image(figname, thumbnail, int(x), int(y))
mariaschuld marked this conversation as resolved.
Show resolved Hide resolved
else:
thumbnail = '_static/thumbs/code.png'

if 'description' in self.options:
description = self.options['description']
else:
raise ValueError('description not doc found')

except FileNotFoundError as e:
print(e)
return []
except ValueError as e:
print(e)
raise
return []

thumbnail_rst = GALLERY_TEMPLATE.format(tooltip=tooltip,
thumbnail=thumbnail,
description=description)
thumbnail = StringList(thumbnail_rst.split('\n'))
thumb = nodes.paragraph()
self.state.nested_parse(thumbnail, self.content_offset, thumb)
return [thumb]