/
base.rb
65 lines (52 loc) · 1.4 KB
/
base.rb
1
2
3
4
5
6
7
8
9
10
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
module TableCloth
class Base
include TableCloth::Extensions::Actions
include TableCloth::Extensions::RowAttributes
NoPresenterError = Class.new(Exception)
attr_reader :collection, :view
def initialize(collection, view)
@collection = collection
@view = view
end
def config
self.class.config
end
class << self
def presenter(klass=nil)
return @presenter = klass if klass
return @presenter if @presenter
if superclass.respond_to?(:presenter)
superclass.presenter
else
raise NoPresenterError, "No Presenter"
end
end
def column(*args, &block)
options = args.extract_options! || {}
options[:proc] = block if block_given?
column_class = options.delete(:using) || Column
args.each do |name|
add_column(class: column_class, options: options, name: name)
end
end
def columns
@columns ||= {}
if superclass.respond_to? :columns
@columns = superclass.columns.merge(@columns)
end
@columns
end
def add_column(options)
@columns ||= {}
@columns[options[:name]] = options
end
def config
@config ||= if superclass.respond_to?(:config)
superclass.config.dup
else
Configuration.new
end
end
end
end
end