From 4a7fa12eaabfeaf237a7cdc9cce7ea664e60471c Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Sun, 14 Feb 2021 15:39:39 +0100 Subject: [PATCH] config: add classlink directive We have index pages for most modules now, which link to individual classes. It is helpful if these empty class headers are hyperlinks. This commit does just that. For most sensors/devices so far this is not really necessary as the images are already hyperlinks. But this will become more useful as we start adding index pages like these for classes without images, such as parameters. --- doc/api/hubs/index.rst | 18 ++++++---------- doc/api/iodevices/index.rst | 21 +++++++------------ doc/api/pupdevices/index.rst | 33 ++++++++++-------------------- doc/common/conf.py | 1 + doc/common/extensions/classlink.py | 31 ++++++++++++++++++++++++++++ doc/ide/hubs/index.rst | 15 +++++--------- doc/ide/iodevices/index.rst | 3 +-- 7 files changed, 62 insertions(+), 60 deletions(-) create mode 100644 doc/common/extensions/classlink.py diff --git a/doc/api/hubs/index.rst b/doc/api/hubs/index.rst index 6cd0242..0368589 100644 --- a/doc/api/hubs/index.rst +++ b/doc/api/hubs/index.rst @@ -13,43 +13,37 @@ primehub ev3brick -.. class:: MoveHub - :noindex: +.. pybricks-classlink:: MoveHub .. figure:: ../../api/images/movehub.png :height: 10 em :target: movehub.html -.. class:: CityHub - :noindex: +.. pybricks-classlink:: CityHub .. figure:: ../../api/images/cityhub.png :height: 10 em :target: cityhub.html -.. class:: TechnicHub - :noindex: +.. pybricks-classlink:: TechnicHub .. figure:: ../../api/images/technichub.png :height: 10 em :target: technichub.html -.. class:: PrimeHub - :noindex: +.. pybricks-classlink:: PrimeHub .. figure:: ../../api/images/primehub.png :height: 10 em :target: primehub.html -.. class:: InventorHub - :noindex: +.. pybricks-classlink:: InventorHub .. figure:: ../../api/images/inventorhub.png :height: 10 em :target: primehub.html -.. class:: EV3Brick - :noindex: +.. pybricks-classlink:: EV3Brick .. figure:: ../../api/images/ev3brick.png :height: 10 em diff --git a/doc/api/iodevices/index.rst b/doc/api/iodevices/index.rst index 566cae8..9b1fe36 100644 --- a/doc/api/iodevices/index.rst +++ b/doc/api/iodevices/index.rst @@ -16,8 +16,7 @@ dcmotor ev3devsensor -.. class:: PUPDevice - :noindex: +.. pybricks-classlink:: PUPDevice .. figure:: ../../api/images/sensor_pup.png :width: 70 % @@ -25,43 +24,37 @@ This class is only available on Powered Up hubs. -.. class:: I2CDevice - :noindex: +.. pybricks-classlink:: I2CDevice .. figure:: ../../api/images/sensor_rj12_bluegreen.png :width: 25 % :target: i2cdevice.html -.. class:: UARTDevice - :noindex: +.. pybricks-classlink:: UARTDevice .. figure:: ../../api/images/sensor_rj12_gray.png :width: 25 % :target: uartdevice.html -.. class:: AnalogSensor - :noindex: +.. pybricks-classlink:: AnalogSensor .. figure:: ../../api/images/sensor_rj12_brown.png :width: 25 % :target: analogsensor.html -.. class:: LUMPDevice - :noindex: +.. pybricks-classlink:: LUMPDevice .. figure:: ../../api/images/sensor_rj12_green.png :width: 25 % :target: lumpdevice.html -.. class:: DCMotor - :noindex: +.. pybricks-classlink:: DCMotor .. figure:: ../../api/images/rcxmotor.png :width: 40 % :target: dcmotor.html -.. class:: Ev3devSensor - :noindex: +.. pybricks-classlink:: Ev3devSensor .. figure:: ../../api/images/sensor_ev3dev.png :width: 70 % diff --git a/doc/api/pupdevices/index.rst b/doc/api/pupdevices/index.rst index d973da3..9cbe29b 100644 --- a/doc/api/pupdevices/index.rst +++ b/doc/api/pupdevices/index.rst @@ -20,78 +20,67 @@ light remote -.. class:: DCMotor - :noindex: +.. pybricks-classlink:: DCMotor .. figure:: ../../api/images/pupdcmotors_label.png :width: 70 % :target: dcmotor.html -.. class:: Motor - :noindex: +.. pybricks-classlink:: Motor .. figure:: ../../api/images/pupmotors_label.png :width: 100 % :target: motor.html -.. class:: TiltSensor - :noindex: +.. pybricks-classlink:: TiltSensor .. figure:: ../../api/images/sensor_tilt.png :width: 35 % :target: tiltsensor.html -.. class:: InfraredSensor - :noindex: +.. pybricks-classlink:: InfraredSensor .. figure:: ../../api/images/sensor_proximity.png :width: 35 % :target: infraredsensor.html -.. class:: ColorDistanceSensor - :noindex: +.. pybricks-classlink:: ColorDistanceSensor .. figure:: ../../api/images/sensor_colordistance.png :width: 32 % :target: colordistancesensor.html -.. class:: PFMotor - :noindex: +.. pybricks-classlink:: PFMotor .. figure:: ../../api/images/pfmotor.png :width: 95 % :target: pfmotor.html -.. class:: ColorSensor - :noindex: +.. pybricks-classlink:: ColorSensor .. figure:: ../../api/images/sensor_color.png :width: 32 % :target: colorsensor.html -.. class:: UltrasonicSensor - :noindex: +.. pybricks-classlink:: UltrasonicSensor .. figure:: ../../api/images/sensor_ultrasonic.png :width: 37 % :target: ultrasonicsensor.html -.. class:: ForceSensor - :noindex: +.. pybricks-classlink:: ForceSensor .. figure:: ../../api/images/sensor_force.png :width: 35 % :target: forcesensor.html -.. class:: Light - :noindex: +.. pybricks-classlink:: Light .. figure:: ../../api/images/light.png :width: 90 % :target: light.html -.. class:: Remote - :noindex: +.. pybricks-classlink:: Remote .. figure:: ../../api/images/pupremote.png :width: 50 % diff --git a/doc/common/conf.py b/doc/common/conf.py index 40b32e4..c96da1b 100644 --- a/doc/common/conf.py +++ b/doc/common/conf.py @@ -59,6 +59,7 @@ extensions = [ 'sphinx.ext.todo', 'sphinx.ext.mathjax', 'color', + 'classlink', ] # Add any paths that contain templates here, relative to this directory. diff --git a/doc/common/extensions/classlink.py b/doc/common/extensions/classlink.py new file mode 100644 index 0000000..1404bd5 --- /dev/null +++ b/doc/common/extensions/classlink.py @@ -0,0 +1,31 @@ +from docutils import nodes +from docutils.parsers.rst import Directive + + +class PybricksClasslinkDirective(Directive): + + required_arguments = 1 + + def run(self): + # Get link name from sphinx-directive + name = self.arguments[0] + + html = ( + ''.format(name.lower()) + + '
' + + '
' + + 'class ' + + '' + name + '' + + '
' + + '
' + + '
' + + '
' + ) + + # Return the node + node = nodes.raw('', html, format="html") + return [node] + + +def setup(app): + app.add_directive_to_domain('py', 'pybricks-classlink', PybricksClasslinkDirective) diff --git a/doc/ide/hubs/index.rst b/doc/ide/hubs/index.rst index 4cb5460..1fa912c 100644 --- a/doc/ide/hubs/index.rst +++ b/doc/ide/hubs/index.rst @@ -12,36 +12,31 @@ technichub primehub -.. class:: MoveHub - :noindex: +.. pybricks-classlink:: MoveHub .. figure:: ../../api/images/movehub.png :height: 10 em :target: movehub.html -.. class:: CityHub - :noindex: +.. pybricks-classlink:: CityHub .. figure:: ../../api/images/cityhub.png :height: 10 em :target: cityhub.html -.. class:: TechnicHub - :noindex: +.. pybricks-classlink:: TechnicHub .. figure:: ../../api/images/technichub.png :height: 10 em :target: technichub.html -.. class:: PrimeHub - :noindex: +.. pybricks-classlink:: PrimeHub .. figure:: ../../api/images/primehub.png :height: 10 em :target: primehub.html -.. class:: InventorHub - :noindex: +.. pybricks-classlink:: InventorHub .. figure:: ../../api/images/inventorhub.png :height: 10 em diff --git a/doc/ide/iodevices/index.rst b/doc/ide/iodevices/index.rst index 386e5c8..db7478c 100644 --- a/doc/ide/iodevices/index.rst +++ b/doc/ide/iodevices/index.rst @@ -10,8 +10,7 @@ pupdevice -.. class:: PUPDevice - :noindex: +.. pybricks-classlink:: PUPDevice .. figure:: ../../api/images/sensor_pup.png :width: 70 %