Class: Tableview::TV

Inherits:
Object
  • Object
show all
Defined in:
lib/tableview/tv.rb

Instance Method Summary collapse

Instance Method Details

#call(template) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/tableview/tv.rb', line 3

def call(template)
  source = template.source
  start, ending = /^\s*/, /\s+(.+?)(?= unless| if| do|\{|#|$)/
  source.gsub!(/#{start}\+#{ending}/, 'table.column(\1)')
  source.gsub!(/#{start}\=>#{ending}/, 'table.table_for(\1)')
  source.gsub!(/#{start}\=#{ending}/, 'table.generate_subtable_for(\1)')
  source.gsub!(/#{start}\*#{ending}/, 'table.config(\1)')
  %{
    format = Tableview::Helper::Format.new(params)
    tv = Tableview::ViewHandler.dsl do |table|
      #{source}
    end
    output = Tableview::output_class(params[:format]).new
    output.process(tv)
    output.to_s
  }
end