views:

249

answers:

3

This is my code. I have a problem with spaces. I can not get the proper generation

- if @lastday.nil? && @lastday != item.created_at.strftime("%d %b %Y")
  .daily-entry
    %h1.date
      =h item.created_at.strftime("%d")
      %span
        =h item.created_at.strftime("%b, %Y")
-else
  .entry
      %h1
        = link_to item.title, "/items/#{item.id}"

Generates this is

<div class='daily-entry'> 
 <h1 class='date'> 
   20
   <span> 
    Sep, 2009
    </span> 
 </h1> 
</div> 
<div class='entry'> 
 <h1> 
  <a href="/items/15">xcvxcvx</a> 
 </h1>
</div>

But I want a HTML

<div class='daily-entry'> 
 <h1 class='date'> 
   20
   <span> 
    Sep, 2009
    </span> 
 </h1> 
 <div class='entry'> 
   <h1> 
     <a href="/items/15">xcvxcvx</a> 
   </h1>
 </div>
</div>

.daily-entry

should be included in the condition

if condition true

<div class='daily-entry'> 
 <h1 class='date'> 
   20
   <span> 
    Sep, 2009
    </span> 
 </h1>
 <div class='entry'> 
  <h1> 
   <a href="/items/15">xcvxcvx</a> 
  </h1>
 </div>
</div>

if condition false

<div class='entry'> 
 <h1> 
  <a href="/items/15">xcvxcvx</a> 
 </h1>
</div>
+1  A: 

Just move the if within the .daily-entry:

.daily-entry
  - if @lastday.nil? && @lastday != item.created_at.strftime("%d %b %Y")
    %h1.date
      =h item.created_at.strftime("%d")
      %span
        =h item.created_at.strftime("%b, %Y")
  -else
    .entry
      %h1
        = link_to item.title, "/items/#{item.id}"
nex3
No :(I edit my quest
Darwin
Sorry, I edit again
Darwin
+1  A: 

Don't you want

if [email protected]?

instead of

if @lastday.nil?
DigitalRoss
+1  A: 

Looks like you'll have to duplicate the entry as a first cut:

-if @lastday.nil? && @lastday != item.created_at.strftime("%d %b %Y")
  .daily-entry
    %h1.date
      =item.created_at.strftime("%d")
      %span= item.created_at.strftime("%b, %Y")
    .entry
      %h1= link_to item.title, "/items/#{item.id}"
-else
  .entry
    %h1= link_to item.title, "/items/#{item.id}"

There ought to be a way to get aound that duplication, but I can't think what it should be - a helper function that takes a block, probably.

Mike Woodhouse