Getting started

oxblade-adminlte Alpha Rust

This page installs oxblade-adminlte, registers its views and renders a dashboard page.

Requirements

  • Rust 1.99 or later
  • laravel-rust 0.2.0 or later, with oxblade through oxblade-laravel 0.2.0 or later
  • The AdminLTE 4 files, served by your application or a CDN. Fixtures are generated against AdminLTE v4.10.4.

Install

[dependencies]
oxblade-adminlte = "0.1.0"
oxblade-laravel = "0.2.0"
laravel = { package = "laravel-rust", version = "0.2.0" }
serde_json = "1"

The laravel feature is on by default. Without it you get the layout, menu, asset and auth types, but no service provider or views.

Register the views

Add the Blade provider and the AdminLTE provider to your application:

use oxblade_adminlte::AdminLteServiceProvider;
use oxblade_laravel::{BladeEngine, BladeServiceProvider};

// inside your application's provider setup
providers.add(BladeServiceProvider::new(|_| BladeEngine::new()));
providers.add(AdminLteServiceProvider);

The views are embedded in the crate and mounted under the adminlte namespace: adminlte::master, adminlte::page and adminlte::auth.form. A view of the same name in your application takes precedence.

Render a page

Extend adminlte::page and fill its sections:

@extends('adminlte::page')

@section('title')
Dashboard
@endsection

@section('content_header')
  <h1>Dashboard</h1>
@endsection

@section('content')
  <p>Welcome back.</p>
@endsection

Then pass the resolved layout and anything else the shell needs:

use laravel::view::view;
use oxblade_adminlte::{Layout, SafeUrl};
use serde_json::json;

let stylesheet: SafeUrl = "/vendor/adminlte/dist/css/adminlte.min.css".parse()?;
let script: SafeUrl = "/vendor/adminlte/dist/js/adminlte.min.js".parse()?;
let html = view(
    "dashboard",
    json!({
        "layout": Layout::default().view("en"),
        "brand": "Dashboard",
        "stylesheet_url": stylesheet,
        "script_url": script,
    }),
)
.render()
.map_err(|error| std::io::Error::other(format!("{error:?}")))?;

Layout deserializes from your configuration; missing keys keep the PHP defaults. view(locale) works out the body classes, container and RTL direction for one request.

The page reads these keys, all optional except layout:

KeyWhat it does
layoutLayoutView from Layout::view
brand, logo_url, logo_altBrand text and an optional logo, alongside the brand text
menuMenu::view() from a compiled menu, see Menus
core_assets, plugin_assetsPageAssets, see Assets and plugins
stylesheet_url, script_urlA single stylesheet and script, when you don't use core_assets
theme_init_urlWhere you serve THEME_INIT_JS
csrf_tokenAdds a csrf-token meta tag; omitted when empty
skip_content, skip_navigation, navbar_label, sidebar_label, toggle_sidebarText for skip links and screen-reader labels, for translation

All text is escaped. The sections content_header, content_top, content, content_bottom, footer, navbar_left, navbar_right, navbar_user and sidebar take your own markup, as do the css and js sections and stacks.

Color mode

Set color_mode to light, dark or auto (the default). To avoid a flash of the wrong theme, serve oxblade_adminlte::THEME_INIT_JS as a JavaScript file and pass its URL as theme_init_url. The script reads the configured mode or the browser's preference. It stores nothing and calls no server endpoint, so it works with a strict Content Security Policy that allows your own scripts.

A complete runnable page is in examples/quickstart.rs.