Skip to content

Commit

Permalink
deploy: 7ab5b8c
Browse files Browse the repository at this point in the history
  • Loading branch information
yzhang-23 committed Sep 1, 2023
1 parent b954be5 commit 1ea2d47
Show file tree
Hide file tree
Showing 155 changed files with 1,565 additions and 3,077 deletions.
2 changes: 1 addition & 1 deletion .buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: a952154b8a439336a090848d2e1ffeb2
config: 2798ec8b10d93ebc8b3e1dde778f2601
tags: 645f666f9bcd5a90fca523b33c5a78b7
60 changes: 47 additions & 13 deletions _sources/tutorials/modules/basics.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ Basics of Writing a Module
This page is intended to walk you through the basics of writing a module. Here
we focus purely on writing the module, not designing it. Because of how
PluginPlay works designing a module can sometimes be non-trivial; tips for
designing a module can be found (TODO: add link). This page assumes we are
designing a module can be found in :ref:`module_designing`. This page assumes we are
writing a module which computes the electric field, |e_field| of a series of
point charges as detailed (TODO: add link).
point charges as detailed in :ref:`module_development`.

Delcaring the Module
Declaring the Module
====================

In PluginPlay modules are implemented by inheriting from the ``ModuleBase``
Expand All @@ -52,9 +52,13 @@ The relevant lines are:
.. note::

Most libraries include more than one module, and given that declaring a
module requries a single line, it is not uncommon to declare multiple modules
module requires a single line, it is not uncommon to declare multiple modules
in a single header file.

.. note::

Declaring a module is not required if the module is written in Python.

Defining the Module
===================

Expand All @@ -74,9 +78,19 @@ to provide a short description about the algorithm implemented in the module.

For our ``CoulombsLaw`` module a basic constructor looks like:

.. literalinclude:: ../../../../tests/cxx/doc_snippets/coulombs_law.cpp
:language: c++
:lines: 23-39
.. tabs::

.. tab:: C++

.. literalinclude:: ../../../../tests/cxx/doc_snippets/coulombs_law.cpp
:language: c++
:lines: 36-39

.. tab:: Python

.. literalinclude:: ../../../../tests/python/doc_snippets/coulombslaw_force.py
:language: python
:lines: 20-25

One particularly nice feature of PluginPlay is that it can autogenerate
restructured text documentation for modules by scraping the meta-data and fields
Expand Down Expand Up @@ -117,9 +131,19 @@ module to aid in defining the module's ``run_`` member function. By convention
For defining our ``CoulombsLaw::run_`` member the relevant PluginPlay bits of
code are:

.. literalinclude:: ../../../../tests/cxx/doc_snippets/coulombs_law.cpp
:language: c++
:lines: 41-45,65-67
.. tabs::

.. tab:: C++

.. literalinclude:: ../../../../tests/cxx/doc_snippets/coulombs_law.cpp
:language: c++
:lines: 41-45,65-67

.. tab:: Python

.. literalinclude:: ../../../../tests/python/doc_snippets/coulombslaw_force.py
:language: python
:lines: 27-29,41-42

The inputs to a module are type-erased. Getting them back in a usable typed form
can be done automatically via template meta-programming. The details of this
Expand All @@ -134,9 +158,19 @@ returns a result map with the type-erased results.
The full definition of the ``run_`` member (including the source code for
computing the electric field) is:

.. literalinclude:: ../../../../tests/cxx/doc_snippets/coulombs_law.cpp
:language: c++
:lines: 41-67
.. tabs::

.. tab:: C++

.. literalinclude:: ../../../../tests/cxx/doc_snippets/coulombs_law.cpp
:language: c++
:lines: 41-67

.. tab:: Python

.. literalinclude:: ../../../../tests/python/doc_snippets/coulombslaw_force.py
:language: python
:lines: 27-42

Submodules
==========
Expand Down
4 changes: 3 additions & 1 deletion _sources/tutorials/modules/design.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
.. See the License for the specific language governing permissions and
.. limitations under the License.
.. _module_designing:

******************
Designing a Module
******************
Expand All @@ -22,7 +24,7 @@ provide any guidance on how to design your module.
Additional Inputs
=================

The property type APIs are necessarilly general and rigid. This can pose
The property type APIs are necessarily general and rigid. This can pose
difficulties when your module needs additional input. PluginPlay provides you
with two options for obtaining the extra input your module needs:

Expand Down
2 changes: 2 additions & 0 deletions _sources/tutorials/modules/index.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
.. See the License for the specific language governing permissions and
.. limitations under the License.
.. _module_development:

##################
Module Development
##################
Expand Down
89 changes: 89 additions & 0 deletions _static/tabs.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
.sphinx-tabs {
margin-bottom: 1rem;
}

[role="tablist"] {
border-bottom: 1px solid #a0b3bf;
}

.sphinx-tabs-tab {
position: relative;
font-family: Lato,'Helvetica Neue',Arial,Helvetica,sans-serif;
color: #1D5C87;
line-height: 24px;
margin: 0;
font-size: 16px;
font-weight: 400;
background-color: rgba(255, 255, 255, 0);
border-radius: 5px 5px 0 0;
border: 0;
padding: 1rem 1.5rem;
margin-bottom: 0;
}

.sphinx-tabs-tab[aria-selected="true"] {
font-weight: 700;
border: 1px solid #a0b3bf;
border-bottom: 1px solid white;
margin: -1px;
background-color: white;
}

.sphinx-tabs-tab:focus {
z-index: 1;
outline-offset: 1px;
}

