rwf

repository·main·Indexed 21 days ago

https://github.com/levkk/rwf

A comprehensive Rust web framework following the classic MVC pattern. Version 0.2.1 provides a full-stack experience including an ORM, authentication (Basic, Token, and Session), background jobs with Postgres durability, and a dynamic templating engine inspired by ERB.

Tokens
69.7K
Snippets
305
Records
365
Agent score
76%

What's inside rwf

  1. Overview of Rwf admin capabilities

    main

    Rwf admin is a web application designed to provide real-time visibility and management capabilities for Rwf-based applications. It provides:

    • A real-time overview of web activity.
    • Insights into the background jobs queue.
    • Tools to manipulate database models directly.
  2. Overview of Rwf features

    main

    Rwf is a comprehensive MVC (Model-View-Controller) framework for Rust that includes:

    • Core Web: HTTP server, WebSockets, static file hosting, and middleware support.
    • Data & Persistence: User-friendly ORM for PostgreSQL, database migrations, and a built-in REST framework with JSON serialization.
    • Application Logic: Authentication with built-in user sessions, background jobs, and scheduled jobs.
    • Frontend & Templating: Dynamic templates and tight integration with Hotwired Turbo for backend-driven SPAs.
    • DevOps & Tooling: Environment-specific configuration, logging, metrics, and a CLI.
    • Migration Paths: WSGI server for Django/Flask migration and a Rack server for Rails migration.
  3. Overview of rwf-ruby

    main

    rwf-ruby provides Rust bindings designed to run Ruby applications built on the Rack interface. Unlike generic Ruby-to-Rust bindings, this project specifically enables running arbitrary Ruby code within a Rust environment by wrapping ruby_exec_node directly.

    Note: This project is currently experimental and requires additional testing before being used in production environments. The bindings are implemented in C.

  4. What is middleware in Rwf

    main

    Middleware is a component that runs before a request reaches a controller. It can be used to:

    • Modify the request: Add custom headers or tags to the incoming request.
    • Validate requests: Check for required conditions (e.g., presence of specific headers).
    • Block requests: Stop a request from reaching the controller entirely by returning a response early.

    By default, controllers have no middleware, meaning requests are processed in their original state.

  5. What is a Controller in Rwf?

    main
    In the MVC (Model-View-Controller) pattern used by Rwf, the Controller is the component that handles user interactions and HTTP requests. It processes user inputs (like form data) and performs actions on their behalf by returning an HTTP Response.
  6. Work with Lists and Hashes in templates

    main

    Rwf supports complex data types that can be iterated or indexed.

    Lists

    Lists are 0-indexed arrays. You can iterate through them using for loops and access specific elements using dot (.) notation.

    <% for item in [1, 2, "three"] %>
    <%= item %>
    <% end %>
    
    <%# Accessing the second element %>
    <%= list.1 %>

    Hashes

    Hashes (key/value pairs) allow you to access values using dot notation with the key name.

    <p><%= user.name %></p>
    <p><%= user.email %></p>
    <% for item in [1, 2, "three"] %>
    <%= item %>
    <% end %>
  7. How template functions work

    main

    Rwf templates provide functions to manipulate constants and variables. Most functions are type-specific and are called using dot (.) notation on a value. For example, you can call string methods directly on a string object.

    Available type-specific function groups include:

    • String functions
    • Integer functions
    • Float functions
    • Hash functions
    • List functions
    <%= "lowercase".upper %>
  8. Core concepts in the Rwf + Turbo integration

    main

    The Rwf + Turbo example demonstrates how to build a Single Page Application (SPA) by combining several technologies:

    • Rwf + Turbo Integration: Tight coupling between the Rust Web Framework and Turbo for seamless updates.
    • WebSockets: Real-time communication capabilities.
    • Stimulus Controllers: Client-side JavaScript logic to enhance HTML.
    • Rwf Controllers: Server-side request handling.
    • Migrations: Database schema evolution.
    • ORM Querying: Interacting with the PostgreSQL database using the Rwf ORM.
  9. Understand truthy and falsy values in templates

    main

    When using variables in conditional statements (like if), Rwf evaluates them for truthiness. The following values are considered falsy:

    Data typeFalsy Value
    Integer0
    Float0.0
    Booleanfalse
    String"" (empty)
    List[] (empty)
    Hash{} (empty)

    All other values evaluate to true.

  10. Evaluate complex expressions in if statements

    main

    Rwf template language supports evaluating complex expressions for truthiness within if statements. The language is nearly Turing-complete, allowing for string manipulation and arithmetic. However, it is recommended to keep template logic simple and delegate complex business logic to Rust views where possible.

    <% if var.lower + "_" + bar.upper == "lo_HI" %>
      <!-- do something -->
    <% end %>