Skip to content

Commit

Permalink
feat(docs): Use preprocessor syntax for including versions (#2462)
Browse files Browse the repository at this point in the history
Introduces a new `#include_aztec_version` and `#include_noir_version`
preprocessor macros that can be used to insert versions. Do not require
escaping the triple-backtick code block, which is annoying in parsing.
  • Loading branch information
spalladino authored Sep 21, 2023
1 parent d22c7b1 commit 7d315cd
Show file tree
Hide file tree
Showing 8 changed files with 444 additions and 354 deletions.
29 changes: 25 additions & 4 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ Most changes are reflected live without having to restart the server.
$ yarn build
```

This command generates static content into the `build` directory and can be served using any static contents hosting service.
This command generates static content into the `build` directory and can be served using any static contents hosting service. When run on Netlify, it will also build the typescript projects needed for extracting type information via typedoc.


## #include_code macro
## Macros

### `#include_code`

You can embed code snippets into a `.md`/`.mdx` file from code which lives elsewhere in the repo.
- In your markdown file:
Expand Down Expand Up @@ -119,7 +121,26 @@ You can embed code snippets into a `.md`/`.mdx` file from code which lives elsew
- `#include_code hello path/from/repo/root/to/file.ts typescript noTitle,noLineNumbers,noSourceLink`
- Ironically, we can't show you a rendering of these examples, because this README.md file doesn't support the `#include_code` macro!

> See [here](./src/components/GithubCode/index.js) for another way to include code, although this approach is flakier, so the above `#include_code` macro is preferred.

### `#include_aztec_version`

This macros will be replaced inline with the current aztec packages tag, which is `aztec-packages-v0.7.10` at the time of these writing. This value is sourced from `.release-please-manifest.json` on the project root.

### Another way to include code.
Alternatively, you can also use the `AztecPackagesVersion()` js function, which you need to import explicitly:

```
import { AztecPackagesVersion } from "@site/src/components/Version";
<>{AztecPackagesVersion()}</>
```
See [here](./src/components/GithubCode/index.js), although this approach is flakier, so the above `#include_code` macro is preferred.
### `#include_noir_version`
This macros will be replaced inline with the required nargo version, which is `0.11.1-aztec.0` at the time of these writing. This value is sourced from `yarn-project/noir-compiler/src/noir-version.json`.
Alternatively, you can also use the `NoirVersion()` js function, which you need to import explicitly:
```
import { NoirVersion } from "@site/src/components/Version";
<>{NoirVersion()}</>
```
17 changes: 8 additions & 9 deletions docs/docs/dev_docs/contracts/syntax/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,21 @@ Aztec.nr contains abstractions which remove the need to understand the low-level

To import Aztec.nr into your Aztec contract project, simply include it as a dependency. For example:

import { AztecPackagesVersion } from "@site/src/components/Version";

<CodeBlock language="toml">{`[package]
```toml
[package]
name = "token_contract"
authors = [""]
compiler_version = "0.1"
type = "contract"

[dependencies]
# Framework import
aztec = { git="https://github.com/AztecProtocol/aztec-packages/", tag="${AztecPackagesVersion()}", directory="yarn-project/aztec-nr/aztec" }
aztec = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/aztec-nr/aztec" }

# Utility dependencies
value_note = { git="https://github.com/AztecProtocol/aztec-packages/", tag="${AztecPackagesVersion()}", directory="yarn-project/aztec-nr/value-note"}
safe_math = { git="https://github.com/AztecProtocol/aztec-packages/", tag="${AztecPackagesVersion()}", directory="yarn-project/aztec-nr/safe-math"}
`}</CodeBlock>
value_note = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/aztec-nr/value-note"}
safe_math = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/aztec-nr/safe-math"}
```

:::info
Note: currently the dependency name ***MUST*** be `aztec`. The framework expects this namespace to be available when compiling into contracts. This limitation may be removed in the future.
Expand Down
13 changes: 6 additions & 7 deletions docs/docs/dev_docs/dapps/tutorials/contract_deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ nargo new --contract token

Then, open the `contracts/token/Nargo.toml` configuration file, and add the `aztec.nr` and `value_note` libraries as dependencies:

import { AztecPackagesVersion } from "@site/src/components/Version";

<CodeBlock language="toml">{`[dependencies]
aztec = { git="https://github.com/AztecProtocol/aztec-packages/", tag="${AztecPackagesVersion()}", directory="yarn-project/aztec-nr/aztec" }
value_note = { git="https://github.com/AztecProtocol/aztec-packages/", tag="${AztecPackagesVersion()}", directory="yarn-project/aztec-nr/value-note"}
safe_math = { git="https://github.com/AztecProtocol/aztec-packages/", tag="${AztecPackagesVersion()}", directory="yarn-project/aztec-nr/safe-math"}
`}</CodeBlock>
```toml
[dependencies]
aztec = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/aztec-nr/aztec" }
value_note = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/aztec-nr/value-note"}
safe_math = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/aztec-nr/safe-math"}
```

Last, copy-paste the code from the `Token` contract into `contracts/token/main.nr`:

Expand Down
9 changes: 4 additions & 5 deletions docs/docs/dev_docs/getting_started/noir_contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,16 @@ Before writing the contracts, we must add the aztec.nr library. This adds smart

3. Add aztec.nr library as a dependency to your noir project. Open Nargo.toml that is in the `contracts/example_contract` folder, and add the dependency section as follows:

import { AztecPackagesVersion } from "@site/src/components/Version";

<CodeBlock language="toml">{`[package]
```toml
[package]
name = "example_contract"
authors = [""]
compiler_version = "0.1"
type = "contract"

[dependencies]
aztec = { git="https://github.com/AztecProtocol/aztec-packages/", tag="master", directory="yarn-project/aztec-nr/aztec" }
`}</CodeBlock>
aztec = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/aztec-nr/aztec" }
```

:::note
You may need to update your dependencies depending on the contract that you are writing. For example, the token contract [imports more](../getting_started/token_contract_tutorial#project-setup).
Expand Down
15 changes: 7 additions & 8 deletions docs/docs/dev_docs/getting_started/token_contract_tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,18 @@ Your project should look like this:

Add the following dependencies to your Nargo.toml file, below the package information:

import { AztecPackagesVersion } from "@site/src/components/Version";

<CodeBlock language="toml">{`[package]
```toml
[package]
name = "token_contract"
authors = [""]
compiler_version = "0.1"
type = "contract"

[dependencies]
aztec = { git="https://github.com/AztecProtocol/aztec-packages/", tag="${AztecPackagesVersion()}", directory="yarn-project/aztec-nr/aztec" }
value_note = { git="https://github.com/AztecProtocol/aztec-packages/", tag="${AztecPackagesVersion()}", directory="yarn-project/aztec-nr/value-note"}
safe_math = { git="https://github.com/AztecProtocol/aztec-packages/", tag="${AztecPackagesVersion()}", directory="yarn-project/aztec-nr/safe-math"}
`}</CodeBlock>
aztec = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/aztec-nr/aztec" }
value_note = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/aztec-nr/value-note"}
safe_math = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="yarn-project/aztec-nr/safe-math"}
```

## Contract Interface

Expand Down
Loading

0 comments on commit 7d315cd

Please sign in to comment.