torrone 0.1.0
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.
- checksums.yaml +7 -0
- data/CHANGELOG +0 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.rst +42 -0
- data/lib/torrone/compiler.rb +11 -0
- data/lib/torrone/config.rb +26 -0
- data/lib/torrone/exporters/pdf_exporter.rb +0 -0
- data/lib/torrone/jar_loader.rb +13 -0
- data/lib/torrone/json_input_stream.rb +25 -0
- data/lib/torrone/report.rb +52 -0
- data/lib/torrone/version.rb +3 -0
- data/lib/torrone.rb +10 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6222ac1c42a1d255b0686030b7914ae5ddbbeaafb35d0529f507c0dcf99b57a4
|
4
|
+
data.tar.gz: 5327bfa684effdf07b20819787efd8a4bb4a8ec6833b6ba80ce9d289a21f4358
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6bede099b2c68baf591bbe31d297d30e555d49123288a896c274cfcb3875802f5d52a2a7ac686d1a6de116e3b7405110b1d584b9f4d4b59735f72291e5019034
|
7
|
+
data.tar.gz: b8c96b912a1df032cf98ffa06690d791d1c7025605640b826f8ae47957222c29cfd1be4246286d33f6f86acf0e542b064e8633de49f0c547bca663606ac2c79b
|
data/CHANGELOG
ADDED
File without changes
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2019 Jonathan Bruno
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rst
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
Torrone
|
2
|
+
======
|
3
|
+
|
4
|
+
Ruby client to JasperReports API.
|
5
|
+
|
6
|
+
Currently, only does compilation of JRXML files and generation of PDF reports.
|
7
|
+
|
8
|
+
|
9
|
+
Installation
|
10
|
+
------------
|
11
|
+
|
12
|
+
After installing the gem::
|
13
|
+
|
14
|
+
gem install torrone
|
15
|
+
|
16
|
+
Usage
|
17
|
+
-----
|
18
|
+
|
19
|
+
Before doing anything, you should configure Torrone::
|
20
|
+
|
21
|
+
Torrone::Config.configure do |config|
|
22
|
+
config.jasper_dir = "/dir/of/reports"
|
23
|
+
end
|
24
|
+
|
25
|
+
Having a compiled jasper file, you can generate a PDF report::
|
26
|
+
|
27
|
+
Torrone::Report.generate('emails', [
|
28
|
+
{ email: 'foo@bar.com' },
|
29
|
+
{ email: 'foo2@bar.com'},
|
30
|
+
{ email: 'foo3@bar.com'}]
|
31
|
+
)
|
32
|
+
|
33
|
+
it generates a report file called emails.pdf
|
34
|
+
|
35
|
+
Contributing
|
36
|
+
------------
|
37
|
+
|
38
|
+
1. Fork it
|
39
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
40
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
41
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
42
|
+
5. Create new Pull Request
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Torrone
|
2
|
+
class Compiler
|
3
|
+
def self.compile(jrxml_file, output_dir = nil)
|
4
|
+
output_dir ||= File.dirname(jrxml_file)
|
5
|
+
output_file = File.join(output_dir, File.basename(jrxml_file, '.jrxml') + '.jasper')
|
6
|
+
_JasperCompileManager = Rjb::import 'net.sf.jasperreports.engine.JasperCompileManager'
|
7
|
+
_JasperCompileManager.compileReportToFile(jrxml_file, output_file);
|
8
|
+
output_file
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rjb'
|
2
|
+
|
3
|
+
module Torrone
|
4
|
+
class Config
|
5
|
+
class << self
|
6
|
+
attr_reader :jar_dir, :jasper_dir, :image_dir, :locale
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.configure
|
10
|
+
conf = Configuration.new
|
11
|
+
yield conf
|
12
|
+
@jar_dir = conf.jar_dir if conf.jar_dir
|
13
|
+
@jasper_dir = conf.jasper_dir if conf.jasper_dir
|
14
|
+
@image_dir = conf.image_dir if conf.image_dir
|
15
|
+
@locale = conf.locale if conf.locale
|
16
|
+
|
17
|
+
JARLoader.load
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
class Configuration
|
23
|
+
attr_accessor :jar_dir, :jasper_dir, :image_dir, :locale
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
File without changes
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Torrone
|
4
|
+
class JsonInputStream
|
5
|
+
class << self
|
6
|
+
def to_stream(data)
|
7
|
+
_String = Rjb::import 'java.lang.String'
|
8
|
+
_ByteArrayInputStream = Rjb::import 'java.io.ByteArrayInputStream'
|
9
|
+
|
10
|
+
data = normalize_data(data)
|
11
|
+
data = _String.new(data)
|
12
|
+
|
13
|
+
_ByteArrayInputStream.new(data.getBytes())
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def normalize_data(data)
|
19
|
+
return data.to_json if data.kind_of?(Array)
|
20
|
+
return data.to_json if data.kind_of?(Hash)
|
21
|
+
data
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'active_support'
|
3
|
+
require 'active_support/core_ext'
|
4
|
+
|
5
|
+
module Torrone
|
6
|
+
class Report
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def generate(report_name, options = {}, params = {})
|
10
|
+
data = options[:data]
|
11
|
+
_JRParameter = Rjb::import 'net.sf.jasperreports.engine.JRParameter'
|
12
|
+
_JsonQLQueryExecuterFactory = Rjb::import 'net.sf.jasperreports.engine.query.JsonQLQueryExecuterFactory'
|
13
|
+
_JsonQueryExecuterFactory = Rjb::import 'net.sf.jasperreports.engine.query.JsonQueryExecuterFactory'
|
14
|
+
_JasperFillManager = Rjb::import 'net.sf.jasperreports.engine.JasperFillManager'
|
15
|
+
_JasperExportManager = Rjb::import 'net.sf.jasperreports.engine.JasperExportManager'
|
16
|
+
_JasperPrint = Rjb::import 'net.sf.jasperreports.engine.JasperPrint'
|
17
|
+
|
18
|
+
_Locale = Rjb::import 'java.util.Locale'
|
19
|
+
|
20
|
+
_HashMap = Rjb::import 'java.util.HashMap'
|
21
|
+
_StandardCharsets = Rjb::import 'java.nio.charset.StandardCharsets'
|
22
|
+
|
23
|
+
namespace, report_name = extract_namespace(report_name)
|
24
|
+
report_path = File.join(Config.jasper_dir || '.', namespace, report_name)
|
25
|
+
jrxml_file = "#{report_path}.jrxml"
|
26
|
+
|
27
|
+
jasper_file = Compiler.compile(jrxml_file);
|
28
|
+
|
29
|
+
datastream = JsonInputStream.to_stream(data)
|
30
|
+
|
31
|
+
parameters = _HashMap.new;
|
32
|
+
parameters.put(_JsonQueryExecuterFactory.JSON_DATE_PATTERN, "yyyy-MM-dd");
|
33
|
+
parameters.put(_JsonQueryExecuterFactory.JSON_NUMBER_PATTERN, "#,##0.##");
|
34
|
+
parameters.put(_JsonQueryExecuterFactory.JSON_LOCALE, _Locale.ENGLISH);
|
35
|
+
parameters.put(_JRParameter.REPORT_LOCALE, _Locale.US);
|
36
|
+
parameters.put('CNPJ_EMPRESA', '5--353');
|
37
|
+
parameters.put(_JsonQLQueryExecuterFactory.JSON_INPUT_STREAM, datastream)
|
38
|
+
jasperPrint = _JasperFillManager.fillReport(jasper_file, parameters);
|
39
|
+
_JasperExportManager.exportReportToPdfFile(jasperPrint,"reports/users.pdf");
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def extract_namespace(name)
|
45
|
+
parts = name.split('/')
|
46
|
+
jasper_name = parts.pop
|
47
|
+
namespace = parts.join('/')
|
48
|
+
[namespace, jasper_name]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/torrone.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require "torrone/version"
|
2
|
+
require "rjb"
|
3
|
+
|
4
|
+
module Torrone
|
5
|
+
autoload :Compiler, 'torrone/compiler'
|
6
|
+
autoload :Report, 'torrone/report'
|
7
|
+
autoload :JARLoader, 'torrone/jar_loader'
|
8
|
+
autoload :Config, 'torrone/config'
|
9
|
+
autoload :JsonInputStream, 'torrone/json_input_stream'
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: torrone
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonathan Bruno
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-01-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: builder
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.2.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.2.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 5.2.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 5.2.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 12.3.2
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 12.3.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rjb
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.5.8
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.5.8
|
69
|
+
description: Ruby client to JasperReports.
|
70
|
+
email:
|
71
|
+
- jonathanbruno.ueg@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- CHANGELOG
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE
|
79
|
+
- README.rst
|
80
|
+
- lib/torrone.rb
|
81
|
+
- lib/torrone/compiler.rb
|
82
|
+
- lib/torrone/config.rb
|
83
|
+
- lib/torrone/exporters/pdf_exporter.rb
|
84
|
+
- lib/torrone/jar_loader.rb
|
85
|
+
- lib/torrone/json_input_stream.rb
|
86
|
+
- lib/torrone/report.rb
|
87
|
+
- lib/torrone/version.rb
|
88
|
+
homepage: https://github.com/jonathanbruno/torrone
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubygems_version: 3.0.1
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Ruby client to JasperReports API. Currently, only does compilation of JRXML
|
111
|
+
files and generation of PDF reports.
|
112
|
+
test_files: []
|