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

Migration: vocs #255

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
10 changes: 7 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
book
target
output
node_modules
.env

# Editors tmp files.
*~
Expand All @@ -10,3 +9,8 @@ output
.snfoundry_cache
.vscode/settings.json
**/starkli-wallet

# From previous mdbook build
book/*
target/*
src/**/*.md
87 changes: 37 additions & 50 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ Please note we have a code of conduct, please follow it in all your interactions
- [Contributing](#contributing)
- [Table of Contents](#table-of-contents)
- [Setup](#setup)
- [MdBook](#mdbook)
- [Working with Markdown Files](#working-with-markdown-files)
- [Adding a new chapter](#adding-a-new-chapter)
- [Adding a new Cairo program](#adding-a-new-cairo-program)
- [Verification script](#verification-script)
- [Tests](#tests)
- [Use of anchor](#use-of-anchor)
- [Translations](#translations)
- [Initiate a new translation for your language](#initiate-a-new-translation-for-your-language)
- [Use of region](#use-of-region)
- [Code of Conduct](#code-of-conduct)
- [Our Pledge](#our-pledge)
- [Our Standards](#our-standards)
Expand All @@ -31,29 +29,37 @@ Please note we have a code of conduct, please follow it in all your interactions

1. Clone this repository.

2. Rust related packages:
2. Install the required dependencies using pnpm:

- Install toolchain providing `cargo` using [rustup](https://rustup.rs/).
- Install [mdBook](https://rust-lang.github.io/mdBook/guide/installation.html) and the required extension with `cargo install mdbook mdbook-i18n-helpers mdbook-last-changed `.
```
pnpm i
```

3. Install `scarb` using [asdf](https://asdf-vm.com/) with `asdf install`. Alternatively, you can install `scarb` manually by following the instructions [here](https://docs.swmansion.com/scarb/).

## MdBook
4. Start the development server:

All the Markdown files **MUST** be edited in english. To work locally in english:
```
pnpm dev
```

- Start a local server with `mdbook serve` and visit [localhost:3000](http://localhost:3000) to view the book.
You can use the `--open` flag to open the browser automatically: `mdbook serve --open`.
## Working with Markdown Files

- Make changes to the book and refresh the browser to see the changes.
All Markdown files (\*.md) MUST be edited in English. Follow these steps to work locally with Markdown files:

- Open a PR with your changes.
- Make changes to the desired .md files in your preferred text editor.
- Save the changes, and your browser window should automatically refresh to reflect the updates.
- Once you've finished making your changes, build the application to ensure everything works as expected:
```
pnpm build
```
- If everything looks good, commit your changes and open a pull request with your modifications.

## Adding a new chapter

To add a new chapter, create a new markdown file in the `src` directory. All the Markdown files **MUST** be edited in english. In order to add them to the book, you need to add a link to it in the `src/SUMMARY.md` file.
- To add a new chapter, create a new markdown file in the `pages` directory. All the Markdown files **MUST** be edited in english. In order to add them to the book, you need to add in the `vocs.config.ts` file.

Do not write directly Cairo program inside the markdown files. Instead, use code blocks that import the Cairo programs from the `listing` directory. These programs are bundled into scarb projects, which makes it easier to test and build all programs. See the next section for more details.
- Do not write directly Cairo program inside the markdown files. Instead, use code blocks that import the Cairo programs from the `listings` directory. These programs are bundled into scarb projects, which makes it easier to test and build all programs. See the next section for more details.

Be sure to check for typos with `typos`:

Expand Down Expand Up @@ -183,27 +189,26 @@ mod tests {

You can use Starknet Foundry to write and run your tests.

### Use of anchor
### Use of region

You can add delimiting comments to select part of the code in the book.

```cairo
file.cairo:

a
// ANCHOR: anchor_name
// [!region region_name]
b
// ANCHOR_END: anchor_name
// [!endregion region_name]
c
```

Then, in the markdown file, you can use the following syntax to include only the code between the delimiting comments:

````markdown
````cairo
{{#include ../../listings/path/to/listing/src/contract.cairo:anchor_name}}
\```
````
```cairo
// [!include ~/listings/src/contract.cairo:region_name]
```
````

This will result in the following code being included in the book:
Expand All @@ -212,39 +217,21 @@ This will result in the following code being included in the book:
b
```

Using `#rustdoc_include` you can have the same result, but users can expand the code in the book to see the whole file (used for showing tests):
To render code in tabs format you can use `:::code-group`. Example you can render contract and tests in separate tabs like this:

````markdown
````cairo
{{#rustdoc_include ../../listings/path/to/listing/src/contract.cairo:anchor_name}}
\```
````
````

## Translations
:::code-group

> Translations efforts are currently on hold. If you are interested in helping out, please send a message in the telegram channel.
```cairo [contract]
// [!include ~/listings/src/contract.cairo:contract]
```

To work with translations, those are the steps to update the translated content:
```cairo [tests]
// [!include ~/listings/src/contract.cairo:tests]
```

- Run a local server for the language you want to edit: `./translations.sh zh-cn` for instance. If no language is provided, the script will only extract translations from english.

- Open the translation file you are interested in `po/zh-cn.po` for instance. You can also use editors like [poedit](https://poedit.net/) to help you on this task.

- When you are done, you should only have changes into the `po/xx.po` file. Commit them and open a PR.
The PR must stars with `i18n` to let the maintainers know that the PR is only changing translation.

The translation work is inspired from [Comprehensive Rust repository](https://github.com/google/comprehensive-rust/blob/main/TRANSLATIONS.md).

You can test to build the book with all translations using the `build.sh` script and serve locally the `book` directory.

### Initiate a new translation for your language

If you wish to initiate a new translation for your language without running a local server, consider the following tips:

- Execute the command `./translations.sh new xx` (replace `xx` with your language code). This method can generate the `xx.po` file of your language for you.
- To update your `xx.po` file, execute the command `./translations.sh xx` (replace `xx` with your language code), as mentioned in the previous chapter.
- If the `xx.po` file already exists (which means you are not initiating a new translation), you should not run this command.
:::
````

## Code of Conduct

Expand Down
2 changes: 0 additions & 2 deletions LANGUAGES

This file was deleted.

9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@ Please refer to the Contribution Guidelines page:
- [Contributing](CONTRIBUTING.md#contributing)
- [Table of Contents](CONTRIBUTING.md#table-of-contents)
- [Setup](CONTRIBUTING.md#setup)
- [MdBook](CONTRIBUTING.md#mdbook)
- [Working with Markdown Files](CONTRIBUTING.md#working-with-markdown-files)
- [Adding a new chapter](CONTRIBUTING.md#adding-a-new-chapter)
- [Adding a new Cairo program](CONTRIBUTING.md#adding-a-new-cairo-program)
- [Verification script](CONTRIBUTING.md#verification-script)
- [Tests](CONTRIBUTING.md#tests)
- [Use of anchor](CONTRIBUTING.md#use-of-anchor)
- [Translations](CONTRIBUTING.md#translations)
- [Initiate a new translation for your language](CONTRIBUTING.md#initiate-a-new-translation-for-your-language)
- [Use of region](CONTRIBUTING.md#use-of-region)
- [Code of Conduct](CONTRIBUTING.md#code-of-conduct)
- [Our Pledge](CONTRIBUTING.md#our-pledge)
- [Our Standards](CONTRIBUTING.md#our-standards)
- [Our Responsibilities](CONTRIBUTING.md#our-responsibilities)
- [Scope](CONTRIBUTING.md#scope)
- [Enforcement](CONTRIBUTING.md#enforcement)
- [Attribution](CONTRIBUTING.md#attribution)
- [Attribution](CONTRIBUTING.md#attribution)
33 changes: 0 additions & 33 deletions book.toml

This file was deleted.

9 changes: 0 additions & 9 deletions build.sh

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ANCHOR: contract
// [!endregion contract]
use core::starknet::eth_address::EthAddress;
use starknet::secp256_trait::{Signature};

Expand All @@ -7,6 +7,7 @@ use starknet::secp256_trait::{Signature};
// 1. Create message to sign
// 2. Hash the message
// 3. Sign the hash (off chain, keep your private key secret)
// [!region contract]
#[starknet::interface]
trait IVerifySignature<TContractState> {
fn get_signature(self: @TContractState, r: u256, s: u256, v: u32,) -> Signature;
Expand Down Expand Up @@ -89,7 +90,7 @@ mod verifySignature {
}
}
}
// ANCHOR_END: contract
// [!endregion contract]

#[cfg(test)]
mod tests {
Expand Down
6 changes: 4 additions & 2 deletions listings/advanced-concepts/hash_trait/src/hash_trait.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// [!region hash]
#[starknet::interface]
pub trait IHashTrait<T> {
fn save_user_with_poseidon(
Expand All @@ -8,7 +9,6 @@ pub trait IHashTrait<T> {
) -> felt252;
}

// ANCHOR: hash
#[starknet::contract]
pub mod HashTraits {
use starknet::storage::StoragePointerWriteAccess;
Expand Down Expand Up @@ -60,8 +60,9 @@ pub mod HashTraits {
}
}
}
// ANCHOR_END: hash
// [!endregion hash]

// [!region tests]
#[cfg(test)]
mod tests {
use starknet::SyscallResultTrait;
Expand Down Expand Up @@ -103,3 +104,4 @@ mod tests {
assert_eq!(test_hash, 0x4d165e1d398ae4864854518d3c58c3d7a21ed9c1f8f3618fbb0031d208aab7b);
}
}
// [!endregion tests]
8 changes: 4 additions & 4 deletions listings/applications/components/src/switchable.cairo
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// ANCHOR: component
// [!region component]
#[starknet::interface]
// ANCHOR: interface
// [!region interface]
pub trait ISwitchable<TContractState> {
fn is_on(self: @TContractState) -> bool;
fn switch(ref self: TContractState);
}
// ANCHOR_END: interface
// [!endregion interface]

#[starknet::component]
pub mod switchable_component {
Expand Down Expand Up @@ -48,7 +48,7 @@ pub mod switchable_component {
}
}
}
// ANCHOR_END: component
// [!endregion component]

// ANCHOR: contract
#[starknet::contract]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ANCHOR: contract
// [!region contract]
#[starknet::contract]
mod CountableContract {
use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess};
Expand Down Expand Up @@ -40,8 +40,9 @@ mod CountableContract {
CountableEvent: countable_component::Event,
}
}
// ANCHOR_END: contract
// [!endregion contract]

// [!region tests]
#[cfg(test)]
mod tests {
use super::CountableContract;
Expand Down Expand Up @@ -112,3 +113,4 @@ mod tests {
assert_eq!(counter.get(), 6);
}
}
// [!endregion tests]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ANCHOR: contract
// [!region contract]
#[starknet::contract]
mod CountableContract {
use components_dependencies::countable_dep_switch::countable_component;
Expand Down Expand Up @@ -33,8 +33,9 @@ mod CountableContract {
SwitchableEvent: switchable_component::Event,
}
}
// ANCHOR_END: contract
// [!endregion contract]

// [!region tests]
#[cfg(test)]
mod tests {
use super::CountableContract;
Expand Down Expand Up @@ -105,3 +106,4 @@ mod tests {
assert_eq!(counter.get(), 6);
}
}
// [!endregion tests]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ANCHOR: contract
// [!region contract]
#[starknet::contract]
pub mod CountableContract {
use components_dependencies::countable_internal_dep_switch::countable_component;
Expand Down Expand Up @@ -33,8 +33,9 @@ pub mod CountableContract {
SwitchableEvent: switchable_component::Event,
}
}
// ANCHOR_END: contract
// [!endregion contract]

// [!region tests]
#[cfg(test)]
mod tests {
use super::CountableContract;
Expand Down Expand Up @@ -103,3 +104,4 @@ mod tests {
assert_eq!(counter.get(), 3);
}
}
// [!endregion tests]
Loading
Loading