Module DynamicReports::Templates

  1. lib/dynamic_reports/templates.rb

Options are:

:layout       If set to false, no layout is rendered, otherwise
              the specified layout is used
:locals       A hash with local variables that should be available
              in the template

Methods

public instance

  1. builder
  2. chart_url
  3. commify
  4. csv
  5. erb
  6. haml
  7. titleize

Public instance methods

builder (options={}, locals={}, &block)
[show source]
# File lib/dynamic_reports/templates.rb, line 25
    def builder(options={}, locals={}, &block)
      require_warn("Builder") unless defined?(::Builder)
      template = options.delete(:template)
      options, template = template, nil if template.is_a?(Hash)
      template = lambda { block } if template.nil?
      render :builder, template, options, locals
    end
chart_url (chart,report)
[show source]
# File lib/dynamic_reports/templates.rb, line 46
    def chart_url(chart,report)
      columns = chart.columns ? chart.columns : report.columns
      chart_type = chart.type.nil? ?  :line : chart.type.to_sym 
      case chart_type
      when :line
        Charts.line_chart(chart,columns,report)
      when :pie
        Charts.pie_chart(chart,columns,report)
      when :bar
        Charts.bar_column_chart(chart,columns,report,:vertical)
      when :column
        Charts.bar_column_chart(chart,columns,report,:horizontal)
      else
        raise StandardError => "Unknown chart type '#{chart.type}'."
      end

    end
commify (object)
[show source]
# File lib/dynamic_reports/templates.rb, line 38
    def commify(object)
      if object.is_a?(Numeric)
        object.to_s.gsub(/(\d)(?=(\d{3})+$)/,'\1,')
      else
        object
      end
    end
csv (options={}, locals={})
[show source]
# File lib/dynamic_reports/templates.rb, line 8
    def csv(options={}, locals={})
      template = options.delete(:template)
      render :csv, template, options.merge!(:content_type => "csv"), locals
    end
erb (options={}, locals={})
[show source]
# File lib/dynamic_reports/templates.rb, line 13
    def erb(options={}, locals={})
      require "erb"
      template = options.delete(:template)
      render :erb, template, options, locals
    end
haml (options={}, locals={})
[show source]
# File lib/dynamic_reports/templates.rb, line 19
    def haml(options={}, locals={})
      require_warn("Haml") unless defined?(::Haml::Engine)
      template = options.delete(:template)
      render :haml, template, options, locals
    end
titleize (object)

TODO: Add Report Helpers for injection

[show source]
# File lib/dynamic_reports/templates.rb, line 34
    def titleize(object)
      object.to_s.split('_').each{ |word| word.capitalize! }.join(' ') 
    end