2015-02-26 20:39 GMT+01:00 Cecil Westerhof <cldwester...@gmail.com>:

>
> At the moment I have the following code:
>     (str "<html>"
>          "<table border='1' cellpadding='10'"
>          "style='font-family:Arial; font-size:16px; margin:
> 10px;width:100%'>"
>          "<tr>"
>          "<th bgcolor='black' color='white'>Quote</th>"
>          "<th bgcolor='black' color='white'>Author</th>"
>          "</tr>")
>
> But I want to make it more generic: the th lines should be data-driven.
> There is a headers variable and when this contains:
>     '(:quote "Quote" :author "Author")
>
> Then the above should be generated. So for every odd position (counting
> from 0) a th string should be inserted. How would I do this?
>

​I found a solution. Do not know how good it is Clojure wise, but it
certainly does what I want:
    (str "<html>"
         "<table border='1' cellpadding='10'"
         "style='font-family:Arial; font-size:16px; margin:
10px;width:100%'>"
         "<tr>"
         (loop [headings     (rest headers)
               html-headings ""]
               (let [header (first headings)]
                    (if (empty? headings)
                        html-headings
                      (recur (rest (rest headings))
                             (str html-headings
                                  (format "<th bgcolor='black'
color='white'>%s</th>" header))))))
         "</tr>")

-- 
Cecil Westerhof

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
  • [no subject] Cecil Westerhof
    • Re: Timothy Baldridge
      • Re: Cecil Westerhof
    • Re: Colin Yates
      • Re: Cecil Westerhof
        • Re: Colin Yates
    • Re: Cecil Westerhof

Reply via email to