Module: BumpsparkHelper

Defined in:
lib/bumpspark_helper.rb

Instance Method Summary collapse

Instance Method Details

#bumpspark_tag(numbers, html_opts = {}) ⇒ Object

Generate a “bumpspark”-style sparkline image tag

call-seq:

<%= bumpspark_tag([20, 23, 12, 23]) %>


9
10
11
12
# File 'lib/bumpspark_helper.rb', line 9

def bumpspark_tag(numbers, html_opts={})
  graph = Bumpspark::Graph.new(numbers)
  tag(:img, html_opts.merge(:src => bumpspark_tag_src(graph)))
end

#bumpspark_tag_src(graph) ⇒ Object

:nodoc:



14
15
16
17
# File 'lib/bumpspark_helper.rb', line 14

def bumpspark_tag_src(graph) #:nodoc:
  data = Base64.encode64(graph.to_png).delete("\n")
  return "data:image/png;base64,#{CGI.escape(data)}" 
end