Class: TableHelper::TableBuilder

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TagHelper
Defined in:
lib/ical/table_builder.rb

Direct Known Subclasses

CalendarHelper::CalendarBuilder

Instance Method Summary collapse

Constructor Details

#initialize(objects, template, options) ⇒ TableBuilder

Returns a new instance of TableBuilder.

Raises:

  • (ArgumentError)


16
17
18
19
# File 'lib/ical/table_builder.rb', line 16

def initialize(objects, template, options)
  raise ArgumentError, "TableBuilder expects an Enumerable object but found #{objects.inspect}" unless objects.respond_to? :each
  @objects, @template, @options = objects, template, options
end

Instance Method Details

#body(*args) ⇒ Object

Raises:

  • (ArgumentError)


46
47
48
49
50
51
52
# File 'lib/ical/table_builder.rb', line 46

def body(*args)
  raise ArgumentError, "Missing block" unless block_given?
  options = options_from_hash(args)
  tbody do
    @objects.each { |c| yield(c) }
  end
end

#body_r(*args) ⇒ Object

Raises:

  • (ArgumentError)


54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ical/table_builder.rb', line 54

def body_r(*args)
  raise ArgumentError, "Missing block" unless block_given?
  options = options_from_hash(args)
  tbody do
    @objects.each { |c|
      concat(tag(:tr, options, true))
      yield(c)
      concat('</tr>'.html_safe)
    }
  end
end

#d(*args) ⇒ Object



85
86
87
88
89
90
91
92
93
94
# File 'lib/ical/table_builder.rb', line 85

def d(*args)
  if block_given?
    concat(tag(:td, options_from_hash(args), true))
    yield
    concat('</td>')
  else
    content = args.shift
    (:td, content, options_from_hash(args))
  end
end

#h(*args) ⇒ Object



74
75
76
77
78
79
80
81
82
83
# File 'lib/ical/table_builder.rb', line 74

def h(*args)
  if block_given?
    concat(tag(:th, options_from_hash(args), true))
    yield
    concat('</th>')
  else
    content = args.shift
    (:th, content, options_from_hash(args))
  end
end

#head(*args) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ical/table_builder.rb', line 21

def head(*args)
  if block_given?
    concat(tag(:thead, options_from_hash(args), true))
    yield
    concat('</thead>')
  else
    @num_of_columns = args.size
    (:thead,
      (:tr,
        args.collect { |c| (:th, c.html_safe)}.join('').html_safe
      )
    )
  end
end

#head_r(*args) ⇒ Object

Raises:

  • (ArgumentError)


36
37
38
39
40
41
42
43
44
# File 'lib/ical/table_builder.rb', line 36

def head_r(*args)
  raise ArgumentError, "Missing block" unless block_given?
  options = options_from_hash(args)
  head do
    concat(tag(:tr, options, true))
    yield
    concat('</tr>')
  end
end

#r(*args) ⇒ Object

Raises:

  • (ArgumentError)


66
67
68
69
70
71
72
# File 'lib/ical/table_builder.rb', line 66

def r(*args)
  raise ArgumentError, "Missing block" unless block_given?
  options = options_from_hash(args)
  tr(options) do
    yield
  end
end