Bug in #cycle

96 views
Skip to first unread message

Jesse

unread,
Oct 28, 2009, 2:03:17 PM10/28/09
to Haml
Failing example (matching first arguments in #cycle) ---

%tbody
%tr
%td
- 1.upto(3) do |i|
%div(style="background-color: #{cycle '#abC', '#fff'};"
class="td")= i

%td
- 1.upto(3).each do |i|
%div(style="background-color: #{cycle '#abC', '#fff'};"
class="td")= i

Working example (differing first arguments in #cycle) ---

%tbody
%tr
%td
- 1.upto(3) do |i|
%div(style="background-color: #{cycle '#abC', '#fff'};"
class="td")= i

%td
- 1.upto(3).each do |i|
%div(style="background-color: #{cycle '#abc', '#fff'};"
class="td")= i

It also fails using css classes .odd & .even for the rows, and with
local string variables odd & even

(I realize that this may not be a haml bug, but I've gotten this far.)

Expected result

==
++
==

Actual result

=+
+=
=+

Eric Wollesen

unread,
Oct 28, 2009, 3:52:46 PM10/28/09
to ha...@googlegroups.com
To get what you want, you probably need to use named cycles. See the
rails doc for cycle.

I suspect this problem has nothing to do with haml.

e.
--
Eric Wollesen
ewol...@gmail.com

Nathan Weizenbaum

unread,
Oct 28, 2009, 3:52:40 PM10/28/09
to ha...@googlegroups.com
Haml has nothing to do with the cycle helper; that's entirely Rails.

Katherine Giron Pe

unread,
Oct 28, 2009, 5:07:46 PM10/28/09
to ha...@googlegroups.com
Jesse..
You can just use css/sass.
.abc
  :background #abC
.white
  :background #fff

  - row_class = cycle("abc", "white")
 -for article in @articles
    %div{:class=>row_class}

Something like that...
But seriously that may not be the cause of the error.
--
-----
BridgeUtopia Web
http://blog.bridgeutopiaweb.com

Jesse

unread,
Nov 18, 2009, 4:58:27 AM11/18/09
to Haml
Reading the documentation, a call to #reset_cycle is the solution.
Thanks.
Reply all
Reply to author
Forward
0 new messages