### Install Kida from Source Source: https://github.com/lbliii/kida/blob/main/site/content/docs/get-started/installation.md Steps to clone the repository and install the package in editable mode. This is useful for development or contributing to the project. ```bash git clone https://github.com/lbliii/kida.git cd kida pip install -e . ``` ```bash git clone https://github.com/lbliii/kida.git cd kida uv sync ``` -------------------------------- ### Run FastAPI Async Example Source: https://github.com/lbliii/kida/blob/main/examples/README.md Installs necessary dependencies and runs the FastAPI integration example using Uvicorn. ```bash pip install fastapi uvicorn cd examples/fastapi_async && uvicorn app:app --reload ``` -------------------------------- ### Run Migration Examples Source: https://github.com/lbliii/kida/blob/main/examples/jinja2_migration/README.md Command to execute the migration example application using Python. This requires the project dependencies to be installed in the migration directory. ```bash cd examples/jinja2_migration && python app.py ``` -------------------------------- ### Run Profiling Example Source: https://github.com/lbliii/kida/blob/main/examples/profiling/README.md Executes the profiling example application located in the examples directory. This command initiates the render process with profiling enabled to demonstrate metric collection. ```bash cd examples/profiling && python app.py ``` -------------------------------- ### Create Kida HTML Template Source: https://github.com/lbliii/kida/blob/main/site/content/docs/get-started/quickstart.md An example of a Kida HTML template (`hello.html`) demonstrating variable output (`{{ title }}`, `{{ name }}`) and control flow blocks (`{% if %}`, `{% for %}`). Kida uses a unified `{% end %}` to close all blocks. ```html {{ title }}

Hello, {{ name }}!

