Sha256: 85968bf8a3af578c939c8f3b0c861a64553da2e06167661cb8dd74c75e54006b

Contents?: true

Size: 481 Bytes

Versions: 8

Compression:

Stored size: 481 Bytes

Contents

require 'base64'

module BumpsparkHelper
  
  # Generate a "bumpspark"-style sparkline image tag
  #
  # call-seq:
  #   <%= bumpspark_tag([20, 23, 12, 23]) %>
  def bumpspark_tag(numbers, html_opts={})
    graph = Bumpspark::Graph.new(numbers)
    tag(:img, html_opts.merge(:src => bumpspark_tag_src(graph)))
  end
  
  def bumpspark_tag_src(graph) #:nodoc:
    data = Base64.encode64(graph.to_png).delete("\n")
    return "data:image/png;base64,#{CGI.escape(data)}" 
  end
  
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
bruce-bumpspark-1.0.0 lib/bumpspark_helper.rb
bruce-bumpspark-1.0.1 lib/bumpspark_helper.rb
bruce-bumpspark-1.0.2 lib/bumpspark_helper.rb
bruce-bumpspark-1.0.3 lib/bumpspark_helper.rb
bruce-bumpspark-1.0.4 lib/bumpspark_helper.rb
bumpspark-1.1.1 lib/bumpspark_helper.rb
bumpspark-1.1.0 lib/bumpspark_helper.rb
bumpspark-1.0.4 lib/bumpspark_helper.rb