Module: GoogleDataSource::DataSource::Helper
- Defined in:
- lib/google_data_source/helper.rb
Instance Method Summary collapse
-
#google_data_source_includes(ssl = false) ⇒ Object
Includes the JavaScript files neccessary for data source visualization The helper should be called the header of the layout.
-
#google_datasource_export_link(format) ⇒ Object
Returns a export link for the given format.
-
#google_datatable(url = nil, options = {}) ⇒ Object
Shows a Google data table.
-
#google_timeline(url = nil, options = {}) ⇒ Object
Shows a Google annotated timeline.
-
#google_visualization(type, url = nil, options = {}) ⇒ Object
Shows a Google visualization.
- #reporting_controls(container_id, options) ⇒ Object
Instance Method Details
#google_data_source_includes(ssl = false) ⇒ Object
Includes the JavaScript files neccessary for data source visualization The helper should be called the header of the layout
6 7 8 9 |
# File 'lib/google_data_source/helper.rb', line 6 def google_data_source_includes(ssl = false) html = "<script src='http#{"s" if ssl}://www.google.com/jsapi' type='text/javascript'></script>" html.html_safe end |
#google_datasource_export_link(format) ⇒ Object
Returns a export link for the given format
53 54 55 56 |
# File 'lib/google_data_source/helper.rb', line 53 def google_datasource_export_link(format) label = t("google_data_source.export_links.#{format}") link_to(label, '#', :class => "export_as_#{format}") end |
#google_datatable(url = nil, options = {}) ⇒ Object
Shows a Google data table
59 60 61 |
# File 'lib/google_data_source/helper.rb', line 59 def google_datatable(url = nil, = {}) google_visualization('Table', url, ) end |
#google_timeline(url = nil, options = {}) ⇒ Object
Shows a Google annotated timeline
64 65 66 |
# File 'lib/google_data_source/helper.rb', line 64 def google_timeline(url = nil, = {}) google_visualization('TimeLine', url, ) end |
#google_visualization(type, url = nil, options = {}) ⇒ Object
Shows a Google visualization. Available types
include:
-
Table
-
TimeLine
url
defines the URL to the data source and defaults to +url_for(:format => ‘datasource’). The options are generally passed to the visualization JS objects after camlizing the keys Options that are not passed include:
-
:container_id
: The Dom id of the container element
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/google_data_source/helper.rb', line 19 def google_visualization(type, url = nil, = {}) # extract options that are not meant for the javascript part container_id = .delete(:container_id) || "google_#{type.underscore}" # camelize option keys = .to_a.inject({}) { |memo, opt| memo[opt.first.to_s.camelize(:lower)] = opt.last; memo } url ||= url_for(:format => 'datasource') html = content_tag(:div, :id => container_id) { } html << javascript_tag("DataSource.Visualization.create('#{type.camelize}', '#{url}', '#{container_id}', #{.to_json});") html << reporting_controls(container_id, ) html end |
#reporting_controls(container_id, options) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/google_data_source/helper.rb', line 34 def reporting_controls(container_id, ) html = tag(:div, {:id => "#{container_id}_controls", :class => "data_source_controls"}, true) # Add Export links unless [:exportable_as].nil? || [:exportable_as].empty? html << tag(:div, {:id => "#{container_id}_export_as"}, true) html << t('google_data_source.export_links.export_as') html << ' ' [:exportable_as].each do |format| html << google_datasource_export_link(format) end html << ActiveSupport::SafeBuffer.new("</div>") end html << ActiveSupport::SafeBuffer.new("</div>") # ugly, any ideas? html end |