Class: JqPlotRails::JqPlot
- Inherits:
-
Object
- Object
- JqPlotRails::JqPlot
- Defined in:
- lib/jqplot_rails/jqplot.rb
Class Method Summary collapse
-
.enable(*args) ⇒ Object
- args
-
Plugins to load.
Class Method Details
.enable(*args) ⇒ Object
- args
-
Plugins to load. Symbols are allowed which will be camelcased automatically.
Enables jqplot by loading required JS and CSS. Loads all plugins if no plugins are provided. Prevent any plugins loading by supplying :no_plugins
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/jqplot_rails/jqplot.rb', line 7 def enable(*args) # Load base files first Dir.glob(Rails.root.join('public', 'jqplot_rails', 'javascripts', '*.js')).each do |path| path = File.join('/', 'jqplot_rails', 'javascripts', File.basename(path)) ::ActionView::Helpers::AssetTagHelper.register_javascript_expansion :jqplot_rails => path ::ActionView::Helpers::AssetTagHelper.register_javascript_expansion :plugins => path end # And now load the plugins unless(args.delete(:no_plugins)) if(args.empty?) # NOTE: The reverse is to let us lazily load everything in the right order. If dependencies change # this will probably stop working at which point I'll just throw in an array with order of load Dir.glob(Rails.root.join('public', 'jqplot_rails', 'javascripts', 'plugins', '*.js')).reverse.each do |path| path = File.join('/', 'jqplot_rails', 'javascripts', 'plugins', File.basename(path)) ::ActionView::Helpers::AssetTagHelper.register_javascript_expansion :jqplot_rails => path ::ActionView::Helpers::AssetTagHelper.register_javascript_expansion :plugins => path end else args.each do |plugin| ::ActionView::Helpers::AssetTagHelper.register_javascript_expansion :jqplot_rails => "/jqplot_rails/javascripts/jqplot.#{plugin.to_s.camelize.sub(/^./, plugin[0,1].downcase)}.min.js" ::ActionView::Helpers::AssetTagHelper.register_javascript_expansion :plugins => "/jqplot_rails/javascripts/jqplot.#{plugin.to_s.camelize.sub(/^./, plugin[0,1].downcase)}.min.js" end end end ::ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion :jqplot_rails => '/jqplot_rails/stylesheets/jquery.jqplot.min.css' ::ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion :plugins => '/jqplot_rails/stylesheets/jquery.jqplot.min.css' ::ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion :jqplot_rails => '/jqplot_rails/stylesheets/jqplot_rails_overrides.css' ::ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion :plugins => '/jqplot_rails/stylesheets/jqplot_rails_overrides.css' end |