jqplot_rails 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,6 @@
1
+ == v0.0.4
2
+ * Make asset loading on-demand
3
+
1
4
  == v0.0.3
2
5
  * DRY up implementation
3
6
  * Provide #jqplot_data_onclick helper for onclick events on plot data
@@ -1 +1,18 @@
1
1
  Build jqplots from the comfort of rails
2
+
3
+ Example:
4
+
5
+ # app/controller/plots_controller.rb
6
+ before_filter do
7
+ JqPlotRails::JqPlot.enable
8
+ end
9
+
10
+ # app/views/layouts/application.html.haml
11
+ ...
12
+ = stylesheet_link_expansion :jqplot_rails
13
+
14
+ # app/view/plots/myplot.html.haml
15
+ %div{:id => :myplot}
16
+ = jqplot('myplot', @data, :animate => true)
17
+
18
+
@@ -0,0 +1,38 @@
1
+ module JqPlotRails
2
+ class JqPlot
3
+ class << self
4
+ # args:: Plugins to load. Symbols are allowed which will be camelcased automatically.
5
+ # Enables jqplot by loading required JS and CSS. Loads all plugins if no plugins are provided. Prevent
6
+ # any plugins loading by supplying :no_plugins
7
+ def enable(*args)
8
+ # Load base files first
9
+ Dir.glob(Rails.root.join('public', 'jqplot_rails', 'javascripts', '*.js')).each do |path|
10
+ path = File.join('/', 'jqplot_rails', 'javascripts', File.basename(path))
11
+ ::ActionView::Helpers::AssetTagHelper.register_javascript_expansion :jqplot_rails => path
12
+ ::ActionView::Helpers::AssetTagHelper.register_javascript_expansion :plugins => path
13
+ end
14
+ # And now load the plugins
15
+ unless(args.delete(:no_plugins))
16
+ if(args.empty?)
17
+ # NOTE: The reverse is to let us lazily load everything in the right order. If dependencies change
18
+ # this will probably stop working at which point I'll just throw in an array with order of load
19
+ Dir.glob(Rails.root.join('public', 'jqplot_rails', 'javascripts', 'plugins', '*.js')).reverse.each do |path|
20
+ path = File.join('/', 'jqplot_rails', 'javascripts', 'plugins', File.basename(path))
21
+ ::ActionView::Helpers::AssetTagHelper.register_javascript_expansion :jqplot_rails => path
22
+ ::ActionView::Helpers::AssetTagHelper.register_javascript_expansion :plugins => path
23
+ end
24
+ else
25
+ args.each do |plugin|
26
+ ::ActionView::Helpers::AssetTagHelper.register_javascript_expansion :jqplot_rails => "/jqplot_rails/javascripts/jqplot.#{plugin.to_s.camelize.sub(/^./, plugin[0,1].downcase)}.min.js"
27
+ ::ActionView::Helpers::AssetTagHelper.register_javascript_expansion :plugins => "/jqplot_rails/javascripts/jqplot.#{plugin.to_s.camelize.sub(/^./, plugin[0,1].downcase)}.min.js"
28
+ end
29
+ end
30
+ end
31
+ ::ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion :jqplot_rails => '/jqplot_rails/stylesheets/jquery.jqplot.min.css'
32
+ ::ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion :plugins => '/jqplot_rails/stylesheets/jquery.jqplot.min.css'
33
+ ::ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion :jqplot_rails => '/jqplot_rails/stylesheets/jqplot_rails_overrides.css'
34
+ ::ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion :plugins => '/jqplot_rails/stylesheets/jqplot_rails_overrides.css'
35
+ end
36
+ end
37
+ end
38
+ end
@@ -6,24 +6,7 @@ module JqPlotRails
6
6
 
7
7
  config.to_prepare do
8
8
  require 'jqplot_rails/jqplot_action_view'
9
- # Load base files first
10
- Dir.glob(Rails.root.join('public', 'jqplot_rails', 'javascripts', '*.js')).each do |path|
11
- path = File.join('/', 'jqplot_rails', 'javascripts', File.basename(path))
12
- ::ActionView::Helpers::AssetTagHelper.register_javascript_expansion :jqplot_rails => path
13
- ::ActionView::Helpers::AssetTagHelper.register_javascript_expansion :plugins => path
14
- end
15
- # And now load the plugins
16
- # NOTE: The reverse is to let us lazily load everything in the right order. If dependencies change
17
- # this will probably stop working at which point I'll just throw in an array with order of load
18
- Dir.glob(Rails.root.join('public', 'jqplot_rails', 'javascripts', 'plugins', '*.js')).reverse.each do |path|
19
- path = File.join('/', 'jqplot_rails', 'javascripts', 'plugins', File.basename(path))
20
- ::ActionView::Helpers::AssetTagHelper.register_javascript_expansion :jqplot_rails => path
21
- ::ActionView::Helpers::AssetTagHelper.register_javascript_expansion :plugins => path
22
- end
23
- ::ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion :jqplot_rails => '/jqplot_rails/stylesheets/jquery.jqplot.min.css'
24
- ::ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion :plugins => '/jqplot_rails/stylesheets/jquery.jqplot.min.css'
25
- ::ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion :jqplot_rails => '/jqplot_rails/stylesheets/jqplot_rails_overrides.css'
26
- ::ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion :plugins => '/jqplot_rails/stylesheets/jqplot_rails_overrides.css'
9
+ require 'jqplot_rails/jqplot'
27
10
  end
28
11
  end
29
12
  end
@@ -13,5 +13,5 @@ module JqPlotRails
13
13
  end
14
14
  end
15
15
 
16
- VERSION = Version.new('0.0.3')
16
+ VERSION = Version.new('0.0.4')
17
17
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jqplot_rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Roberts
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-12-13 00:00:00 -08:00
18
+ date: 2011-12-29 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -431,6 +431,7 @@ files:
431
431
  - files/dist/plugins/jqplot.pointLabels.min.js
432
432
  - files/dist/copyright.txt
433
433
  - lib/jqplot_rails.rb
434
+ - lib/jqplot_rails/jqplot.rb
434
435
  - lib/jqplot_rails/railtie.rb
435
436
  - lib/jqplot_rails/jqplot_action_view.rb
436
437
  - lib/jqplot_rails/tasks.rb