### Install Aidoku Test Runner Source: https://github.com/aidoku/aidoku-rs/blob/main/book/src/ch04-00-debugging.md Install the aidoku-rs test runner from GitHub. This tool simulates the Aidoku environment for testing. ```sh cargo install --git https://github.com/Aidoku/aidoku-rs aidoku-test-runner ``` -------------------------------- ### Run Aidoku Log Server Source: https://github.com/aidoku/aidoku-rs/blob/main/book/src/ch04-00-debugging.md Start a log server to stream Aidoku logs to a provided URL. Ensure the device is on the same network. ```sh aidoku logcat ``` -------------------------------- ### Install Rust WebAssembly Toolchain Source: https://github.com/aidoku/aidoku-rs/blob/main/book/src/ch01-02-tooling.md Install the specific toolchain required for compiling Rust code to WebAssembly. This is a prerequisite for Aidoku-rs development. ```sh rustup install wasm32-unknown-unknown ``` -------------------------------- ### Install Aidoku CLI Source: https://github.com/aidoku/aidoku-rs/blob/main/book/src/ch01-02-tooling.md Install the Aidoku command-line interface from its Git repository. This tool provides essential functionality for Aidoku source development. ```sh cargo install --git https://github.com/Aidoku/aidoku-rs aidoku-cli ``` -------------------------------- ### Package Aidoku Source for Installation Source: https://github.com/aidoku/aidoku-rs/blob/main/book/src/ch02-00-creating-a-source.md Compile your Rust source code and bundle resources into an installable .aix file. This command should be run from your source's root directory. ```sh aidoku package ``` -------------------------------- ### Example source.json Structure Source: https://github.com/aidoku/aidoku-rs/blob/main/book/src/ch02-01-resource-files.md This JSON structure defines the basic components of a source.json file, including info, listings, and config. Ensure all required fields are present for a valid source. ```json { "info": { "id": "en.example-source", "name": "Example Source", "version": 1, "url": "https://aidoku.app", "contentRating": 0, "languages": ["en"] }, "listings": [ { "id": "test", "name": "Test" } ], "config": { "supportsTagSearch": true } } ``` -------------------------------- ### Write Aidoku Tests in Rust Source: https://github.com/aidoku/aidoku-rs/blob/main/book/src/ch04-00-debugging.md Write Rust tests using the `#[aidoku_test]` attribute. This example demonstrates JavaScript execution within a JsContext. ```rust #[cfg(test)] mod test { use super::*; use aidoku_test::aidoku_test; #[aidoku_test] fn test_js_execution() { use aidoku::imports::js::JsContext; let context = JsContext::new(); let result = context.eval("1 + 2"); assert_eq!(result, Ok(String::from("3"))); } } ``` -------------------------------- ### Parse HTML Content in Rust Source: https://github.com/aidoku/aidoku-rs/blob/main/book/src/ch02-02-the-rust-program.md Fetch HTML content from a URL and then use CSS selectors to extract specific elements. The `select_first` method finds the first matching element, and `text` or `attr` can be used to get its content or attribute. ```rust let html = Request::get("http://aidoku.app")?.html()?; let text = html .select_first("main.home .features > .feature h2") .and_then(|element| element.text()); let image = html .select_first(".image > img") .and_then(|element| element.attr("abs:src")); ``` -------------------------------- ### Initialize New Aidoku Source Project Source: https://github.com/aidoku/aidoku-rs/blob/main/book/src/ch02-00-creating-a-source.md Use this command to create the basic file structure and configuration for a new Aidoku source. You will be prompted for source details like name, URL, and language. ```sh aidoku init source_dir ``` -------------------------------- ### Aidoku CLI Commands Source: https://github.com/aidoku/aidoku-rs/blob/main/crates/cli/README.md Overview of the available commands for the aidoku-cli, including package, build, init, serve, and verify. ```ignore Usage: aidoku Commands: package Build and package a source build Build a source list init Initialize a new source serve Serve a source on the local network verify Verify a source is ready to be published help Print this message or the help of the given subcommand(s) Options: -h, --help Print help ``` -------------------------------- ### Run Aidoku Source Tests from Command Line Source: https://github.com/aidoku/aidoku-rs/blob/main/crates/test-runner/README.md Execute the aidoku-test-runner binary directly from your terminal, providing the path to the WASM file containing your Aidoku source tests. ```sh aidoku-test-runner ``` -------------------------------- ### Configure Aidoku Test Runner Source: https://github.com/aidoku/aidoku-rs/blob/main/book/src/ch04-00-debugging.md Configure your project to use the aidoku-test-runner by setting the build target and runner in `.cargo/config.toml`. ```toml [build] target = "wasm32-unknown-unknown" [target.wasm32-unknown-unknown] runner = "aidoku-test-runner" ``` -------------------------------- ### Configure Cargo Runner for Wasm Source: https://github.com/aidoku/aidoku-rs/blob/main/crates/test-macro/README.md Set up your `.cargo/config.toml` file to use the `aidoku-test-runner` for `wasm32-unknown-unknown` targets. This ensures `cargo test` automatically runs tests when compiling for Wasm. ```toml [target.wasm32-unknown-unknown] runner = "aidoku-test-runner" ``` -------------------------------- ### Registering a Custom Aidoku Source Source: https://github.com/aidoku/aidoku-rs/blob/main/book/src/ch02-02-the-rust-program.md Use the register_source! macro to expose your custom source and its implemented traits to the Aidoku app. Ensure all implemented traits, except the base Source trait, are listed. ```rust struct MySource; impl Source for MySource { ... } impl ImageRequestProvider for MySource { ... } impl DeepLinkHandler for MySource { ... } register_source!(MySource, ImageRequestProvider, DeepLinkHandler); ``` -------------------------------- ### Implement and Register Aidoku Source Source: https://github.com/aidoku/aidoku-rs/blob/main/crates/lib/README.md Implement the `Source` trait for your custom source and register it using the `register_source!` macro to export wasm functions. ```rust struct TestSource; impl Source for TestSource { // implement Source trait methods here } // register the source to export wasm functions register_source!(TestSource, Home); ``` -------------------------------- ### Make a Network Request in Rust Source: https://github.com/aidoku/aidoku-rs/blob/main/book/src/ch02-02-the-rust-program.md Use the `Request::get` function to fetch data from a URL. Headers can be added, and the response status can be checked. This function is blocking. ```rust let response: Response = Request::get("http://example.com")? .header("User-Agent", "Aidoku") .send()?; assert_eq!(response.status_code(), 200); ``` -------------------------------- ### Add Aidoku Test Dev Dependencies Source: https://github.com/aidoku/aidoku-rs/blob/main/crates/test-macro/README.md Include these dependencies in your Cargo.toml file for testing. The 'test' feature for aidoku disables its panic handler, allowing tests to run. ```toml [dev-dependencies] aidoku = { version = "1", features = ["test"] } # the "test" feature disables the panic handler, allowing tests to be run aidoku-test = "1" ``` -------------------------------- ### Verify Aidoku Package Source: https://github.com/aidoku/aidoku-rs/blob/main/book/src/ch02-01-resource-files.md Use the 'aidoku verify' command to check packaged sources against their schemas. This command ensures the integrity of the package. ```sh aidoku verify package.aix ``` -------------------------------- ### Configure JSON Schemas in Zed Editor Source: https://github.com/aidoku/aidoku-rs/blob/main/book/src/ch02-01-resource-files.md Configure the JSON language server settings in Zed for Aidoku resource files. The '...' indicates where the schema array would be placed. ```json "lsp": { "json-language-server": { "settings": { "json": { "schemas": [ ... ] } } } } ``` -------------------------------- ### Configure JSON Schemas in VS Code Source: https://github.com/aidoku/aidoku-rs/blob/main/book/src/ch02-01-resource-files.md Add this configuration to your VS Code settings.json to enable schema validation and autocompletion for Aidoku resource JSON files. ```json "json.schemas": [ { "fileMatch": ["*/res/source.json"], "url": "https://raw.githubusercontent.com/Aidoku/aidoku-rs/refs/heads/main/crates/cli/src/supporting/schema/source.schema.json" }, { "fileMatch": ["*/res/filters.json"], "url": "https://raw.githubusercontent.com/Aidoku/aidoku-rs/refs/heads/main/crates/cli/src/supporting/schema/filters.schema.json" }, { "fileMatch": ["*/res/settings.json"], "url": "https://raw.githubusercontent.com/Aidoku/aidoku-rs/refs/heads/main/crates/cli/src/supporting/schema/settings.schema.json" } ] ``` -------------------------------- ### Aidoku Error Handling with `error!` Macro Source: https://github.com/aidoku/aidoku-rs/blob/main/book/src/ch02-02-the-rust-program.md Construct an AidokuError using the error! macro for situations where an operation fails and you need to return an error. This is useful for indicating missing elements or failed lookups. ```rust let img_element = html.select("img").ok_or_else(|| error!("img element not found"))?; ``` -------------------------------- ### Aidoku Error Handling with `bail!` Macro Source: https://github.com/aidoku/aidoku-rs/blob/main/book/src/ch02-02-the-rust-program.md Use the bail! macro to immediately return an AidokuError from a function. This is convenient for early exits when a condition is not met, such as an optional value being None. ```rust let Some(img_element) = html.select("img") else { bail!("img element not found"); }; ``` -------------------------------- ### Apply Aidoku Test Attribute Source: https://github.com/aidoku/aidoku-rs/blob/main/crates/test-macro/README.md Use the `aidoku_test` attribute on your test functions in Rust code. This attribute is provided by the `aidoku-test` crate. ```rust #[cfg(test)] mod test { use aidoku_test::aidoku_test; #[aidoku_test] fn test_function() { assert_eq!(1, 1); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.