2013-06-17 4 views
2

범위 선택기를 만들려고 노력 중이며 바닥에서 벗어날 수 없습니다.확대 범위 선택기

내가 좋아하는 일을하려고 해요 :

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

그리고 그것은 단지 공급 된 HTML을 반환합니다. 나는 그것이 몸 "안녕하세요"와 div를 반환 기대합니다.

어떻게하면됩니까?

편집

바로 이것이 내가 deftemplate 진짜 html 파일로 무슨 짓을했는지, 더 간결하기 :

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")) 

나는 this tutorial과 함께 팔로우하고 있지만 범위와 일치 시키려면 스 니펫을 사용합니다. 이게 필요한가?

sniptest으로 테스트 할 수 있습니까?

+0

내가 오해 될 수있다 :

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 사용할 수있는 조각의 위치에 따라 더 재미있는 일을 할 수 있습니다 , (콘텐츠 "안녕하세요") 대신 (콘텐츠 "안녕하세요") 의미 했습니까? –

+0

아니요, 콘텐츠가 일치하는 콘텐츠를 대체 할 것으로 생각했습니다. 잘못인가? – Khanzor

답변

3

이러한 것들을 "조각 선택자"라고 부릅니다. 이러한 것들은 큰 의미로 사용되며, 에 포장하면 동일한 효과를 얻을 수 있지만 content을 직접적으로 지원하지 않습니다. 하지만,

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>" 
+0

고마워. 그게 날 위해 클릭하지 않았다 :. 하지만 지금은 완벽 해. – Khanzor

관련 문제