jasper-rails 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  module JasperRails
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
data/lib/jasper-rails.rb CHANGED
@@ -11,6 +11,10 @@ module JasperRails
11
11
  classpath << File::PATH_SEPARATOR + File.expand_path(jar)
12
12
  end
13
13
 
14
+ Dir["lib/*.jar"].each do |jar|
15
+ classpath << File::PATH_SEPARATOR + File.expand_path(jar)
16
+ end
17
+
14
18
  Rjb::load( classpath, ['-Djava.awt.headless=true','-Xms128M', '-Xmx256M'] )
15
19
 
16
20
  JRException = Rjb::import 'net.sf.jasperreports.engine.JRException'
@@ -21,7 +25,7 @@ module JasperRails
21
25
  JRXmlUtils = Rjb::import 'net.sf.jasperreports.engine.util.JRXmlUtils'
22
26
  JRXPathQueryExecuterFactory = Rjb::import 'net.sf.jasperreports.engine.query.JRXPathQueryExecuterFactory'
23
27
  InputSource = Rjb::import 'org.xml.sax.InputSource'
24
- StringReader = Rjb::import 'java.io.StringReader'
28
+ StringReader = Rjb::import 'java.io.StringReader'
25
29
  HashMap = Rjb::import 'java.util.HashMap'
26
30
  ByteArrayInputStream = Rjb::import 'java.io.ByteArrayInputStream'
27
31
  JavaString = Rjb::import 'java.lang.String'
@@ -33,7 +37,7 @@ module JasperRails
33
37
  options ||= {}
34
38
  parameters ||= {}
35
39
  jrxml_file = jasper_file.sub(/\.jasper$/, ".jrxml")
36
-
40
+
37
41
  begin
38
42
  # Convert the ruby parameters' hash to a java HashMap.
39
43
  # Pay attention that, for now, all parameters are converted to string!
@@ -41,26 +45,26 @@ module JasperRails
41
45
  parameters.each do |k,v|
42
46
  jasper_params.put(JavaString.new(k.to_s), JavaString.new(v.to_s))
43
47
  end
44
-
48
+
45
49
  # Compile it, if needed
46
50
  if !File.exist?(jasper_file) || (File.exist?(jrxml_file) && File.mtime(jrxml_file) > File.mtime(jasper_file))
47
51
  JasperCompileManager.compileReportToFile(jrxml_file, jasper_file)
48
52
  end
49
-
53
+
50
54
  # Fill the report
51
55
  input_source = InputSource.new
52
56
  input_source.setCharacterStream(StringReader.new(datasource.to_xml(options).to_s))
53
57
  data_document = silence_warnings do
54
- # This is here to avoid the "already initialized constant DOCUMENT_POSITION_*" warnings.
55
- # It's harmless. But pretty annoying.
58
+ # This is here to avoid the "already initialized constant DOCUMENT_POSITION_*" warnings.
59
+ # It's harmless. But pretty annoying.
56
60
  JRXmlUtils._invoke('parse', 'Lorg.xml.sax.InputSource;', input_source)
57
61
  end
58
-
62
+
59
63
  jasper_params.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, data_document)
60
64
  jasper_print = JasperFillManager.fillReport(jasper_file, jasper_params)
61
-
65
+
62
66
  # Export it!
63
- JasperExportManager._invoke('exportReportToPdf', 'Lnet.sf.jasperreports.engine.JasperPrint;', jasper_print)
67
+ JasperExportManager._invoke('exportReportToPdf', 'Lnet.sf.jasperreports.engine.JasperPrint;', jasper_print)
64
68
  rescue Exception=>e
65
69
  if e.respond_to? 'printStackTrace'
66
70
  puts e.message
@@ -73,16 +77,16 @@ module JasperRails
73
77
  end
74
78
  end
75
79
  end
76
-
80
+
77
81
  class ActionController::Responder
78
82
  def to_pdf
79
83
  jasper_file = "app/views/#{controller.controller_path}/#{controller.action_name}.jasper"
80
-
84
+
81
85
  params = {}
82
- controller.instance_variables.each do |v|
86
+ controller.instance_variables.each do |v|
83
87
  params[v.to_s[1..-1]] = controller.instance_variable_get(v)
84
88
  end
85
-
89
+
86
90
  controller.send_data Jasper::Rails::render_pdf(jasper_file, resource, params, options), :type => Mime::PDF
87
91
  end
88
92
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jasper-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-05-17 00:00:00.000000000Z
13
+ date: 2012-06-28 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rjb
17
- requirement: &70175555391060 !ruby/object:Gem::Requirement
17
+ requirement: &70228495461760 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,7 +22,7 @@ dependencies:
22
22
  version: 1.4.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70175555391060
25
+ version_requirements: *70228495461760
26
26
  description: Generate pdf reports on Rails using Jasper Reports reporting tool
27
27
  email: rodrigomaia@grupofortes.com.br
28
28
  executables: []
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  version: '0'
66
66
  requirements: []
67
67
  rubyforge_project:
68
- rubygems_version: 1.8.17
68
+ rubygems_version: 1.8.10
69
69
  signing_key:
70
70
  specification_version: 3
71
71
  summary: Rails and JasperReports integration