rumtk_web/utils/packaging.rs
1/*
2 * rumtk attempts to implement HL7 and medical protocols for interoperability in medicine.
3 * This toolkit aims to be reliable, simple, performant, and standards compliant.
4 * Copyright (C) 2025 Luis M. Santos, M.D.
5 * Copyright (C) 2025 Nick Stephenson
6 * Copyright (C) 2025 Ethan Dixon
7 * Copyright (C) 2025 MedicalMasses L.L.C.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24use minifier::{css, html, js, json};
25use rumtk_core::core::RUMResult;
26use rumtk_core::strings::{RUMString, RUMStringConversions, ToCompactString};
27
28pub enum Asset<'a> {
29 CSS(&'a str),
30 HTML(&'a str),
31 JSON(&'a str),
32 JS(&'a str),
33}
34
35pub fn minify_asset(asset: Asset) -> RUMResult<RUMString> {
36 match asset {
37 Asset::CSS(css) => match css::minify(css) {
38 Ok(css) => Ok(css.to_compact_string()),
39 Err(err) => Err(err.to_rumstring()),
40 },
41 Asset::HTML(html) => Ok(html::minify(html).to_compact_string()),
42 Asset::JSON(json) => Ok(json::minify(json).to_compact_string()),
43 Asset::JS(js) => Ok(js::minify(js).to_compact_string()),
44 }
45}