hubman
hubman

Reputation: 149

converter code ejs to jade

I have code in ejs of http://www.digitalaholic.com/nodejs-pagination/, and want converter to .jade, i attempt but is not sufficient, not working. i work in nodejs and expressjs, i need code in jade.

<div class="container">
        <h1>Students</h1>
        <ul class="list-group">
            <% students.forEach( function( student ) { %>
                <li class="list-group-item"><%= student.name %></li>
            <% }) %>
        </ul>
        <% if (pageCount > 1) { %>
        <ul class="pagination">
            <% if (currentPage > 1) { %>
                <li><a href="/?page=1">&laquo;</a></li>
            <% } %>
            <% var i = 1;
            if (currentPage > 5) {
                i = +currentPage - 4;
            } %>
            <% if (i !== 1) { %>
                <li class="disabled"><a href="#">...</a></li>
            <% } %>
            <% for (i; i<=pageCount; i++) { %>
                <% if (currentPage == i) { %>
                    <li class="active"><span><%= i %> <span class="sr-only">(current)</span></span></li>
                <% } else { %>
                    <li><a href="/?page=<%= i %>"><%= i %></a></li>
                <% } %>
                <% if (i == (+currentPage + 4)) { %>
                    <li class="disabled"><a href="#">...</a></li>
                <% break; } %>
            <% } %>
            <% if (currentPage != pageCount) { %>
                <li><a href="/?page=<%= pageCount %>">&raquo;</a></li>
            <% } %>
        </ul>
    <% } %>
    </div>

my code attempt is for converter to jade is the code follow:

     div(class="container")
        h1 Students

        ul(class="list-group")
            each item in students
                li(class="list-group-item") item.name

        if (pageCount > 1) 
            ul(class="pagination")
                if currentPage > 1 
                    li
                      a(href="/?page=1")
                var i = 1;
                if currentPage > 5 
                    i = +currentPage - 4;
                if i !== 1  
                    li(class="disabled")
                        a(href="#") ...
                for (var i; i<=pageCount; i++)  
                    if currentPage == i  
                        li(class="active")
                            span i  
                                span(class="sr-only") (current)
                    else 
                        li
                          a(href="/?page=<%= i %>")
                            = i 
                    if (i == (+currentPage + 4))
                        li(class="disabled")
                            a(href="#") ...
                        break;
                if (currentPage != pageCount)
                    li
                      a(href="/?page=<%= pageCount %>")

Upvotes: 1

Views: 747

Answers (1)

KyleK
KyleK

Reputation: 5131

Please precise what is "not working", what HTML do you get, what error, what do you expect.

But right now, I can say: a(href="/?page=<%= pageCount %>") this is EJS and this should be also converted, then for and break are not working as it I think, but you can pass raw JS:

 div(class="container")
    h1 Students

    ul(class="list-group")
        each item in students
            li(class="list-group-item") item.name

    if (pageCount > 1) 
        ul(class="pagination")
            if currentPage > 1 
                li
                  a(href="/?page=1")
            var i = 1;
            if currentPage > 5 
                i = +currentPage - 4;
            if i !== 1  
                li(class="disabled")
                    a(href="#") ...
            - for (var i; i<=pageCount; i++)  
                if currentPage == i  
                    li(class="active")
                        span i  
                            span(class="sr-only") (current)
                else 
                    li
                      a(href="/?page=" + i)
                        = i 
                if (i == (+currentPage + 4))
                    li(class="disabled")
                        a(href="#") ...
                    - break;
            if (currentPage != pageCount)
                li
                  a(href="/?page=" + pageCount)

Upvotes: 1

Related Questions