Assets and plugins

oxblade-adminlte Alpha Rust

The crate works out which AdminLTE files a page needs and in what order. It never fetches or copies those files: you publish them under your public directory or point at a CDN.

Core assets

AssetConfig mirrors the PHP assets config. Deserialize it from your configuration; missing keys keep the shipped presets.

{
  "mode": "local",
  "cdn_fallback": true,
  "bootstrap_icons": true,
  "local": {
    "adminlte_css": "vendor/adminlte/dist/css/adminlte.min.css",
    "fonts_css": null
  }
}
  • mode is local (the default) or cdn.
  • local paths are relative to your public directory, without a leading slash. cdn entries are HTTPS URLs and may contain {version}.
  • A key you leave out uses the preset. A key set to null turns that location off.
  • With local mode and cdn_fallback on, a file that isn't published falls back to the CDN entry.

Tell the crate what you have published with an AssetHost:

use oxblade_adminlte::AssetHost;
use std::{collections::HashSet, path::Path};

struct PublicFiles(HashSet<String>);

impl PublicFiles {
    fn scan(public: &Path, paths: &[&str]) -> Self {
        Self(paths.iter().filter(|p| public.join(p).is_file()).map(|p| p.to_string()).collect())
    }
}

impl AssetHost for PublicFiles {
    fn published(&self, path: &str) -> bool {
        self.0.contains(path)
    }
    fn url(&self, path: &str) -> String {
        format!("/{path}")
    }
}

Check the files once at startup rather than on every request.

Then build the page's list:

let core = config.page(layout.rtl(), "4.10.4", &host)?;
// pass as "core_assets" to the view

The version argument is the AdminLTE release you installed. {version} becomes its major and minor (4.10) unless adminlte_version is set. Styles come out in the PHP order: Source Sans 3, OverlayScrollbars, Bootstrap Icons, AdminLTE, then the optional colour sheet. Set fonts: false to skip the font stylesheet. Core scripts load in order before plugins and page scripts, without defer. Plugin scripts keep their configured defer flag. In RTL the AdminLTE and colour sheets switch to their RTL builds.

To apply PHP's palette attributes, resolve the layout with Layout::view_with_assets(locale, &config) using the same asset configuration. With extended colors enabled, palette.primary names a color from the selected palette. The legacy palette enables its AA contrast correction by default. Set palette.contrast to false to opt out or "aa" to opt in. Layout's print setting accepts a list or space-separated string and keeps only the upstream plain and app tokens.

Plugins

Plugins::presets() loads the plugin list from Laravel-AdminLTE v4.1.0: Datatables, DatatablesButtons, Select2, TomSelect, Tabulator, Flatpickr, Quill, NoUiSlider, Chartjs, Sweetalert2 and Pace. All are off by default. You can also deserialize your own list in the PHP shape (active, and files with type, asset, location, rtl and defer).

Each page decides which plugins to load:

use oxblade_adminlte::{PluginActivation, Plugins};
use std::collections::BTreeMap;

let plugins = Plugins::presets()?;
let page = BTreeMap::from([("Chartjs".to_string(), PluginActivation::Enable)]);
let extra = plugins.resolve(&page, layout.rtl(), config.version("4.10.4"), &host);
// pass as "plugin_assets" to the view

Inherit (or no entry) keeps the plugin's active setting; Enable and Disable override it for this page. The key is the plugin's name if it has one, else its key in the list. Files are emitted in the order they are declared.

What gets rejected

Asset URLs are configuration you trust, but they are still checked before they reach the page:

  • Local paths may not be absolute, contain .., \, :, ? or #.
  • Final asset URLs must be HTTPS or rooted paths. Protocol-relative preset URLs such as //cdn.datatables.net/... become https://....
  • An entry that fails these checks is left out rather than printed.

Asset origins and CSP

The built-in resolver accepts HTTPS URLs and rooted local paths for styles and scripts. It converts protocol-relative presets to HTTPS. The default local mode can load a CDN asset when a local file is missing. Core presets use cdn.jsdelivr.net; optional plugins also use cdnjs.cloudflare.com and cdn.datatables.net. Add only the hosts your chosen assets use to style-src and script-src, and allow font-src for the hosts serving your web and icon fonts. The default Source Sans 3 stylesheet loads its font files from cdn.jsdelivr.net unless you serve them locally or set fonts: false.

For a same-origin policy, publish the local files, turn off cdn_fallback, and keep plugin URLs local. Set a CDN entry to null too when the matching local location is deliberately omitted. The generated tags do not add Subresource Integrity hashes. Use app-authored asset tags if you need SRI.

Licences

The crate ships no AdminLTE, Bootstrap, plugin or font files. When you publish them, keep each project's licence notice with the files.