.sphinx-tabs-panel {
position: relative;
padding: 1rem;
border: 1px solid #a0b3bf;
margin: 0px -1px -1px -1px;
border-radius: 0 0 5px 5px;
border-top: 0;
background: white;
}

.sphinx-tabs-panel.code-tab {
padding: 0.4rem;
}

.sphinx-tab img {
margin-bottom: 24 px;
}

/* Dark theme preference styling */

@media (prefers-color-scheme: dark) {
body[data-theme="auto"] .sphinx-tabs-panel {
color: white;
background-color: rgb(50, 50, 50);
}

body[data-theme="auto"] .sphinx-tabs-tab {
color: white;
background-color: rgba(255, 255, 255, 0.05);
}

body[data-theme="auto"] .sphinx-tabs-tab[aria-selected="true"] {
border-bottom: 1px solid rgb(50, 50, 50);
background-color: rgb(50, 50, 50);
}
}

/* Explicit dark theme styling */

body[data-theme="dark"] .sphinx-tabs-panel {
color: white;
background-color: rgb(50, 50, 50);
}

body[data-theme="dark"] .sphinx-tabs-tab {
color: white;
background-color: rgba(255, 255, 255, 0.05);
}

body[data-theme="dark"] .sphinx-tabs-tab[aria-selected="true"] {
border-bottom: 2px solid rgb(50, 50, 50);
background-color: rgb(50, 50, 50);
}
145 changes: 145 additions & 0 deletions _static/tabs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
try {
var session = window.sessionStorage || {};
} catch (e) {
var session = {};
}

window.addEventListener("DOMContentLoaded", () => {
const allTabs = document.querySelectorAll('.sphinx-tabs-tab');
const tabLists = document.querySelectorAll('[role="tablist"]');

allTabs.forEach(tab => {
tab.addEventListener("click", changeTabs);
});

tabLists.forEach(tabList => {
tabList.addEventListener("keydown", keyTabs);
});

// Restore group tab selection from session
const lastSelected = session.getItem('sphinx-tabs-last-selected');
if (lastSelected != null) selectNamedTabs(lastSelected);
});

/**
* Key focus left and right between sibling elements using arrows
* @param {Node} e the element in focus when key was pressed
*/
function keyTabs(e) {
const tab = e.target;
let nextTab = null;
if (e.keyCode === 39 || e.keyCode === 37) {
tab.setAttribute("tabindex", -1);
// Move right
if (e.keyCode === 39) {
nextTab = tab.nextElementSibling;
if (nextTab === null) {
nextTab = tab.parentNode.firstElementChild;
}
// Move left
} else if (e.keyCode === 37) {
nextTab = tab.previousElementSibling;
if (nextTab === null) {
nextTab = tab.parentNode.lastElementChild;
}
}
}

if (nextTab !== null) {
nextTab.setAttribute("tabindex", 0);
nextTab.focus();
}
}

/**
* Select or deselect clicked tab. If a group tab
* is selected, also select tab in other tabLists.
* @param {Node} e the element that was clicked
*/
function changeTabs(e) {
// Use this instead of the element that was clicked, in case it's a child
const notSelected = this.getAttribute("aria-selected") === "false";
const positionBefore = this.parentNode.getBoundingClientRect().top;
const notClosable = !this.parentNode.classList.contains("closeable");

deselectTabList(this);

if (notSelected || notClosable) {
selectTab(this);
const name = this.getAttribute("name");
selectNamedTabs(name, this.id);

if (this.classList.contains("group-tab")) {
// Persist during session
session.setItem('sphinx-tabs-last-selected', name);
}
}

const positionAfter = this.parentNode.getBoundingClientRect().top;
const positionDelta = positionAfter - positionBefore;
// Scroll to offset content resizing
window.scrollTo(0, window.scrollY + positionDelta);
}

/**
* Select tab and show associated panel.
* @param {Node} tab tab to select
*/
function selectTab(tab) {
tab.setAttribute("aria-selected", true);

// Show the associated panel
document
.getElementById(tab.getAttribute("aria-controls"))
.removeAttribute("hidden");
}

/**
* Hide the panels associated with all tabs within the
* tablist containing this tab.
* @param {Node} tab a tab within the tablist to deselect
*/
function deselectTabList(tab) {
const parent = tab.parentNode;
const grandparent = parent.parentNode;

Array.from(parent.children)
.forEach(t => t.setAttribute("aria-selected", false));

Array.from(grandparent.children)
.slice(1) // Skip tablist
.forEach(panel => panel.setAttribute("hidden", true));
}

/**
* Select grouped tabs with the same name, but no the tab
* with the given id.
* @param {Node} name name of grouped tab to be selected
* @param {Node} clickedId id of clicked tab
*/
function selectNamedTabs(name, clickedId=null) {
const groupedTabs = document.querySelectorAll(`.sphinx-tabs-tab[name="${name}"]`);
const tabLists = Array.from(groupedTabs).map(tab => tab.parentNode);

tabLists
.forEach(tabList => {
// Don't want to change the tabList containing the clicked tab
const clickedTab = tabList.querySelector(`[id="${clickedId}"]`);
if (clickedTab === null ) {
// Select first tab with matching name
const tab = tabList.querySelector(`.sphinx-tabs-tab[name="${name}"]`);
deselectTabList(tab);
selectTab(tab);
}
})
}

if (typeof exports === 'undefined') {
exports = {};
}

exports.keyTabs = keyTabs;
exports.changeTabs = changeTabs;
exports.selectTab = selectTab;
exports.deselectTabList = deselectTabList;
exports.selectNamedTabs = selectNamedTabs;
Loading

0 comments on commit 1ea2d47

Please sign in to comment.