Class: Calendrier::CalendrierBuilder::SimpleBuilder

Inherits:
Builder
  • Object
show all
Defined in:
lib/calendrier/calendrier_builder.rb

Instance Method Summary collapse

Methods inherited from Builder

#initialize

Constructor Details

This class inherits a constructor from Calendrier::CalendrierBuilder::Builder

Instance Method Details

#render(header, content) ⇒ Object



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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/calendrier/calendrier_builder.rb', line 23

def render(header, content)
  display = @options[:display]
  title = @options[:title] || ''
  cell_date_format = @options[:cell_date_format] || (display == :month ? '%A' : :default)
  time_slot_title = @options[:time_slot_title] || ''

  @context.(:div, nil, :class => "calendar #{display.to_s}") do
    cal = @context.(:span, title)
    cal << @context.(:table, nil) do

      unless header.nil?
        thead = @context.(:thead, nil) do
          @context.(:tr, nil) do
            ths = "".html_safe
            ths << @context.(:th, time_slot_title) if display == :week
            header.each do |cell_date|
              ths << @context.(:th, I18n.l(cell_date, :format => cell_date_format))
            end
            ths
          end
        end
      end

      unless content.nil?
        tbody = @context.(:tbody, nil) do
          trs = "".html_safe
          content.each_with_index do |row, index|
            trs << @context.(:tr, nil) do
              tds = "".html_safe
              tds << @context.(:td, "#{index}h") if display == :week
              row.collect do |cell|
                cell_content = "".html_safe
                cell_time = cell[:time]
                cell_content << @context.(:span, cell_time.day) if display == :month && !cell_time.nil?
                cell_content << cell[:content]
                tds << @context.(:td, cell_content)
              end
              tds
            end
          end
          @context.concat trs
        end
      end

      thead.concat(tbody) unless thead.nil?
    end
    cal
  end
end