-
-
Save mgaare/0ab86563ecacc76a7ab9 to your computer and use it in GitHub Desktop.
Problem with enlive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; input: | |
({:tag :tr, | |
:attrs nil, | |
:content | |
("\n " | |
{:tag :td, | |
:attrs nil, | |
:content | |
("\n " | |
{:tag :a, :attrs {:href "/view/:id"}, :content ("Name")} | |
"\n ")} | |
"\n " | |
{:tag :td, | |
:attrs nil, | |
:content | |
("\n " | |
{:tag :a, | |
:attrs {:href "mailto:john@aol.com"}, | |
:content ("john@aol.com")} | |
"\n ")} | |
"\n " | |
{:tag :td, | |
:attrs nil, | |
:content | |
("\n " | |
{:tag :a, | |
:attrs {:href "+12125551234"}, | |
:content ("212-555-1234")} | |
"\n ")} | |
"\n " | |
{:tag :td, | |
:attrs nil, | |
:content | |
("")} | |
"\n " | |
{:tag :td, :attrs nil, :content ("42")} | |
"\n ")}) | |
;; output: | |
({:tag :tr, | |
:attrs nil, | |
:content | |
("\n " | |
[:tag :td] | |
[:attrs nil] | |
[:content | |
("\n " | |
{:tag :a, :attrs {:href "/view/:id"}, :content ("Name")} | |
"\n ")] | |
"\n " | |
{:tag :td, | |
:attrs nil, | |
:content | |
("\n " | |
{:tag :a, | |
:attrs {:href "mailto:john@aol.com"}, | |
:content ("john@aol.com")} | |
"\n ")} | |
"\n " | |
[:tag :td] | |
[:attrs nil] | |
[:content | |
("\n " | |
{:tag :a, | |
:attrs {:href "+12125551234"}, | |
:content ("212-555-1234")} | |
"\n ")] | |
"\n " | |
{:tag :td, | |
:attrs nil, | |
:content | |
("")} | |
"\n " | |
[:tag :td] | |
[:attrs nil] | |
[:content ("42")] | |
"\n ")}) | |
;; relevant code | |
(defn set-link-and-text | |
[target text] | |
#(transform % [:a] | |
(do-> | |
(content text) | |
(set-attr :href target)))) | |
(defn test-summary [nodes rec] | |
(at nodes | |
[[:td (html/nth-of-type 1)]] | |
(set-link-and-text | |
(str "/view/" (:id rec)) | |
(str (:first-name rec) " " (:last-name rec))) | |
[[:td (html/nth-of-type 2)]] | |
(set-link-and-text | |
(str "mailto:" (:email rec)) | |
(str (:email rec))) | |
[[:td (html/nth-of-type 3)]] | |
(let [phone (:phone rec)] | |
(set-link-and-text | |
(get-phone-dial phone) | |
(get-phone-display phone))) | |
[[:td (html/nth-of-type 4)]] | |
(content "Last activity") | |
[[:td (html/nth-of-type 5)]] | |
(content (str (:score rec))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment