enlive odd selector question, changing non element content and preserving other inner elements

130 views
Skip to first unread message

Jarrod Swart

unread,
Feb 14, 2014, 9:19:52 PM2/14/14
to enliv...@googlegroups.com
Had a question concerning replace text that is in the content of an element, but surrounded by other elements.  ie:

<one>
    <two>a</two>
    three
    <four>b</four>
</one>

In this example how would I select and change the text "three"?  I am attempting to clone the li:nth-child(2), I have a second snippet that will grab the insides of such an li.

How do I change the word Shirts & Dashboard in the code below, as in what series of enlive selectors can do it while keeping the other elements intact?

<ul id="side-menu" class="nav">
    <li>
        <a href="index.html">
            <i class="fa fa-dashboard fa-fw"></i>
            Dashboard
        </a>
    </li>
    <li>
        <a href="#">
            <i class="fa fa-bar-chart-o fa-fw"></i>
            Shirts
            <span class="fa arrow"></span>
        </a>
        <ul class="nav nav-second-level collapse">
            <li>
                <a href="/">Rush</a>
            </li>
        </ul>
    </li>
</ul>

Here is the top level snippet to grab the side bar and dump it into the root template.

(html/defsnippet side-nav-links "public/index.html" [:#side-menu] []
                   [[:a (html/attr= :href "index.html")]] (html/do->
                                                    (html/content "Dashboard") ;; this overwrites the <i> tag so knowing how to change this text is ideal too.
                                                    (html/set-attr :href "/"))
                   [[:li (html/nth-child 2)]] (html/clone-for [x [1 2 3]]
                                                              (html/content (nav-sub-group))))

Here is where I grab the inside of the li to create new lis based on this structure.

(html/defsnippet nav-sub-group "public/index.html" [:#side-menu [:li (html/nth-child 2)]] []
                   [<<<Change text of "Shirts" here>>>] <<< ? >>>)

All of the HTML/CSS is open for change.  I simply need to know the simplest solution, and advice on anything else I am doing wrong is great too.

Best,
Jarrod

Christophe Grand

unread,
Feb 17, 2014, 6:44:42 AM2/17/14
to enlive-clj

On Sat, Feb 15, 2014 at 3:19 AM, Jarrod Swart <jcs...@gmail.com> wrote:
(html/defsnippet nav-sub-group "public/index.html" [:#side-menu [:li (html/nth-child 2)]] []
                   [<<<Change text of "Shirts" here>>>] <<< ? >>>)

(html/defsnippet nav-sub-group "public/index.html" [:#side-menu [:li (html/nth-child 2)]] []
                   [[html/text-node (html/left :i.fa.fa-bar-chart-o.fa-fw)]] (constantly "Chemise"))

This one shoud work: selects the text node which has a i.fa.fa-bar-chart-o.fa-fw to its left

--
On Clojure http://clj-me.cgrand.net/
Clojure Programming http://clojurebook.com
Training, Consulting & Contracting http://lambdanext.eu/

Jarrod Swart

unread,
Mar 11, 2014, 10:51:56 PM3/11/14
to enliv...@googlegroups.com, chris...@cgrand.net
Excellent thank you!
Reply all
Reply to author
Forward
0 new messages