Standby Range Selector

I am trying to create a range selector, and it seems I cannot get off the ground.

I try things like:

(sniptest "<div><p class='start'>Hi</p><p class='end'>There</p></div>"
      [{[:.start] [:.end]}] (content "Hello"))

And that just returns the supplied html. I expect it to return a div with the body Hello.

How to do it?

EDIT

To be more concise, this is what I did with the deftemplate and the real html file:

HTML

<html>
<head>
  <title></title>
</head>
<body>
  <h1>Not hello</h1>

<div class="start">
 foo
 </div>

 <div class="end">
    bar
 </div>
</body>
</html>

CLJ

(ns compojure-blog-test.views.landing-page
  (:require [net.cgrand.enlive-html :as html]))

(html/deftemplate landing-page "compojure_blog_test/views/landing_page.html"
  [blogs]
  {[:.start] [:.end]} (html/content "Blah blah"))

I follow this tutorial , but it uses a fragment to match ranges. It's not obligatory?

Is it possible to test them only with sniptest?

+2
source share
1 answer

" " , , , content , clone-for, .

user> (require '[net.cgrand.enlive-html :as html])
nil
user> (html/sniptest "<div>
                        <p class='before'>before</p>
                        <p class='start'>Hi</p>
                        <p class='end'>There</p>
                        <p class='after'>after</p>
                        <p class='end'>last</p>
                      </div>"
                     {[:.start] [:.end]} (html/clone-for [m ["Hello"]]
                                            [:p] (html/content m)))
"<div>
   <p class=\"before\">before</p>
   <p class=\"start\">Hello</p>
   <p class=\"end\">Hello</p>
   <p class=\"after\">after</p>
   <p class=\"end\">last</p>
 </div>"

,

user> (html/sniptest "<div>
                        <p class='before'>before</p>
                        <p class='start'>Hi</p>
                        <p class='end'>There</p>
                        <p class='after'>after</p>
                        <p class='end'>last</p>
                     </div>"
    {[:.start] [:.end]} (html/clone-for [m [["Hello" "Sir"]]]
                           [:p.start] (html/content (first m))
                           [:p.end]   (html/content (last m))))
"<div>
  <p class=\"before\">before</p>
  <p class=\"start\">Hello</p>
  <p class=\"end\">Sir</p>
  <p class=\"after\">after</p>
  <p class=\"end\">last</p>
 </div>"

do-> clone-for:

user> (html/sniptest "<div>
                        <p class='before'>before</p>
                        <p class='start'>Hi</p>
                        <p class='end'>There</p>
                        <p class='after'>after</p>
                        <p class='end'>last</p>
                      </div>"
    {[:.start] [:.end]} (html/do-> (html/content "Hello")))
"<div>
   <p class=\"before\">before</p>
   <p class=\"start\">Hello</p>
   <p class=\"end\">Hello</p>
   <p class=\"after\">after</p>
   <p class=\"end\">last</p>
</div>"
+3

All Articles