|
| 1 | +--- |
| 2 | +title: "Home" |
| 3 | +format: |
| 4 | + html: |
| 5 | + toc: false |
| 6 | +--- |
| 7 | + |
| 8 | +The `options` Quarto extension allows developers to craft options that incorporate default parameters. |
| 9 | + |
| 10 | +## Usage |
| 11 | + |
| 12 | +The `options` extension does not introduce significant enhancements to your document's content. Instead, it serves as a way for authors to quickly bootstrap their own custom code cell through an [extension embedding](https://quarto.org/docs/journals/formats.html#extension-embedding). |
| 13 | + |
| 14 | +## Installation |
| 15 | + |
| 16 | +To install the `options` extension inside of your own extension, follow these steps: |
| 17 | + |
| 18 | +1. Open your terminal. |
| 19 | + |
| 20 | +2. Navigate to where your own extension's development location is. |
| 21 | + |
| 22 | +3. Execute the following command: |
| 23 | + |
| 24 | +```sh |
| 25 | +quarto add coatless-quarto/options --embed <your-extension-name> |
| 26 | +``` |
| 27 | + |
| 28 | +This command will download and install the extension under the `_extensions` subdirectory of your Quarto extension project. If you are using version control, ensure that you include this directory in your repository. |
| 29 | + |
| 30 | +### File structure |
| 31 | + |
| 32 | +When embedding the extension inside of your own extension, you should see the following folder structure: |
| 33 | + |
| 34 | +```sh |
| 35 | +. |
| 36 | +└── _extensions |
| 37 | + └── <your-extension-name> |
| 38 | + └── _extensions |
| 39 | + └── coatless-quarto |
| 40 | + └── options |
| 41 | + |
| 42 | +``` |
| 43 | + |
| 44 | +### Registering the extension |
| 45 | + |
| 46 | +Inside of the `_extension.yml`, please include the nested extension under `filters` as the first extension to run: |
| 47 | + |
| 48 | +``` |
| 49 | +title: My Extension |
| 50 | +author: My Name |
| 51 | +version: 0.1.1 |
| 52 | +quarto-required: ">=1.4.549" |
| 53 | +contributes: |
| 54 | + format: |
| 55 | + common: |
| 56 | + filters: |
| 57 | + - coatless-quarto/options |
| 58 | + - <your-extension>.lua |
| 59 | +``` |
| 60 | + |
| 61 | +## Retrieving Options |
| 62 | + |
| 63 | +Inside of the Lua filter, this extension can be used to setup: |
| 64 | + |
| 65 | +```lua |
| 66 | +-- Store function calls in a table value |
| 67 | +local options = require("_extensions.coatless-quarto.options.options") |
| 68 | + |
| 69 | +-- Attempt to retrieve option |
| 70 | +options.tryOption(options, key) |
| 71 | + |
| 72 | +-- Retrieve option if present, otherwise use default |
| 73 | +options.getOption(options, key, default) |
| 74 | +``` |
0 commit comments