{% if items %} {% end %} ``` -------------------------------- ### Render Basic HTML Template with Kida Source: https://github.com/lbliii/kida/blob/main/site/content/docs/get-started/_index.md Demonstrates how to render a simple HTML template using Kida's `Environment`. It initializes the environment, loads a string template, and renders it with a provided variable. The output is 'Hello, World!'. ```python from kida import Environment env = Environment() template = env.from_string("Hello, {{ name }}!") print(template.render(name="World")) ``` -------------------------------- ### Run DictLoader Example Source: https://github.com/lbliii/kida/blob/main/examples/README.md Demonstrates loading templates directly from a dictionary instead of the filesystem, which is useful for testing or single-file applications. ```bash cd examples/dict_loader && python app.py ``` -------------------------------- ### Verify Kida Installation Source: https://github.com/lbliii/kida/blob/main/site/content/docs/get-started/installation.md Methods to confirm that Kida is correctly installed by checking the library version. Can be executed via a Python script or directly from the terminal. ```python import kida print(kida.__version__) ``` ```bash python -c "import kida; print(kida.__version__)" ``` -------------------------------- ### Install Kida via Package Managers Source: https://github.com/lbliii/kida/blob/main/site/content/docs/get-started/installation.md Commands to install the kida-templates package using modern Python package managers. Use uv for faster dependency resolution or pip for standard environments. ```bash uv add kida-templates ``` ```bash pip install kida-templates ``` -------------------------------- ### Run Kida Examples Source: https://github.com/lbliii/kida/blob/main/examples/README.md A collection of shell commands to execute various Kida functionality demonstrations. Each command navigates to a specific example directory and runs the associated Python application. ```bash cd examples/hello && python app.py cd examples/file_loader && python app.py cd examples/components && python app.py cd examples/streaming && python app.py cd examples/async_rendering && python app.py cd examples/caching && python app.py cd examples/modern_syntax && python app.py cd examples/introspection && python app.py cd examples/htmx_partials && python app.py cd examples/bytecode_cache && python app.py cd examples/design_system && python app.py cd examples/llm_streaming && python app.py cd examples/concurrent && python app.py cd examples/profiling && python app.py ``` -------------------------------- ### Run Design System Example Application (Bash) Source: https://github.com/lbliii/kida/blob/main/examples/design_system/README.md This command navigates to the design system example directory and executes the Python application. It's used to run the live demonstration of the component library. ```bash cd examples/design_system && python app.py ``` -------------------------------- ### Run and Test Kida Loop Context Example Source: https://github.com/lbliii/kida/blob/main/examples/loop_context/README.md Commands to execute the loop context example application and run the associated test suite. ```bash cd examples/loop_context && python app.py ``` ```bash pytest examples/loop_context/ -v ``` -------------------------------- ### Run and Test HTMX Partial Examples Source: https://github.com/lbliii/kida/blob/main/examples/htmx_partials/README.md Commands to execute the example application and run the test suite for the HTMX partial rendering implementation. The application demonstrates the use of render_block to return specific template fragments. ```bash cd examples/htmx_partials && python app.py ``` ```bash pytest examples/htmx_partials/ -v ``` -------------------------------- ### Run Modern Syntax Examples with Python Source: https://github.com/lbliii/kida/blob/main/examples/modern_syntax/README.md Executes the Python application demonstrating modern syntax features. This command navigates to the example directory and runs the main script. ```bash cd examples/modern_syntax && python app.py ``` -------------------------------- ### Execute and Test RenderedTemplate Example Source: https://github.com/lbliii/kida/blob/main/examples/rendered_template/README.md Commands to run the example application and execute the test suite for the RenderedTemplate implementation. ```bash cd examples/rendered_template && python app.py ``` ```bash pytest examples/rendered_template/ -v ``` -------------------------------- ### Verify Installation from TestPyPI Source: https://github.com/lbliii/kida/blob/main/plan/rfc-kida-extraction.md Install the kida package from TestPyPI using pip to confirm that the publishing process was successful and the package is available for installation. ```bash pip install -i https://test.pypi.org/simple/ kida ``` -------------------------------- ### Run Template Introspection Example Source: https://github.com/lbliii/kida/blob/main/examples/introspection/README.md Executes the introspection demonstration script located in the examples directory. This script initializes the analysis engine to process template metadata. ```bash cd examples/introspection && python app.py ``` -------------------------------- ### Run Caching Example Source: https://github.com/lbliii/kida/blob/main/examples/caching/README.md This command navigates to the caching examples directory and runs the Python application. It's used to demonstrate the fragment caching functionality in action. ```bash cd examples/caching && python app.py ``` -------------------------------- ### Run Loop Context Helpers Example Source: https://github.com/lbliii/kida/blob/main/examples/README.md Demonstrates the use of loop variables like loop.first, loop.last, and loop.index within for-loops for enhanced template control. ```bash cd examples/loop_context && python app.py ``` -------------------------------- ### Run Migration Tests Source: https://github.com/lbliii/kida/blob/main/examples/jinja2_migration/README.md Command to execute the test suite for the Jinja2 migration examples using pytest. It validates that the templates render equivalent output. ```bash pytest examples/jinja2_migration/ -v ``` -------------------------------- ### Kida Variable Syntax Examples Source: https://github.com/lbliii/kida/blob/main/plan/rfc-kida-site.md Demonstrates basic variable output and expression evaluation within Kida templates. ```kida {{ name }} {{ user.email }} {{ items[0] }} {{ 1 + 2 }} ``` -------------------------------- ### Install Kida Package Source: https://github.com/lbliii/kida/blob/main/site/content/docs/tutorials/migrate-from-jinja2.md Installs the Kida package using pip. This is the first step in migrating to Kida. ```bash pip install kida ``` -------------------------------- ### Execute Project Tests Source: https://github.com/lbliii/kida/blob/main/examples/README.md Commands to run the end-to-end test suite for the Kida examples using pytest. ```bash # All examples pytest examples/ # One example pytest examples/hello/ ``` -------------------------------- ### Install Kida Performance Dependencies Source: https://github.com/lbliii/kida/blob/main/site/content/docs/about/performance.md Commands to install optional C-extensions for faster HTML escaping. Using MarkupSafe via the 'perf' extra significantly reduces overhead for templates with many interpolated values. ```bash pip install kida[perf] # or: uv sync --optional perf ``` -------------------------------- ### Migrating from Jinja2 to Kida Source: https://github.com/lbliii/kida/blob/main/plan/rfc-kida-site.md Provides code examples for updating imports, environment initialization, and syntax adjustments when migrating from Jinja2 to Kida. ```python from kida import Environment, FileSystemLoader env = Environment( loader=FileSystemLoader('templates'), autoescape=True, ) # Verification template = env.from_string("Hello, {{ name }}!") result = template.render(name="World") assert result == "Hello, World!" ``` ```bash pip install kida ``` -------------------------------- ### Run RenderedTemplate Lazy Wrapper Example Source: https://github.com/lbliii/kida/blob/main/examples/README.md Illustrates the use of RenderedTemplate to wrap a template and context, allowing for lazy rendering or streaming without pre-rendering. ```bash cd examples/rendered_template && python app.py ``` -------------------------------- ### Run Kida Custom Filters Example Source: https://github.com/lbliii/kida/blob/main/examples/custom_filters/README.md Command to execute the Kida custom filters example application. This will likely demonstrate the usage of registered filters and tests in a live environment. Navigate to the specified directory before running. ```bash cd examples/custom_filters && python app.py ``` -------------------------------- ### Install Kida via pip Source: https://github.com/lbliii/kida/blob/main/README.md Command to install the kida-templates package using the Python package manager. ```bash pip install kida-templates ``` -------------------------------- ### Kida Home Page Template Example Source: https://github.com/lbliii/kida/blob/main/site/content/docs/tutorials/flask-integration.md An example of a Kida home page template (`home.html`) that extends the base template and defines the title and content blocks. ```kida {% extends "base.html" %} {% block title %}{{ title }}{% end %} {% block content %}

