rgviz-rails 0.44 → 0.45

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -10,8 +10,18 @@ This library is built on top of rgviz[https://github.com/asterite/rgviz].
10
10
 
11
11
  gem install rgviz-rails
12
12
 
13
+ === Rails 3
14
+
15
+ In your Gemfile
16
+
17
+ gem 'rgviz'
18
+ gem 'rgviz-rails', :require => 'rgviz_rails'
19
+
20
+ === Rails 2.x
21
+
13
22
  In your environment.rb
14
23
 
24
+ config.gem "rgviz"
15
25
  config.gem "rgviz-rails", :lib => 'rgviz_rails'
16
26
 
17
27
  === Usage
@@ -90,7 +100,7 @@ If you need to tweak a result before returning it, just include a block:
90
100
 
91
101
  You can invoke the rgviz method in your views. {Read more about this}[https://github.com/asterite/rgviz-rails/wiki/Showing-a-visualization-in-a-view].
92
102
 
93
- You can always do it the {old way}[http://code.google.com/apis/visualization/documentation/using_overview.html]. {Read more about this}
103
+ You can always do it the {old way}[http://code.google.com/apis/visualization/documentation/using_overview.html].
94
104
 
95
105
  === Current Limitations
96
106
  * The *format* clause is ignored (If someone knows of a working icu library for ruby, please tell me)
@@ -2,75 +2,73 @@ require "rgviz_rails/view_helper"
2
2
  # includes the view helper to ActionView::Base
3
3
  ActionView::Base.send(:include, Rgviz::ViewHelper)
4
4
 
5
- def _define_rgviz_class
6
- ::ActionController::Base.module_eval do
7
- def render_with_rgviz(*args, &block)
8
- if args.length == 1 && args[0].kind_of?(Hash)
9
- hash = args.first
10
- case hash[:rgviz]
11
- when nil then render_without_rgviz *args, &block
12
- else
13
- model = hash[:rgviz]
14
- conditions = hash[:conditions]
15
- extensions = hash[:extensions]
16
- query = params[:tq]
17
- tqx = params[:tqx] || ''
5
+ module Rgviz
6
+ def self._define_rgviz_class
7
+ ::ActionController::Base.module_eval do
8
+ def render_with_rgviz(*args, &block)
9
+ if args.length == 1 && args[0].kind_of?(Hash)
10
+ hash = args.first
11
+ case hash[:rgviz]
12
+ when nil then render_without_rgviz *args, &block
13
+ else
14
+ model = hash[:rgviz]
15
+ conditions = hash[:conditions]
16
+ extensions = hash[:extensions]
17
+ query = params[:tq]
18
+ tqx = params[:tqx] || ''
18
19
 
19
- tqx = Rgviz::Tqx.parse(tqx)
20
+ tqx = Rgviz::Tqx.parse(tqx)
20
21
 
21
- begin
22
- executor = Rgviz::Executor.new model, query
23
- options = {}
24
- options[:conditions] = conditions if conditions
25
- options[:extensions] = extensions if extensions
26
- table = executor.execute options
22
+ begin
23
+ executor = Rgviz::Executor.new model, query
24
+ options = {}
25
+ options[:conditions] = conditions if conditions
26
+ options[:extensions] = extensions if extensions
27
+ table = executor.execute options
27
28
 
28
- yield table if block_given?
29
+ yield table if block_given?
29
30
 
30
- case tqx['out']
31
- when 'json'
32
- render_without_rgviz :text => Rgviz::JsRenderer.render(table, tqx)
33
- when 'html'
34
- render_without_rgviz :text => Rgviz::HtmlRenderer.render(table)
35
- when 'csv'
36
- csv_output = Rgviz::CsvRenderer.render(table)
37
- if tqx['outFileName']
38
- send_data csv_output, :filename => tqx['outFileName'], :type => 'text/csv'
31
+ case tqx['out']
32
+ when 'json'
33
+ render_without_rgviz :text => Rgviz::JsRenderer.render(table, tqx)
34
+ when 'html'
35
+ render_without_rgviz :text => Rgviz::HtmlRenderer.render(table)
36
+ when 'csv'
37
+ csv_output = Rgviz::CsvRenderer.render(table)
38
+ if tqx['outFileName']
39
+ send_data csv_output, :filename => tqx['outFileName'], :type => 'text/csv'
40
+ else
41
+ render_without_rgviz :text => csv_output
42
+ end
39
43
  else
40
- render_without_rgviz :text => csv_output
44
+ render_without_rgviz :text => Rgviz::JsRenderer.render_error('not_supported', "Unsupported output type: #{out}", tqx)
45
+ end
46
+ rescue ParseException => e
47
+ case tqx['out']
48
+ when 'json'
49
+ render_without_rgviz :text => Rgviz::JsRenderer.render_error('invalid_query', e.message, tqx)
50
+ when 'html'
51
+ render_without_rgviz :text => "<b>Error:</b> #{e.message}"
52
+ when 'csv'
53
+ render_without_rgviz :text => "Error: #{e.message}"
54
+ else
55
+ render_without_rgviz :text => "<b>Unsupported output type:</b> #{out}"
41
56
  end
42
- else
43
- render_without_rgviz :text => Rgviz::JsRenderer.render_error('not_supported', "Unsupported output type: #{out}", tqx)
44
- end
45
- rescue ParseException => e
46
- case tqx['out']
47
- when 'json'
48
- render_without_rgviz :text => Rgviz::JsRenderer.render_error('invalid_query', e.message, tqx)
49
- when 'html'
50
- render_without_rgviz :text => "<b>Error:</b> #{e.message}"
51
- when 'csv'
52
- render_without_rgviz :text => "Error: #{e.message}"
53
- else
54
- render_without_rgviz :text => "<b>Unsupported output type:</b> #{out}"
55
57
  end
56
58
  end
59
+ else
60
+ render_without_rgviz *args, &block
57
61
  end
58
- else
59
- render_without_rgviz *args, &block
60
62
  end
63
+ alias_method_chain :render, :rgviz
61
64
  end
62
- alias_method_chain :render, :rgviz
63
65
  end
64
66
  end
65
67
 
66
- if Rails::VERSION::MAJOR == 2
67
- config.after_initialize do
68
- _define_rgviz_class
69
- end
70
- else
68
+ if Rails::VERSION::MAJOR > 2
71
69
  class Railtie < Rails::Railtie
72
70
  initializer "define rgviz class" do
73
- _define_rgviz_class
71
+ Rgviz._define_rgviz_class
74
72
  end
75
73
  end
76
74
  end
@@ -197,10 +197,11 @@ module Rgviz
197
197
 
198
198
  @first_time = 0
199
199
 
200
- if defined? :raw
201
- raw out
202
- else
200
+
201
+ if Rails::VERSION::MAJOR == 2
203
202
  out
203
+ else
204
+ raw out
204
205
  end
205
206
  end
206
207
 
data/rails/init.rb ADDED
@@ -0,0 +1,5 @@
1
+ if Rails::VERSION::MAJOR == 2
2
+ config.after_initialize do
3
+ Rgviz._define_rgviz_class
4
+ end
5
+ end
metadata CHANGED
@@ -1,11 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgviz-rails
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 81
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
- - 44
8
- version: "0.44"
8
+ - 45
9
+ version: "0.45"
9
10
  platform: ruby
10
11
  authors:
11
12
  - Ary Borenszweig
@@ -13,7 +14,7 @@ autorequire:
13
14
  bindir: bin
14
15
  cert_chain: []
15
16
 
16
- date: 2010-12-11 00:00:00 -03:00
17
+ date: 2010-12-16 00:00:00 -03:00
17
18
  default_executable:
18
19
  dependencies:
19
20
  - !ruby/object:Gem::Dependency
@@ -24,6 +25,7 @@ dependencies:
24
25
  requirements:
25
26
  - - ">="
26
27
  - !ruby/object:Gem::Version
28
+ hash: 3
27
29
  segments:
28
30
  - 0
29
31
  version: "0"
@@ -47,6 +49,7 @@ files:
47
49
  - lib/rgviz_rails/adapters/postgresql_adapter.rb
48
50
  - lib/rgviz_rails/adapters/sqlite_adapter.rb
49
51
  - lib/rgviz_rails/init.rb
52
+ - rails/init.rb
50
53
  - spec/blueprints.rb
51
54
  - spec/spec.opts
52
55
  - spec/spec_helper.rb
@@ -69,6 +72,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
72
  requirements:
70
73
  - - ">="
71
74
  - !ruby/object:Gem::Version
75
+ hash: 3
72
76
  segments:
73
77
  - 0
74
78
  version: "0"
@@ -77,6 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
81
  requirements:
78
82
  - - ">="
79
83
  - !ruby/object:Gem::Version
84
+ hash: 3
80
85
  segments:
81
86
  - 0
82
87
  version: "0"