I have a set of URLs, and some of the URLs have indirect references (as a vector). Any URL that does not have an indirect reference just has nil
. I'm starting out with the following test map:
{"URL 1" nil,
"URL 2" ["indirect 1" "indirect 2"]}
I'm using hiccup to build an HTML report, so I want this output:
[:div "Imports: "
[:ul
[:li "URL 1"]
[:li "URL 2"]
[:ul
[:li "indirect 1"]
[:li "indirect 2"]
[:li "indirect 3"]]]]
I'm running into some problems returning nil when the URL does not have an indirect reference. My current code looks like this:
(defn list-imports
[imports]
(if-not (nil? imports)
[:div "Imports: "
[:ul
(for [direct (keys imports)]
[[:li direct]
(if-let [indirects (get imports direct)]
[:ul
(for [indirect indirects]
[:li indirect])]
[:span])])]]
[:div "Imports: none" [:br] [:br]]))
The problem is, it's returning this...
[:div
"Imports: "
[:ul
([[:li "URL 1"] [:span]]
[[:li "URL 2"] [:ul ([:li "indirect 1"] [:li "indirect 2"])]])]]
I had to add in a [:span]
tag as the case for when the indirect imports are nil
, which I don't really want there... but otherwise, it puts in nil
there.
The other problem is that it ends up enclosed in ()
and an extra vector, because I'm doing multiple things within the for statement. When I try to convert it with hiccup, I get [:li "URL 1"] is not a valid element name.