{{ title }}

Welcome to the site!

{% end %} ``` -------------------------------- ### Run t-string Interpolation Example Source: https://github.com/lbliii/kida/blob/main/examples/README.md Demonstrates high-frequency string interpolation using Python 3.14+ t-strings with automatic HTML escaping via the k() function. ```bash cd examples/t_string && python app.py ``` -------------------------------- ### Template Loaders in Kida Source: https://github.com/lbliii/kida/blob/main/site/content/releases/0.2.0.md Examples of using ChoiceLoader, PrefixLoader, PackageLoader, and FunctionLoader to manage template sources. ```python from kida import ChoiceLoader, FileSystemLoader loader = ChoiceLoader([ FileSystemLoader("themes/custom/"), FileSystemLoader("themes/default/"), ]) ``` ```python from kida import PrefixLoader, FileSystemLoader, DictLoader loader = PrefixLoader({ "app": FileSystemLoader("templates/app/"), "admin": FileSystemLoader("templates/admin/"), "shared": DictLoader({"header.html": "
"}), }) env.get_template("app/index.html") ``` ```python from kida import PackageLoader loader = PackageLoader("my_framework", "templates") ``` ```python from kida import FunctionLoader loader = FunctionLoader(lambda name: my_db.get_template(name)) ``` -------------------------------- ### Install Kida with Optional C Extension in Bash Source: https://github.com/lbliii/kida/blob/main/plan/rfc-performance-optimization.md This bash command demonstrates how to install Kida with an optional C extension for enhanced performance in HTML escaping. This approach aligns with Kida's 'pure Python' goal by making the C extension an opt-in feature. ```bash pip install kida[fast] # Installs kida-speedups C extension ``` -------------------------------- ### Kida Pattern Matching Example Source: https://github.com/lbliii/kida/blob/main/site/content/docs/tutorials/migrate-from-jinja2.md Shows Kida's pattern matching syntax using `{% match %}`, `{% case %}`, and `{% end %}` for conditional logic. ```kida {% match status %} {% case "active" %} ✓ Active {% case "pending" %} ⏳ Pending {% case _ %} Unknown {% end %} ``` -------------------------------- ### FastAPI Integration with Kida Source: https://github.com/lbliii/kida/blob/main/site/content/docs/tutorials/flask-integration.md Shows a basic example of integrating Kida with the FastAPI web framework, demonstrating how to set up the Kida environment and render templates within FastAPI routes. ```python from fastapi import FastAPI from fastapi.responses import HTMLResponse from kida import Environment, FileSystemLoader app = FastAPI() kida_env = Environment(loader=FileSystemLoader("templates/")) @app.get("/", response_class=HTMLResponse) def home(): template = kida_env.get_template("home.html") return template.render(title="FastAPI + Kida") ``` -------------------------------- ### Configure Cache and TTL Settings Source: https://github.com/lbliii/kida/blob/main/site/content/docs/reference/configuration.md Examples for setting cache sizes and TTL values for fragments, including template-level overrides. ```python # Small cache (testing) cache_size=10 # Large cache (production) cache_size=1000 # Short TTL for development fragment_ttl=1.0 # Longer TTL for production fragment_ttl=3600.0 # 1 hour ``` ```kida {% cache "user-" ~ user.id, ttl="5m" %} {{ render_profile(user) }} {% end %} ``` -------------------------------- ### Install Kida Templates Source: https://github.com/lbliii/kida/blob/main/docs/releases/v0.2.6.md Command to upgrade the Kida templates package to the latest version. ```bash pip install -U kida-templates ``` -------------------------------- ### Kida Block Caching Example Source: https://github.com/lbliii/kida/blob/main/site/content/docs/about/comparison.md Demonstrates Kida's block caching feature using `{% cache %}`. This allows for performance optimization by storing and reusing the output of template sections. ```kida {% cache "sidebar-" ~ user.id %} {{ render_sidebar(user) }} {% end %} ``` -------------------------------- ### Run Python Script to Render Template Source: https://github.com/lbliii/kida/blob/main/site/content/docs/get-started/quickstart.md Command to execute the Python script that renders the Kida template. This step assumes the `render.py` script and the `templates/hello.html` file are in the correct locations. ```bash python render.py ``` -------------------------------- ### Concurrent Template Rendering with Python 3.14t Source: https://github.com/lbliii/kida/blob/main/site/content/docs/get-started/installation.md Demonstrates how to utilize Python 3.14t's free-threading (no GIL) to render templates in parallel using ThreadPoolExecutor. This maximizes performance for compute-heavy rendering tasks. ```python from concurrent.futures import ThreadPoolExecutor from kida import Environment env = Environment() template = env.from_string("Hello, {{ name }}!") with ThreadPoolExecutor(max_workers=4) as executor: results = list(executor.map( lambda n: template.render(name=n), ["Alice", "Bob", "Charlie", "Diana"] )) ``` -------------------------------- ### Upgrade Kida Templates using PIP Source: https://github.com/lbliii/kida/blob/main/site/content/releases/_index.md This command upgrades the 'kida-templates' package using the standard 'pip' package manager. Ensure 'pip' is installed and accessible in your environment. ```bash pip install --upgrade kida-templates ``` -------------------------------- ### Development Environment Setup Source: https://github.com/lbliii/kida/blob/main/README.md Commands to clone the repository and initialize the development environment using uv with Python 3.14t. This includes dependency synchronization and running the test suite with the GIL disabled. ```bash git clone https://github.com/lbliii/kida.git cd kida # Uses Python 3.14t by default (.python-version) uv sync --group dev --python 3.14t PYTHON_GIL=0 uv run --python 3.14t pytest ``` -------------------------------- ### Upgrade Kida Templates using UV Source: https://github.com/lbliii/kida/blob/main/site/content/releases/_index.md This command upgrades the 'kida-templates' package using the 'uv pip' package manager. Ensure 'uv' is installed and configured in your environment. ```bash uv pip install --upgrade kida-templates ``` -------------------------------- ### Run Pytest for Kida Custom Filters Source: https://github.com/lbliii/kida/blob/main/examples/custom_filters/README.md Command to run pytest for the Kida custom filters example. This command will execute the test suite located in the specified directory, providing verbose output. Ensure pytest is installed and configured. ```bash pytest examples/custom_filters/ -v ``` -------------------------------- ### Run All Comparison Benchmarks (Bash) Source: https://github.com/lbliii/kida/blob/main/benchmarks/RESULTS.md Executes all comparison benchmarks for Kida and Jinja2 using pytest. This command aggregates results from various benchmark files, including full comparison, streaming, cold start, and scaling tests. Ensure pytest and the necessary benchmark files are installed and accessible. ```bash # Run all comparison benchmarks pytest benchmarks/test_benchmark_full_comparison.py benchmarks/test_benchmark_streaming.py \ benchmarks/test_benchmark_cold_start.py benchmarks/test_benchmark_scaling.py \ benchmarks/test_benchmark_scaling_depth.py --benchmark-only -v ``` -------------------------------- ### Test Modern Syntax Examples with Pytest Source: https://github.com/lbliii/kida/blob/main/examples/modern_syntax/README.md Runs tests for the modern syntax examples using pytest. This command ensures the functionality of the implemented features. ```bash pytest examples/modern_syntax/ -v ``` -------------------------------- ### Initialize Kida Environment Source: https://github.com/lbliii/kida/blob/main/site/content/docs/reference/configuration.md Demonstrates how to instantiate the Kida Environment with essential settings like loaders, auto-escaping, and cache parameters. ```python from kida import Environment, FileSystemLoader env = Environment( loader=FileSystemLoader("templates/"), autoescape=True, auto_reload=True, cache_size=400, fragment_cache_size=1000, fragment_ttl=300.0, ) ``` -------------------------------- ### Build and Publish Kida to TestPyPI Source: https://github.com/lbliii/kida/blob/main/plan/rfc-kida-extraction.md Build the kida package using `uv build` and then publish it to the TestPyPI repository using `uv publish --publish-url https://test.pypi.org/legacy/`. This allows for testing the installation process before releasing to the main PyPI. ```bash cd kida uv build uv publish --publish-url https://test.pypi.org/legacy/ ``` -------------------------------- ### Kida Macro: Single Responsibility Example Source: https://github.com/lbliii/kida/blob/main/site/content/docs/syntax/functions.md Provides an example of a Kida macro adhering to the single responsibility principle, focusing on a clear and concise purpose. It contrasts this with an example of a macro that attempts to do too much. ```kida {# Good: Single purpose #} {% def user_avatar(user, size=32) %} {{ user.name }} {% end %} {# Avoid: Too much logic #} {% def user_card_with_everything(user, show_bio, show_posts, ...) %} ... {% end %} ``` -------------------------------- ### Initialize Kida Environment with FileSystemLoader Source: https://github.com/lbliii/kida/blob/main/site/content/docs/reference/api.md Demonstrates how to create an Environment instance for Kida, specifying a FileSystemLoader for template retrieval and enabling HTML auto-escaping. This is the primary way to set up Kida for rendering templates from files. ```python from kida import Environment, FileSystemLoader env = Environment( loader=FileSystemLoader("templates/"), autoescape=True, ) ``` -------------------------------- ### Load and Render Templates in Python Source: https://github.com/lbliii/kida/blob/main/site/content/docs/usage/_index.md Demonstrates how to create a Kida environment with a FileSystemLoader, load a template, and render it with context variables. It also shows how to compile and render a template directly from a string. ```python from kida import Environment, FileSystemLoader # Create environment env = Environment( loader=FileSystemLoader("templates/"), autoescape=True, ) # Load and render template = env.get_template("page.html") html = template.render(title="Hello", items=[1, 2, 3]) # Compile from string (not cached) template = env.from_string("{{ name }}") html = template.render(name="World") ``` -------------------------------- ### Render Kida Template with Python Source: https://github.com/lbliii/kida/blob/main/site/content/docs/get-started/quickstart.md Python script (`render.py`) to render a Kida template. It uses `kida.Environment` and `kida.FileSystemLoader` to load the template and then `template.render()` to process it with provided data. The output is printed to the console. ```python from kida import Environment, FileSystemLoader # Create environment with template directory env = Environment(loader=FileSystemLoader("templates/")) # Load and render the template template = env.get_template("hello.html") html = template.render( title="My Page", name="World", items=["Apple", "Banana", "Cherry"] ) print(html) ``` -------------------------------- ### Render Templates with Python Source: https://github.com/lbliii/kida/blob/main/site/content/docs/get-started/first-project.md Initializes the Kida environment, registers custom filters, and renders templates by passing context data. ```python from kida import Environment, FileSystemLoader env = Environment(loader=FileSystemLoader("templates/")) # Add a custom filter env.add_filter("currency", lambda v: f"${v:,.2f}") # Render the welcome email welcome = env.get_template("welcome.html") print(welcome.render( company="Acme Inc", date="2026-02-08", user={"name": "alice", "role": "admin"}, features=["Dashboard", "Reports", "API Access"], admin_url="https://admin.example.com", )) print("---") # Render the invoice email invoice_tmpl = env.get_template("invoice.html") print(invoice_tmpl.render( company="Acme Inc", date="2026-02-08", invoice={ "id": "INV-001", "items": [ {"name": "Widget", "qty": 3, "price": 9.99}, {"name": "Gadget", "qty": 1, "price": 24.99}, ], "total": 54.96, }, )) ``` -------------------------------- ### Load templates from Python packages Source: https://github.com/lbliii/kida/blob/main/site/content/docs/usage/loading-templates.md PackageLoader retrieves templates from installed Python packages, ensuring compatibility across different installation environments. ```python from kida import Environment, PackageLoader loader = PackageLoader("my_app", "templates") env = Environment(loader=loader) template = env.get_template("base.html") ``` -------------------------------- ### Install Flask and Kida Dependencies Source: https://github.com/lbliii/kida/blob/main/site/content/docs/tutorials/flask-integration.md Installs the necessary Python packages, Flask and Kida, using pip. This is a prerequisite for using Kida with Flask. ```bash pip install flask kida ``` -------------------------------- ### Load templates from the filesystem Source: https://github.com/lbliii/kida/blob/main/site/content/docs/usage/loading-templates.md Demonstrates how to use FileSystemLoader to load templates from single or multiple directories. It also shows how to list available templates within a directory. ```python from kida import Environment, FileSystemLoader # Single directory env = Environment(loader=FileSystemLoader("templates/")) # Multiple directories (searched in order) env = Environment(loader=FileSystemLoader([ "templates/", "shared/templates/", ])) # Load a template template = env.get_template("page.html") # List Templates loader = FileSystemLoader("templates/") templates = loader.list_templates() ``` -------------------------------- ### Load Templates from Filesystem with Kida Source: https://github.com/lbliii/kida/blob/main/README.md Demonstrates how to load templates from the filesystem using Kida's Environment and FileSystemLoader. It initializes the environment with a template directory and retrieves a template for rendering. ```python from kida import Environment, FileSystemLoader env = Environment(loader=FileSystemLoader("templates/")) template = env.get_template("page.html") print(template.render(title="Hello", content="World")) ``` -------------------------------- ### Initialize Kida Environment and Template Source: https://github.com/lbliii/kida/blob/main/site/content/docs/advanced/analysis.md Sets up a Kida environment using a DictLoader and retrieves a compiled template for analysis. ```python from kida import Environment, DictLoader env = Environment(loader=DictLoader({ "page.html": "{% extends \"base.html\" %}{% block title %}{{ page.title }}{% end %}{% block nav %}{% end %}{% block content %}{{ page.content }}{% end %}", "base.html": "{% block title %}{% end %}{% block nav %}{% end %}{% block content %}{% end %}" })) template = env.get_template("page.html") ``` -------------------------------- ### Kida Base Template Example Source: https://github.com/lbliii/kida/blob/main/site/content/docs/tutorials/flask-integration.md An example of a base Kida template (`base.html`) defining the basic HTML structure with blocks for title, navigation, and content, which other templates can extend. ```kida {% block title %}My App{% end %}
{% block content %}{% end %}
``` -------------------------------- ### Caching Heavy Operations Example Source: https://github.com/lbliii/kida/blob/main/site/content/docs/syntax/caching.md Shows an example of caching the result of a heavy operation, such as fetching and rendering a list of recent posts. This is a good candidate for caching to improve performance. ```kida {% cache "recent-posts" %} {% for post in get_recent_posts(limit=10) %} {{ post.title }} {% end %} {% end %} ``` -------------------------------- ### Run Kida Test Suite Source: https://github.com/lbliii/kida/blob/main/plan/rfc-kida-extraction.md Navigate to the kida directory, synchronize dependencies using `uv sync`, and run the kida test suite with `pytest -v` to verify its standalone functionality. ```bash cd kida && uv sync && pytest -v ``` -------------------------------- ### Compare Kida and Jinja2 Rendering Patterns Source: https://github.com/lbliii/kida/blob/main/plan/rfc-kida-site.md Demonstrates the difference between Kida's O(n) StringBuilder approach and Jinja2's generator-based rendering pattern. ```python # Kida: O(n) StringBuilder _out.append(...) return "".join(_out) # Jinja2: Generator yields (higher overhead) yield ... ``` -------------------------------- ### List Comprehension Syntax Example (Kida Template) Source: https://github.com/lbliii/kida/blob/main/plan/rfc-list-comprehensions.md Demonstrates the usage of list comprehensions within Kida's templating engine for data transformation. Examples show basic filtering and mapping operations. ```kida {% set opts = [{"value": s, "label": s | capitalize} for s in style_options] %} {% set visible = [x for x in items if x.visible] %} ``` -------------------------------- ### Run Design System Tests (Bash) Source: https://github.com/lbliii/kida/blob/main/examples/design_system/README.md This command executes the test suite for the design system example using pytest. It verifies the functionality and behavior of the components and the overall library. ```bash pytest examples/design_system/ -v ``` -------------------------------- ### Kida Macro: Descriptive Naming Examples Source: https://github.com/lbliii/kida/blob/main/site/content/docs/syntax/functions.md Illustrates the importance of using descriptive names for Kida macros to improve code readability and maintainability. It shows examples of good, clear names versus vague, unhelpful ones. ```kida {# Good: Clear purpose #} {% def format_price(amount, currency="USD") %} {% def user_badge(role) %} {% def pagination_nav(current, total) %} {# Avoid: Vague names #} {% def render(x) %} {% def do_thing(item) %} ``` -------------------------------- ### Configure Bytecode Cache Source: https://github.com/lbliii/kida/blob/main/site/content/docs/reference/configuration.md Shows how to manage persistent bytecode caching to improve cold-start performance. ```python from kida.bytecode_cache import BytecodeCache # Auto-detect (default) bytecode_cache=None # Explicit disable bytecode_cache=False # Custom location bytecode_cache=BytecodeCache("__pycache__/kida/") ``` -------------------------------- ### Render a template from a string using Kida Source: https://github.com/lbliii/kida/blob/main/README.md Demonstrates the basic usage of the Kida environment to compile a template string and render it with provided context variables. ```python from kida import Environment env = Environment() template = env.from_string("Hello, {{ name }}!") print(template.render(name="World")) # Output: Hello, World! ``` -------------------------------- ### Execute Bengal Build and Serve Commands Source: https://github.com/lbliii/kida/blob/main/plan/rfc-kida-site.md Common CLI commands for managing the documentation site lifecycle using the Bengal tool. ```bash # Development server cd kida && bengal serve site/ # Production build cd kida && bengal build site/ # Verify links cd kida && bengal validate site/ ``` -------------------------------- ### Test Template Compilation and Rendering Source: https://github.com/lbliii/kida/blob/main/plan/rfc-kida-extraction.md Verify that template compilation and rendering still function correctly by creating a kida Environment, loading a simple template, and rendering it with sample data. ```python python -c "from kida import Environment; e=Environment(); print(e.from_string('Hello {{ name }}').render(name='World'))" ``` -------------------------------- ### Initialize CachedBlocksDict Wrapper Source: https://github.com/lbliii/kida/blob/main/site/content/docs/advanced/block-caching.md Provides a minimal example of initializing the CachedBlocksDict wrapper for intercepting block lookups. ```python from kida.template.cached_blocks import CachedBlocksDict wrapper = CachedBlocksDict( original=None, cached={"nav": ""}, cached_names=frozenset({"nav"}), stats={"hits": 0, "misses": 0}, ) ``` -------------------------------- ### Configure GitHub Actions for Documentation CI/CD Source: https://github.com/lbliii/kida/blob/main/plan/rfc-kida-site.md YAML workflow configuration to automate building and deploying the documentation site to GitHub Pages. ```yaml name: Build Documentation on: push: branches: [main] paths: - 'site/**' - 'src/**' pull_request: paths: - 'site/**' jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.14' - name: Install dependencies run: | pip install bengal kida - name: Build site run: bengal build site/ - name: Deploy to GitHub Pages if: github.ref == 'refs/heads/main' uses: peaceiris/actions-gh-pages@v4 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./site/public ``` -------------------------------- ### Execute Migration Commands Source: https://github.com/lbliii/kida/blob/main/plan/rfc-kida-extraction.md Shell commands used to copy source files, utilities, and test suites from the existing repository to the new Kida project directory. ```bash cp -r bengal/rendering/kida/* kida/src/kida/ mkdir -p kida/src/kida/utils cp bengal/utils/lru_cache.py kida/src/kida/utils/lru_cache.py cd kida && pytest ``` -------------------------------- ### Inline Component Rendering Source: https://github.com/lbliii/kida/blob/main/site/content/docs/get-started/tstring-templates.md Examples of using t-strings to build reusable HTML components and lists within Python functions. ```python from kida import k def render_badge(label: str, color: str) -> str: return k(t'{label}') def render_user_list(users: list[dict]) -> str: items = "".join( k(t"
  • {user['name']} ({user['email']})
  • ") for user in users ) return k(t"") ```