Module: FullstackCarouselHelper

Defined in:
app/helpers/fullstack_carousel_helper.rb

Instance Method Summary collapse

Instance Method Details

<% end %>



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/helpers/fullstack_carousel_helper.rb', line 11

def carousel_page_part(key, options = {}, &block)
  @_fullstack_carousel_counter ||= 0
  @_fullstack_carousel_counter += 1
  
  options = { :arrows => true }.merge(options)
  htmlid  = options.delete(:id) || "carousel-#{key}-#{@_fullstack_carousel_counter}"
  htmlclass   = ((options.delete(:class) || "").split(/\s+/) + [ "carousel" ]).join(" ")
  options[:class] = htmlclass
  options[:id] = htmlid
  arrows  = !!options.delete(:arrows)

  arrows_html = !arrows ? "" : <<-eos
    <a class="carousel-control left" href="##{htmlid}" data-slide="prev">&lsaquo;</a>
    <a class="carousel-control right" href="##{htmlid}" data-slide="next">&rsaquo;</a>    
  eos

  items_html = ""
  
  part( key, :schema => :slideshow ) do |slideshow|
      slideshow.items.each_with_index do |item, i|    
         slideshow_page = capture do
            :div, :class => ( i == 0 ? "item active" : "item" ) do
             yield(item)
           end
         end
         items_html << slideshow_page
      end
  end
  
   :div, options do
    raw <<-eos
        <div class="carousel-inner">
        #{items_html}
        </div>
        #{arrows_html}
    eos
   
  end
end