jasper-bridge 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +41 -0
- data/Rakefile +9 -0
- data/jasper-bridge.gemspec +27 -0
- data/jasper/bin/XmlJasperInterface.class +0 -0
- data/jasper/lib/commons-beanutils-1.8.2.jar +0 -0
- data/jasper/lib/commons-collections-3.2.1.jar +0 -0
- data/jasper/lib/commons-digester-1.7.jar +0 -0
- data/jasper/lib/commons-logging-1.1.jar +0 -0
- data/jasper/lib/iText-2.1.7.jar +0 -0
- data/jasper/lib/jasperreports-3.7.6.jar +0 -0
- data/jasper/lib/nblibraries.properties +2 -0
- data/jasper/lib/xalan.jar +0 -0
- data/lib/generator.rb +33 -0
- data/lib/jasper-bridge.rb +34 -0
- data/lib/jasper-bridge/version.rb +5 -0
- data/test/helper.rb +16 -0
- data/test/test_generate.rb +19 -0
- metadata +64 -0
data/README.rdoc
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
= jasper-bridge
|
2
|
+
|
3
|
+
A bridge from RubyOnRails to Jasper.
|
4
|
+
|
5
|
+
== Requires
|
6
|
+
|
7
|
+
1. Java (JDK) - http://www.oracle.com/technetwork/java/javase/downloads/index.html
|
8
|
+
|
9
|
+
== Install
|
10
|
+
|
11
|
+
In Gemfile:
|
12
|
+
gem 'jasper-bridge'
|
13
|
+
|
14
|
+
Run 'bundle install' or in console 'gem install jasper-bridge'.
|
15
|
+
|
16
|
+
== Use
|
17
|
+
|
18
|
+
1.In controller class:
|
19
|
+
|
20
|
+
require 'jasper-bridge'
|
21
|
+
class ProductsController < ApplicationController
|
22
|
+
include Jasper::Bridge
|
23
|
+
...
|
24
|
+
end
|
25
|
+
|
26
|
+
2.Put jasper file in "#{Rails.root}/reports" directory.
|
27
|
+
|
28
|
+
3.In action of the controller, call method 'send_doc' to response the report. Like the example:
|
29
|
+
|
30
|
+
def index
|
31
|
+
@produtos = Produto.all
|
32
|
+
send_doc(@products.to_xml, '/products/product', 'Products.jasper', "Products", params[:output_type])
|
33
|
+
end
|
34
|
+
|
35
|
+
== Jasper Lib Versions
|
36
|
+
|
37
|
+
The java libs on this gem is from JasperReports 3.7.6. So reports must be compiled in the same version.
|
38
|
+
|
39
|
+
== Copyright
|
40
|
+
Copyright (c) 2011 paulopessoa. See LICENSE.txt for further details.
|
41
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
require "jasper-bridge/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "jasper-bridge"
|
8
|
+
s.version = Jasper::Bridge::VERSION
|
9
|
+
s.authors = ["Paulo Pessoa"]
|
10
|
+
s.email = ["paulopessoa@gmail.com"]
|
11
|
+
s.homepage = "https://github.com/paulopessoa/jasper-bridge"
|
12
|
+
s.summary = %q{Bridge from RoR to Jasper by IO.popen}
|
13
|
+
s.description = %q{Bridge from RoR to Jasper by IO.popen}
|
14
|
+
|
15
|
+
s.rubyforge_project = "jasper-bridge"
|
16
|
+
|
17
|
+
# s.files = `git ls-files`.split("\n")
|
18
|
+
s.files = Dir["{lib/**/*.rb,README.rdoc,test/**/*.rb,Rakefile,*.gemspec,jasper/bin/**,jasper/lib/**}"]
|
19
|
+
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
# s.test_files = Dir["{test/*}"]
|
22
|
+
|
23
|
+
# s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
|
+
# s.executables = ["jb"]
|
25
|
+
|
26
|
+
s.require_paths = ["lib"]
|
27
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/generator.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Jasper
|
2
|
+
|
3
|
+
class Generator
|
4
|
+
include Config
|
5
|
+
|
6
|
+
def self.generate_report(xml_data, report_design, output_type, select_criteria)
|
7
|
+
report_design << '.jasper' if !report_design.match(/\.jasper$/)
|
8
|
+
|
9
|
+
dir = File.expand_path("../../",__FILE__)
|
10
|
+
classpath = "#{dir}/jasper/bin"
|
11
|
+
|
12
|
+
case CONFIG['host']
|
13
|
+
when /mswin32/,/mingw32/
|
14
|
+
Dir.foreach("#{dir}/jasper/lib") do |file|
|
15
|
+
classpath << ";#{dir}/jasper/lib/"+file if (file != '.' and file != '..' and file.match(/\.jar$/))
|
16
|
+
end
|
17
|
+
else
|
18
|
+
Dir.foreach("#{dir}/jasper/lib") do |file|
|
19
|
+
classpath << ":#{dir}/jasper/lib/"+file if (file != '.' and file != '..' and file.match(/\.jar$/))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
pipe = IO.popen "java -cp \"#{classpath}\" XmlJasperInterface -o:#{output_type} -f:reports/#{report_design} -x:#{select_criteria}", "w+b"
|
24
|
+
pipe.write xml_data
|
25
|
+
pipe.close_write
|
26
|
+
result = pipe.read
|
27
|
+
pipe.close
|
28
|
+
result
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "jasper-bridge/version"
|
2
|
+
require "generator"
|
3
|
+
|
4
|
+
module Jasper
|
5
|
+
module Bridge
|
6
|
+
|
7
|
+
protected
|
8
|
+
|
9
|
+
def cache_hack
|
10
|
+
if ENV['HTTP_USER_AGENT'] =~ /msie/i
|
11
|
+
response.headers['Pragma'] = ''
|
12
|
+
response.headers['Cache-Control'] = ''
|
13
|
+
else
|
14
|
+
response.headers['Pragma'] = 'no-cache'
|
15
|
+
response.headers['Cache-Control'] = 'no-cache, must-revalidate'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def send_doc(xml, xml_start_path, report, filename, output_type = 'pdf')
|
20
|
+
mime_type = "application/#{output_type}"
|
21
|
+
|
22
|
+
cache_hack
|
23
|
+
send_data Generator.generate_report(xml, report, output_type, xml_start_path),
|
24
|
+
:filename => "#{filename}.#{output_type}",
|
25
|
+
:type => mime_type,
|
26
|
+
:disposition => 'inline' #'attachment'
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.teste
|
30
|
+
p 'dir=' + File.expand_path("../../",__FILE__)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
13
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
14
|
+
|
15
|
+
class Test::Unit::TestCase
|
16
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'jasper-bridge'
|
4
|
+
|
5
|
+
class TestGenerate < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_generate_report_pdf
|
8
|
+
xml_data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<produtos>\n <produto>\n <cod-produto>1</cod-produto>\n <created-at>2011-09-19T14:34:15Z</created-at>\n <nome>bolacha</nome>\n <updated-at>2011-09-19T14:34:15Z</updated-at>\n </produto>\n <produto>\n <cod-produto>2</cod-produto>\n <created-at>2011-09-19T17:33:55Z</created-at>\n <nome>biscoito</nome>\n <updated-at>2011-09-19T17:33:55Z</updated-at>\n </produto>\n</produtos>\n"
|
9
|
+
result = Jasper::Generator.generate_report(xml_data, 'Produtos.jasper', 'pdf', '/produtos/produto')
|
10
|
+
assert result != nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_generate_report_rtf
|
14
|
+
xml_data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<produtos>\n <produto>\n <cod-produto>1</cod-produto>\n <created-at>2011-09-19T14:34:15Z</created-at>\n <nome>bolacha</nome>\n <updated-at>2011-09-19T14:34:15Z</updated-at>\n </produto>\n <produto>\n <cod-produto>2</cod-produto>\n <created-at>2011-09-19T17:33:55Z</created-at>\n <nome>biscoito</nome>\n <updated-at>2011-09-19T17:33:55Z</updated-at>\n </produto>\n</produtos>\n"
|
15
|
+
result = Jasper::Generator.generate_report(xml_data, 'Produtos.jasper', 'rtf', '/produtos/produto')
|
16
|
+
assert result != nil
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jasper-bridge
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Paulo Pessoa
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-16 00:00:00.000000000 -03:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
description: Bridge from RoR to Jasper by IO.popen
|
16
|
+
email:
|
17
|
+
- paulopessoa@gmail.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- lib/generator.rb
|
23
|
+
- lib/jasper-bridge.rb
|
24
|
+
- lib/jasper-bridge/version.rb
|
25
|
+
- README.rdoc
|
26
|
+
- test/test_generate.rb
|
27
|
+
- test/helper.rb
|
28
|
+
- Rakefile
|
29
|
+
- jasper-bridge.gemspec
|
30
|
+
- jasper/bin/XmlJasperInterface.class
|
31
|
+
- jasper/lib/xalan.jar
|
32
|
+
- jasper/lib/nblibraries.properties
|
33
|
+
- jasper/lib/commons-beanutils-1.8.2.jar
|
34
|
+
- jasper/lib/jasperreports-3.7.6.jar
|
35
|
+
- jasper/lib/iText-2.1.7.jar
|
36
|
+
- jasper/lib/commons-collections-3.2.1.jar
|
37
|
+
- jasper/lib/commons-digester-1.7.jar
|
38
|
+
- jasper/lib/commons-logging-1.1.jar
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: https://github.com/paulopessoa/jasper-bridge
|
41
|
+
licenses: []
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project: jasper-bridge
|
60
|
+
rubygems_version: 1.6.2
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Bridge from RoR to Jasper by IO.popen
|
64
|
+
test_files: []
|