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.
57 lines
2.3 KiB
57 lines
2.3 KiB
(in-package #:cl-user) |
|
(defpackage #:validation |
|
(:use #:cl |
|
#:app-constants) |
|
(:export #:has-static-assets-extention? |
|
#:is-valid-favicon-type? |
|
#:favicon-need-resizing? |
|
#:string-is-nil-or-empty?) |
|
(:documentation "Package for validating 'stuff'.")) |
|
(in-package #:validation) |
|
|
|
(defun file-has-valid-static-assets-extention? (filename) |
|
(cond ((or (string= "css" (pathname-type filename)) |
|
(string= "js" (pathname-type filename)) |
|
(string= "png" (pathname-type filename)) |
|
(string= "ico" (pathname-type filename)) |
|
(string= "gif" (pathname-type filename)) |
|
(string= "jpg" (pathname-type filename)) |
|
(string= "svg" (pathname-type filename)) |
|
(string= "txt" (pathname-type filename))) |
|
filename) |
|
(t nil))) |
|
|
|
(defun file-is-valid-favicon-type? (filename) |
|
"Returns path of file if `FILE' is a valid favicon. |
|
Valid file types are 'ico', 'gif' and 'png'." |
|
(cond ((or (string= "png" (pathname-type filename)) |
|
(string= "ico" (pathname-type filename)) |
|
(string= "gif" (pathname-type filename))) |
|
filename) |
|
(t nil))) |
|
|
|
(defun string-is-nil-or-empty? (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 favicon-need-resizing? (dimensions) |
|
"Checks to see if the `WIDTH' or `HEIGHT' are greater than 192x192 pixels. |
|
`DIMENSIONS' is a cons list, with the `WIDTH' being first element and |
|
`HEIGHT' being the second. If either of them are, then you look into |
|
scaling down the image, using code in the `UTILS' package probably." |
|
(cond ((or (< 192 (car dimensions)) (< 192 (cdr dimensions))) |
|
t) ; True as in the dimensions are valid |
|
(t ;; Bit confusing with the use of `T' here but its standard |
|
;; practice to end `COND' with a catch-all `T'. In this |
|
;; case, `T' here means the dimensions are invalid, as in |
|
;; 'yes' the favicon needs resizing. This is confusing |
|
;; Boolean logic but when you call this function, the |
|
;; return types make sense from that point-of-view. |
|
nil)))
|
|
|