Skip to content

Commit

Permalink
Fix width of code blocks in app dev tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-traverse committed Nov 11, 2024
1 parent bb90511 commit 29e98ef
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
7 changes: 7 additions & 0 deletions doc/app_dev/tutorial/error_handling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ with a validation error. Here is what that looks like using futures:

.. literalinclude:: ../../../examples/apps/javascript/src/error_handling.js
:language: JavaScript
:class: container
:lines: 64 - 71
:linenos:
:lineno-start: 64
Expand All @@ -36,6 +37,7 @@ Exactly the same error handling capability is available using callbacks:

.. literalinclude:: ../../../examples/apps/javascript/src/error_handling.js
:language: JavaScript
:class: container
:lines: 80 - 89
:linenos:
:lineno-start: 80
Expand All @@ -51,6 +53,7 @@ TRAC has a means to provide this information.

.. literalinclude:: ../../../examples/apps/javascript/src/error_handling.js
:language: JavaScript
:class: container
:lines: 98 - 105
:linenos:
:lineno-start: 98
Expand All @@ -62,6 +65,7 @@ information, this can be accessed by looking at the individual error items:

.. literalinclude:: ../../../examples/apps/javascript/src/error_handling.js
:language: JavaScript
:class: container
:lines: 106 - 109
:linenos:
:lineno-start: 106
Expand All @@ -83,6 +87,7 @@ With upload streams, the client sends a series of messages to the server and rec
or error in response. The error handler can be attached when you send the first message to the stream:

.. code-block:: javascript
:class: container
stream.createDataset(request0)
.then(_ => {...}) // Handle upload success
Expand All @@ -108,6 +113,7 @@ Because errors are processed using stream events, the futures / callback handler
to no-op functions to avoid unhandled or duplicate events.

.. code-block:: javascript
:class: container
// Handle the download stream
stream.on("data", msg => {...});
Expand Down Expand Up @@ -136,6 +142,7 @@ details of the stream event processing:

.. literalinclude:: ../../../examples/apps/javascript/src/error_handling.js
:language: JavaScript
:class: container
:lines: 146 - 152
:linenos:
:lineno-start: 146
17 changes: 16 additions & 1 deletion doc/app_dev/tutorial/hello_world.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ Installing the API
------------------

The easiest way to build web client applications for TRAC is using the web API package,
It is available to install with NPM::
It is available to install with NPM:

.. code-block::
:class: container
npm install --save tracdap-web-api
Expand Down Expand Up @@ -66,6 +69,7 @@ Start by importing the TRAC API package:

.. literalinclude:: ../../../examples/apps/javascript/src/hello_world.js
:language: JavaScript
:class: container
:lines: 18 - 18
:linenos:
:lineno-start: 18
Expand All @@ -74,6 +78,7 @@ We need two things to create the TRAC connection, an RPC transport and an instan
TRAC API class. You can use tracdap.setup to create an RPC transport that works in the browser.

.. code-block:: javascript
:class: container
:linenos:
:lineno-start: 20
Expand All @@ -89,6 +94,7 @@ In this example we only need the metadata API.

.. literalinclude:: ../../../examples/apps/javascript/src/hello_world.js
:language: JavaScript
:class: container
:lines: 24 - 25
:linenos:
:lineno-start: 24
Expand All @@ -102,6 +108,7 @@ In this case, you'll need to create an RPC connector pointed at the address of y

.. literalinclude:: ../../../examples/apps/javascript/src/hello_world.js
:language: JavaScript
:class: container
:lines: 20, 22

You'll also need to supply the global XMLHttpRequest object, which is not normally available outside a
Expand All @@ -110,6 +117,7 @@ package available on NPM:

.. literalinclude:: ../../../examples/apps/javascript/run_examples.js
:language: JavaScript
:class: container
:lines: 19 - 21


Expand All @@ -126,6 +134,7 @@ in code.

.. literalinclude:: ../../../examples/apps/javascript/src/hello_world.js
:language: JavaScript
:class: container
:lines: 28 - 58
:linenos:
:lineno-start: 28
Expand All @@ -144,6 +153,7 @@ Request objects from the ``tracdap.api`` package can be created the same way met

.. literalinclude:: ../../../examples/apps/javascript/src/hello_world.js
:language: JavaScript
:class: container
:lines: 60 - 76
:linenos:
:lineno-start: 60
Expand All @@ -169,6 +179,7 @@ to send our request to the TRAC metadata service.

.. literalinclude:: ../../../examples/apps/javascript/src/hello_world.js
:language: JavaScript
:class: container
:lines: 78 - 85
:linenos:
:lineno-start: 78
Expand All @@ -182,6 +193,7 @@ This example uses the future form, which allows chaining of ``.then()``, ``.catc
``.finally()`` blocks. The equivalent call using a callback would be:

