Sha256: 4750c55591ca941e4f8868acb1ab56060d5c7f9bd585ea941c90a43b45e23db7

Contents?: true

Size: 1.47 KB

Versions: 3

Compression:

Stored size: 1.47 KB

Contents

require 'rack/utils'
require 'cgi'

module LedgerWeb
  module Helpers

    include Rack::Utils

    def partial (template, locals = {})
      erb(template, :layout => false, :locals => locals)
    end
  
    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
  
    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
  
    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

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

    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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ledger_web-1.5.2 lib/ledger_web/helpers.rb
ledger_web-1.5.1 lib/ledger_web/helpers.rb
ledger_web-1.5.0 lib/ledger_web/helpers.rb