Public archive for the Return to Ritherdon project.
https://www.nicolaellisandritherdon.com
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.6 KiB
48 lines
1.6 KiB
(defpackage #:utils |
|
(:use #:cl |
|
#:log4cl) |
|
(:export #:format-date |
|
#:i18n-load |
|
#:_ |
|
#:parse-iso-date |
|
#:request-params |
|
#:string-is-nil-or-empty-p |
|
#:separate-files-in-web-request) |
|
(:documentation "Utilities that do not depend on models.")) |
|
|
|
(in-package #:utils) |
|
|
|
(defun format-date (date) |
|
"Format the given date with the default date format (yyyy-mm-dd). Return a string." |
|
(local-time:format-timestring nil date :format +date-y-m-d+)) |
|
|
|
(defun asciify (string) |
|
(str:downcase (slug:asciify string))) |
|
|
|
(defun request-params (request) |
|
(loop :for (key . value) :in request |
|
:collect (let ((*package* (find-package :keyword))) |
|
(read-from-string key)) |
|
:collect value)) |
|
|
|
(defun string-is-nil-or-empty-p (string-to-test) |
|
"Tests to see if `STRING-TO-TEST' is empty of just whitespace. |
|
This is essentially the 'IsNullOrWhiteSpace' function I use in C#. It |
|
expands the 'empty string' check to include a check to see if there is |
|
string with just a '(white) space' in it." |
|
(if (or (string= string-to-test " ") |
|
(zerop (length string-to-test)) |
|
(null string-to-test)) |
|
t |
|
nil)) |
|
|
|
(defun separate-files-in-web-request (request &optional request-value) |
|
"Creates a new list of 'upload' files from a web `REQUEST'. |
|
You will mostly use this for processing a multi-file upload (HTML) |
|
form. The standard value for the 'name' attribute in (file) input tag |
|
in the HTML form is `CONTENT-FILES' but you can use a different |
|
name. Just specify it in this function's `REQUEST-VALUE' argument." |
|
(loop :for item :in request |
|
if (or (string= "CONTENT-FILES" (car item)) |
|
(string= request-value (car item))) |
|
collect item))
|
|
|