.. code-block:: JavaScript
:class: container
metaApi.createObject(request, (err, header) => {
Expand All @@ -199,6 +211,7 @@ We can do this using a :class:`MetadataReadRequest<tracdap.api.MetadataReadReque

.. literalinclude:: ../../../examples/apps/javascript/src/hello_world.js
:language: JavaScript
:class: container
:lines: 87 - 93
:linenos:
:lineno-start: 87
Expand All @@ -213,6 +226,7 @@ Finally we use :meth:`readObject()<tracdap.api.TracMetadataApi.readObject>` to s

.. literalinclude:: ../../../examples/apps/javascript/src/hello_world.js
:language: JavaScript
:class: container
:lines: 95
:linenos:
:lineno-start: 95
Expand All @@ -234,6 +248,7 @@ a console or IDE. In this example we just create the schema and then load it bac

.. literalinclude:: ../../../examples/apps/javascript/src/hello_world.js
:language: JavaScript
:class: container
:lines: 97 -
:linenos:
:lineno-start: 97
Expand Down
6 changes: 6 additions & 0 deletions doc/app_dev/tutorial/metadata_mojo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Let's create a request for this search:

.. literalinclude:: ../../../examples/apps/javascript/src/metadata_mojo.js
:language: JavaScript
:class: container
:lines: 28 - 43
:linenos:
:lineno-start: 28
Expand All @@ -42,6 +43,7 @@ To execute the search we use the :meth:`search()<tracdap.api.TracMetadataApi.sea

.. literalinclude:: ../../../examples/apps/javascript/src/metadata_mojo.js
:language: JavaScript
:class: container
:lines: 48 - 61
:linenos:
:lineno-start: 48
Expand All @@ -65,6 +67,7 @@ Here is a simple example, starting with expression for the single term from the

.. literalinclude:: ../../../examples/apps/javascript/src/metadata_mojo.js
:language: JavaScript
:class: container
:lines: 63 - 72
:linenos:
:lineno-start: 63
Expand All @@ -74,6 +77,7 @@ is one of the business divisions we are interested in:

.. literalinclude:: ../../../examples/apps/javascript/src/metadata_mojo.js
:language: JavaScript
:class: container
:lines: 74 - 87
:linenos:
:lineno-start: 74
Expand All @@ -85,6 +89,7 @@ Now let's create a logical expression, which combines the two previous expressio

.. literalinclude:: ../../../examples/apps/javascript/src/metadata_mojo.js
:language: JavaScript
:class: container
:lines: 89 - 97
:linenos:
:lineno-start: 89
Expand All @@ -102,6 +107,7 @@ to call the :meth:`search()<tracdap.api.TracMetadataApi.search>` method of the

.. literalinclude:: ../../../examples/apps/javascript/src/metadata_mojo.js
:language: JavaScript
:class: container
:lines: 99 - 109
:linenos:
:lineno-start: 99
Expand Down
13 changes: 13 additions & 0 deletions doc/app_dev/tutorial/streaming.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and downloads, using a web sockets implementation based on the work by Improbabl
The TRAC transport is available as an option in the transport setup:

.. code-block:: javascript
:class: container
:linenos:
:lineno-start: 20
Expand All @@ -34,6 +35,7 @@ Or to run outside a browser:

.. literalinclude:: ../../../examples/apps/javascript/src/streaming.js
:language: JavaScript
:class: container
:lines: 20 - 24
:linenos:
:lineno-start: 20
Expand Down Expand Up @@ -61,6 +63,7 @@ except that the content can be empty.

.. literalinclude:: ../../../examples/apps/javascript/src/streaming.js
:language: JavaScript
:class: container
:lines: 50 - 64
:linenos:
:lineno-start: 50
Expand All @@ -70,6 +73,7 @@ to create an input stream, then passes the stream into the upload function:

.. literalinclude:: ../../../examples/apps/javascript/src/streaming.js
:language: JavaScript
:class: container
:lines: 161 - 162
:linenos:
:lineno-start: 161
Expand All @@ -81,6 +85,7 @@ which is different from the event streams used in Node.js and Protobuf.js.
TRAC provides a utility function to create an event stream, using a web ReadableStream as the source.

.. code-block:: javascript
:class: container
:linenos:
:lineno-start: 161
Expand All @@ -106,6 +111,7 @@ in a single stream.

.. literalinclude:: ../../../examples/apps/javascript/src/streaming.js
:language: JavaScript
:class: container
:lines: 65 - 74
:linenos:
:lineno-start: 65
Expand All @@ -117,6 +123,7 @@ so we can use this to complete the promise.

.. literalinclude:: ../../../examples/apps/javascript/src/streaming.js
:language: JavaScript
:class: container
:lines: 75 - 81
:linenos:
:lineno-start: 75
Expand All @@ -129,6 +136,7 @@ The "end" event signals that the source stream is complete.

.. literalinclude:: ../../../examples/apps/javascript/src/streaming.js
:language: JavaScript
:class: container
:lines: 82 - 95
:linenos:
:lineno-start: 82
Expand All @@ -143,6 +151,7 @@ Instead we want to reject the promise explicitly, to pass on the error informati

.. literalinclude:: ../../../examples/apps/javascript/src/streaming.js
:language: JavaScript
:class: container
:lines: 96 - 105
:linenos:
:lineno-start: 96
Expand All @@ -167,6 +176,7 @@ This is exactly the same as the request used to call

.. literalinclude:: ../../../examples/apps/javascript/src/streaming.js
:language: JavaScript
:class: container
:lines: 111 - 117
:linenos:
:lineno-start: 111
Expand All @@ -178,6 +188,7 @@ If there are any errors during the operation, the promise will be rejected.

.. literalinclude:: ../../../examples/apps/javascript/src/streaming.js
:language: JavaScript
:class: container
:lines: 123 - 128
:linenos:
:lineno-start: 123
Expand All @@ -197,6 +208,7 @@ utility function to aggregate them into a single

.. literalinclude:: ../../../examples/apps/javascript/src/streaming.js
:language: JavaScript
:class: container
:lines: 130 - 143
:linenos:
:lineno-start: 130
Expand All @@ -208,6 +220,7 @@ handlers, to prevent JavaScript warnings about unhandled results / errors.

.. literalinclude:: ../../../examples/apps/javascript/src/streaming.js
:language: JavaScript
:class: container
:lines: 145 - 154
:linenos:
:lineno-start: 145
Expand Down
Loading

0 comments on commit 29e98ef

Please sign in to comment.