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

Add dark mode to documentation #1626

Merged
merged 3 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
622 changes: 622 additions & 0 deletions docs/_static/css/dark.css

Large diffs are not rendered by default.

77 changes: 77 additions & 0 deletions docs/_static/css/toggle.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
input[type=checkbox] {
visibility: hidden;
height: 0;
width: 0;
margin: 0;
}

.rst-versions .rst-current-version {
padding: 10px;
display: flex;
justify-content: space-between;
}

.rst-versions .rst-current-version .fa-book,
.rst-versions .rst-current-version .fa-v,
.rst-versions .rst-current-version .fa-caret-down {
height: 24px;
line-height: 24px;
vertical-align: middle;
}

.rst-versions .rst-current-version .fa-element {
width: 80px;
text-align: center;
}

.rst-versions .rst-current-version .fa-book {
text-align: left;
}

.rst-versions .rst-current-version .fa-v {
color: #27AE60;
text-align: right;
}

label {
margin: 0 auto;
display: inline-block;
justify-content: center;
align-items: right;
border-radius: 100px;
position: relative;
cursor: pointer;
text-indent: -9999px;
width: 50px;
height: 21px;
background: #000;
}

label:after {
border-radius: 50%;
position: absolute;
content: '';
background: #fff;
width: 15px;
height: 15px;
top: 3px;
left: 3px;
transition: ease-in-out 200ms;
}

input:checked+label {
background: #3a7ca8;
}

input:checked+label:after {
left: calc(100% - 5px);
transform: translateX(-100%);
}

