Module: LedgerWeb::Helpers

Includes:
Rack::Utils
Defined in:
lib/ledger_web/helpers.rb

Instance Method Summary collapse

Instance Method Details

#default(key, value) ⇒ Object



43
44
45
46
47
48
# File 'lib/ledger_web/helpers.rb', line 43

def default(key, value)
  if not Report.params.has_key? key
    puts "Setting #{key} to #{value}"
    Report.params[key] = value
  end
end

#expect(expected) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ledger_web/helpers.rb', line 30

def expect(expected)
  not_present = []
  expected.each do |key|
    if not params.has_key? key
      not_present << key
    end
  end
  
  if not_present.length > 0
    raise "Missing params: #{not_present.join(', ')}"
  end
end

#partial(template, locals = {}) ⇒ Object



9
10
11
# File 'lib/ledger_web/helpers.rb', line 9

def partial (template, locals = {})
  erb(template, :layout => false, :locals => locals)
end

#query(options = {}, &block) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/ledger_web/helpers.rb', line 21

def query(options={}, &block)
  q = capture(&block)
  report = Report.from_query(q)
  if options[:pivot]
    report = report.pivot(options[:pivot], options[:pivot_sort_order])
  end
  return report
end

#table(report, options = {}) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/ledger_web/helpers.rb', line 13

def table(report, options = {})
  Table.new(report) do |t|
    t.decorate :all => LedgerWeb::Decorators::NumberDecorator.new
    t.attributes[:class] = 'table table-striped table-hover table-bordered table-condensed'
    yield t if block_given?
  end.render
end

#visualization(report, options = {}, &block) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ledger_web/helpers.rb', line 50

def visualization(report, options={}, &block)
  vis = capture(&block)
  @vis_count ||= 0
  @vis_count += 1
  @_out_buf.concat(
    partial(
      :visualization,
      :report => report,
      :visualization_code => vis, 
      :div_id => "vis_#{@vis_count}"
    )
  )
end