| make sure meaningful default dom ids are used - reportable - Fork of reportable… | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| commit d1eb67d6de166aa56e020e4510150c1e91a93fed | |
| parent b8ee111f12ef95eec333b448a14179d9aa7eef2f | |
| Author: Marco Otte-Witte <[email protected]> | |
| Date: Thu, 13 May 2010 13:43:43 +0200 | |
| make sure meaningful default dom ids are used | |
| Diffstat: | |
| M lib/saulabs/reportable/report_tag_… | 16 +++++++++------- | |
| M spec/other/report_tag_helper_spec.… | 21 +++++++++++++++------ | |
| 2 files changed, 24 insertions(+), 13 deletions(-) | |
| --- | |
| diff --git a/lib/saulabs/reportable/report_tag_helper.rb b/lib/saulabs/reportab… | |
| @@ -58,15 +58,14 @@ module Saulabs | |
| end | |
| - # Renders a sparkline with the given data using grafico. | |
| + # Renders a sparkline with the given data using Raphael. | |
| # | |
| # @param [Array<Array<DateTime, Float>>] data | |
| # an array of report data as returned by {Saulabs::Reportable::Report#… | |
| # @param [Hash] options | |
| # options for width, height, the dom id and the format | |
| - # @param [Hash] grafico_options | |
| - # options for grafico which to_json get called on, | |
| - # see the grafico documentation for more information. | |
| + # @param [Hash] raphael_options | |
| + # options that are passed directly to Raphael as JSON | |
| # | |
| # @option options [Fixnum] :width (300) | |
| # the width of the generated graph | |
| @@ -80,11 +79,14 @@ module Saulabs | |
| # | |
| # @example Rendering a sparkline tag for report data | |
| # | |
| - # <%= raphael_report_tag(User.registrations_report, {:width => 200, :h… | |
| + # <%= raphael_report_tag(User.registrations_report, { :width => 200, :… | |
| # | |
| def raphael_report_tag(data, options = {}, raphael_options = {}) | |
| + @__raphael_report_tag_count ||= -1 | |
| + @__raphael_report_tag_count += 1 | |
| + default_dom_id = "#{data.model_name.downcase}_#{data.report_name}#{@__… | |
| options.reverse_merge!(Config.raphael_options.slice(:width, :height, :… | |
| - options.reverse_merge!(:dom_id => "#{data.model_name.downcase}_#{data.… | |
| + options.reverse_merge!(:dom_id => default_dom_id) | |
| raphael_options.reverse_merge!(Config.raphael_options.except(:width, :… | |
| %Q{<div id="#{options[:dom_id]}" style="width:#{options[:width]}px;hei… | |
| <script type="text\/javascript" charset="utf-8"> | |
| @@ -92,7 +94,7 @@ module Saulabs | |
| graph.g.linechart( | |
| -10, 4, #{options[:width]}, #{options[:height]}, | |
| #{(0..data.size).to_a.to_json}, | |
| - #{data.map{|d| eval options[:format], d[1].send(:binding) }.to_jso… | |
| + #{data.map { |d| eval options[:format], d[1].send(:binding) }.to_j… | |
| #{raphael_options.to_json} | |
| ).hover(function() { | |
| this.disc = graph.g.disc(this.x, this.y, 3).attr({fill: "#2F69BF",… | |
| diff --git a/spec/other/report_tag_helper_spec.rb b/spec/other/report_tag_helpe… | |
| @@ -5,23 +5,32 @@ describe Saulabs::Reportable::ReportTagHelper do | |
| before do | |
| @helper = TestHelper.new | |
| end | |
| - | |
| + | |
| describe '#raphael_report_tag' do | |
| - | |
| + | |
| data_set = Saulabs::Reportable::ResultSet.new([[DateTime.now, 1.0], [DateT… | |
| - | |
| + | |
| it 'should return a string' do | |
| @helper.raphael_report_tag(data_set).class.should == String | |
| end | |
| - | |
| + | |
| it 'should contain a div tag' do | |
| @helper.raphael_report_tag(data_set).should =~ /^<div id=".*">.*<\/div>/ | |
| end | |
| - | |
| + | |
| it 'should contain a script tag' do | |
| @helper.raphael_report_tag(data_set).should =~ /<script type="text\/java… | |
| end | |
| - | |
| + | |
| + it 'should assign a default dom id to the the div tag if none is specified… | |
| + @helper.raphael_report_tag(data_set).should =~ /^<div id="#{data_set.mod… | |
| + end | |
| + | |
| + it 'should assign correct default dom ids to the the div tag if none is sp… | |
| + @helper.raphael_report_tag(data_set).should =~ /^<div id="#{data_set.mod… | |
| + @helper.raphael_report_tag(data_set).should =~ /^<div id="#{data_set.mod… | |
| + end | |
| + | |
| end | |
| describe '#google_report_tag' do |