html.transition,
html.transition *,
html.transition *:before,
html.transition *:after {
transition: ease-in-out 200ms !important;
transition-delay: 0 !important;
}
38 changes: 38 additions & 0 deletions docs/_static/js/toggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
document.addEventListener('DOMContentLoaded', function() {

function toggleCssMode(isDay) {
var mode = (isDay ? "Day" : "Night");
localStorage.setItem("css-mode", mode);

var daysheet = $('link[href="_static/pygments.css"]')[0].sheet;
daysheet.disabled = !isDay;

var nightsheet = $('link[href="_static/css/dark.css"]')[0];
if (!isDay && nightsheet === undefined) {
var element = document.createElement("link");
element.setAttribute("rel", "stylesheet");
element.setAttribute("type", "text/css");
element.setAttribute("href", "_static/css/dark.css");
document.getElementsByTagName("head")[0].appendChild(element);
return;
}
if (nightsheet !== undefined) {
nightsheet.sheet.disabled = isDay;
}
}

var initial = localStorage.getItem("css-mode") != "Night";
var checkbox = document.querySelector('input[name=mode]');

toggleCssMode(initial);
checkbox.checked = initial;

checkbox.addEventListener('change', function() {
document.documentElement.classList.add('transition');
window.setTimeout(() => {
document.documentElement.classList.remove('transition');
}, 1000)
toggleCssMode(this.checked);
})

});
36 changes: 36 additions & 0 deletions docs/_templates/versions.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{# Add rst-badge after rst-versions for small badge style. #}
<div class="rst-versions" data-toggle="rst-versions" role="note" aria-label="versions">
<span class="rst-current-version" data-toggle="rst-current-version">
<span class="fa fa-book fa-element"> RTD </span>

<span class="fa fa-element">
<input class="container_toggle" type="checkbox" id="switch" name="mode">
<label for="switch"></label>
</span>

<span class="fa fa-v fa-element"> v: {{ current_version }} <span class="fa fa-caret-down"></span></span>

</span>
<div class="rst-other-versions">
<dl>
<dt>{{ _('Versions') }}</dt> {% for slug, url in versions %}
<dd><a href="{{ url }}">{{ slug }}</a></dd>
{% endfor %}
</dl>
<dl>
<dt>{{ _('Downloads') }}</dt> {% for type, url in downloads %}
<dd><a href="{{ url }}">{{ type }}</a></dd>
{% endfor %}
</dl>
<dl>
{# Translators: The phrase "Read the Docs" is not translated #}
<dt>{{ _('On Read the Docs') }}</dt>
<dd>
<a href="//{{ PRODUCTION_DOMAIN }}/projects/{{ slug }}/?fromdocs={{ slug }}">{{ _('Project Home') }}</a>
</dd>
<dd>
<a href="//{{ PRODUCTION_DOMAIN }}/builds/{{ slug }}/?fromdocs={{ slug }}">{{ _('Builds') }}</a>
</dd>
</dl>
</div>
</div>
7 changes: 4 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,14 @@
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

def setup(app):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to leave this in?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't remove it, I'm just handling it using html_js_files instead of app.add_js_file. Both have the same effect, but html_js_files accepts multiple paths so it seemed more efficient.

Related documentation:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to change it back though if you prefer.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, interesting. The new way works for me!

app.add_js_file("js/matomo.js")
html_css_files = ["css/toggle.css"]

html_js_files = ["js/matomo.js", "js/toggle.js"]

# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
# directly to the root of the documentation.
#html_extra_path = []
html_extra_path = ["_static/css"]

# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
Expand Down
24 changes: 12 additions & 12 deletions docs/contracts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ Each Contract Factory exposes the following methods.
with transaction details being passed into the end portion of the
function call, and function arguments being passed into the first portion.

The ``block_identifier`` parameter is passed directly to the call at the end portion
The ``block_identifier`` parameter is passed directly to the call at the end portion
of the function call.

Returns the amount of gas consumed which can be used as a gas estimate for
Expand Down Expand Up @@ -351,7 +351,7 @@ Each Contract Factory exposes the following methods.
.. py:classmethod:: Contract.encodeABI(fn_name, args=None, kwargs=None, data=None)

Encodes the arguments using the Ethereum ABI for the contract function that
matches the given `fn_name` and arguements `args`. The `data` parameter
matches the given ``fn_name`` and arguments ``args``. The ``data`` parameter
defaults to the function selector.

.. code-block:: python
Expand All @@ -373,7 +373,7 @@ Each Contract Factory exposes the following methods.
.. py:classmethod:: Contract.get_function_by_signature(signature)

Searches for a distinct function with matching signature. Returns an instance of
:py:class:`ContractFunction` upon finding a match. Raises `ValueError` if no
:py:class:`ContractFunction` upon finding a match. Raises ``ValueError`` if no
match is found.

.. code-block:: python
Expand All @@ -397,7 +397,7 @@ Each Contract Factory exposes the following methods.
.. py:classmethod:: Contract.get_function_by_name(name)

Searches for a distinct function with matching name. Returns an instance of
:py:class:`ContractFunction` upon finding a match. Raises `ValueError` if no
:py:class:`ContractFunction` upon finding a match. Raises ``ValueError`` if no
match is found or if multiple matches are found.

.. code-block:: python
Expand All @@ -411,7 +411,7 @@ Each Contract Factory exposes the following methods.
Searches for a distinct function with matching selector.
The selector can be a hexadecimal string, bytes or int.
Returns an instance of :py:class:`ContractFunction` upon finding a match.
Raises `ValueError` if no match is found.
Raises ``ValueError`` if no match is found.

.. code-block:: python

Expand All @@ -438,7 +438,7 @@ Each Contract Factory exposes the following methods.
.. py:classmethod:: Contract.get_function_by_args(*args)

Searches for a distinct function with matching args. Returns an instance of
:py:class:`ContractFunction` upon finding a match. Raises `ValueError` if no
:py:class:`ContractFunction` upon finding a match. Raises ``ValueError`` if no
match is found or if multiple matches are found.

.. code-block:: python
Expand All @@ -448,16 +448,16 @@ Each Contract Factory exposes the following methods.


.. note::
`Contract` methods `all_functions`, `get_function_by_signature`, `find_functions_by_name`,
`get_function_by_name`, `get_function_by_selector`, `find_functions_by_args` and
`get_function_by_args` can only be used when abi is provided to the contract.
``Contract`` methods ``all_functions``, ``get_function_by_signature``, ``find_functions_by_name``,
``get_function_by_name``, ``get_function_by_selector``, ``find_functions_by_args`` and
``get_function_by_args`` can only be used when abi is provided to the contract.


.. note::
`Web3.py` rejects the initialization of contracts that have more than one function
Web3.py rejects the initialization of contracts that have more than one function
with the same selector or signature.
eg. `blockHashAddendsInexpansible(uint256)` and `blockHashAskewLimitary(uint256)` have the
same selector value equal to `0x00000000`. A contract containing both of these functions
eg. ``blockHashAddendsInexpansible(uint256)`` and ``blockHashAskewLimitary(uint256)`` have the
same selector value equal to ``0x00000000``. A contract containing both of these functions
will be rejected.


Expand Down
12 changes: 6 additions & 6 deletions docs/ethpm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ The ``Package`` class currently verifies the following things.
LinkableContract
----------------

`Py-EthPM` uses a custom subclass of ``Web3.contract.Contract`` to manage contract factories and instances which might require bytecode linking. To create a deployable contract factory, both the contract type's `abi` and `deployment_bytecode` must be available in the Package's manifest.
`Py-EthPM` uses a custom subclass of ``Web3.contract.Contract`` to manage contract factories and instances which might require bytecode linking. To create a deployable contract factory, both the contract type's ``abi`` and ``deployment_bytecode`` must be available in the Package's manifest.

.. doctest::

Expand Down Expand Up @@ -132,7 +132,7 @@ Methods

.. py:classmethod:: LinkableContract.link_bytecode(attr_dict)

This method returns a newly created contract factory with the applied link references defined in the `attr_dict`. This method expects `attr_dict` to be of the type ``Dict[`contract_name`: `address`]`` for all link references that are unlinked.
This method returns a newly created contract factory with the applied link references defined in the ``attr_dict``. This method expects ``attr_dict`` to be of the type ``Dict[`contract_name`: `address`]`` for all link references that are unlinked.

URI Schemes and Backends
------------------------
Expand Down Expand Up @@ -236,13 +236,13 @@ way through the EIP process)
- ``version``: The URI escaped version string, *should* conform to the
`semver <http://semver.org/>`__ version numbering specification.

i.e.
i.e.
- ``ethpm://packages.zeppelinos.eth/[email protected]``
- ``ethpm://0x808B53bF4D70A24bA5cb720D37A4835621A9df00:1/[email protected]``

To specify a specific asset within a package, you can namespace the target asset.

i.e.
i.e.
- ``ethpm://maker.snakecharmers.eth:1/[email protected]/sources/token.sol``
- ``ethpm://maker.snakecharmers.eth:1/[email protected]/contract_types/DSToken/abi``
- ``ethpm://maker.snakecharmers.eth:1/[email protected]/deployments/mainnet/dai``
Expand Down Expand Up @@ -391,7 +391,7 @@ To write a manifest to disk
Writes the active manifest to disk. Will not overwrite an existing manifest with the same name and root directory.

Defaults
- Writes manifest to current working directory (as returned by `os.getcwd()`) unless a ``Path`` is provided as manifest_root_dir.
- Writes manifest to current working directory (as returned by ``os.getcwd()``) unless a ``Path`` is provided as manifest_root_dir.
- Writes manifest with a filename of "<version>.json" unless desired manifest name (which must end in ".json") is provided as manifest_name.
- Writes the minified manifest version to disk unless prettify is set to True

Expand Down Expand Up @@ -553,7 +553,7 @@ To inline the source code directly in the manifest, use ``inline_source()`` or `

.. note::

`owned_compiler_output.json` below is expected to be the standard-json output generated by the solidity compiler as described `here <https://solidity.readthedocs.io/en/v0.4.24/using-the-compiler.html>`. The output must contain the `abi` and `bytecode` objects from compilation.
``owned_compiler_output.json`` below is expected to be the standard-json output generated by the solidity compiler as described `here <https://solidity.readthedocs.io/en/v0.4.24/using-the-compiler.html>`_. The output must contain the ``abi`` and ``bytecode`` objects from compilation.

.. doctest::

Expand Down
12 changes: 6 additions & 6 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,11 @@ it as a ``Package`` instance.

# Note. To use the web3.pm module, you will need to instantiate your w3 instance
# with a web3 provider connected to the chain on which your registry lives.

# The ethPM module is still experimental and subject to change,
# so for now we need to enable it via a temporary flag.
w3.enable_unstable_package_management_api()

# Then we need to set the registry address that we want to use.
# This should be an ENS address, but can also be a checksummed contract address.
w3.pm.set_registry("ens.snakecharmers.eth")
Expand All @@ -365,7 +365,7 @@ it as a ``Package`` instance.
ens_package = w3.pm.get_package("ethregistrar", "1.0.1")


Now that we have a ``Package`` representation of our target ethPM package, we can generate contract factories
Now that we have a ``Package`` representation of our target ethPM package, we can generate contract factories
and instances from this ``Package``. However, it's important to note that some packages might be missing
the necessary contract assets needed to generate an instance or a factory. You can use the
`ethPM explorer <http://explorer.ethpm.com/>`__ to figure out the names of the contract types and deployments
Expand All @@ -387,7 +387,7 @@ available within an ethPM package.

# To create a contract factory from a contract type located in an ethPM package.
registrar_factory = ens_package.get_contract_factory("BaseRegistrarImplementation")

# Now you can treat registrar_factory like any other Web3 Contract factory to deploy new instances!
# Note. This will deploy new instances to the chain of the connected provider (in this example, mainnet)
registrar_factory.constructor(...).transact()
Expand Down Expand Up @@ -433,8 +433,8 @@ In this guide we will interact with an existing token contract that we have
already deployed to a local testing chain. This guide assumes:

1. An existing token contract at a known address.
1. Access to the proper ``ABI`` for the given contract.
1. A `~web3.main.Web3` instance connected to a provider with an unlocked account which can send transactions.
2. Access to the proper ``ABI`` for the given contract.
3. A ``web3.main.Web3`` instance connected to a provider with an unlocked account which can send transactions.


Creating the contract factory
Expand Down
8 changes: 4 additions & 4 deletions docs/middleware.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Default Middleware

Some middlewares are added by default if you do not supply any. The defaults
are likely to change regularly, so this list may not include the latest version's defaults.
You can find the latest defaults in the constructor in `web3/manager.py`
You can find the latest defaults in the constructor in ``web3/manager.py``

AttributeDict
~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -68,10 +68,10 @@ HTTPRequestRetry
.. py:method:: web3.middleware.http_retry_request_middleware

This middleware is a default specifically for HTTPProvider that retries failed
requests that return the following errors: `ConnectionError`, `HTTPError`, `Timeout`,
`TooManyRedirects`. Additionally there is a whitelist that only allows certain
requests that return the following errors: ``ConnectionError``, ``HTTPError``, ``Timeout``,
``TooManyRedirects``. Additionally there is a whitelist that only allows certain
methods to be retried in order to not resend transactions, excluded methods are:
`eth_sendTransaction`, `personal_signAndSendTransaction`, `personal_sendTransaction`.
``eth_sendTransaction``, ``personal_signAndSendTransaction``, ``personal_sendTransaction``.

.. _Modifying_Middleware:

Expand Down
8 changes: 4 additions & 4 deletions docs/providers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ succesful connection it can make:

1. The connection specified by an environment variable, see :ref:`provider_uri`
2. :class:`~web3.providers.ipc.IPCProvider`, which looks for several IPC file locations.
`IPCProvider` will not automatically detect a testnet connection, it is suggested that the
user instead uses a `w3` instance from `web3.auto.infura` (e.g.
`from web3.auto.infura.ropsten import w3`) if they want to auto-detect a testnet.
``IPCProvider`` will not automatically detect a testnet connection, it is suggested that the
user instead uses a ``w3`` instance from ``web3.auto.infura`` (e.g.
``from web3.auto.infura.ropsten import w3``) if they want to auto-detect a testnet.
3. :class:`~web3.providers.rpc.HTTPProvider`, which attempts to connect to "http://localhost:8545"
4. None - if no providers are successful, you can still use Web3 APIs
4. ``None`` - if no providers are successful, you can still use Web3 APIs
that do not require a connection, like:

- :ref:`overview_type_conversions`
Expand Down
Loading