rasper 0.1.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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rasper.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Rodrigo Manhães
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,73 @@
1
+ Rasper
2
+ ======
3
+
4
+ JRuby 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 rasper
15
+
16
+ You should install `Apache Maven 2 <http://maven.apache.org>`_ in order to
17
+ download the JAR files needed to run JasperReports. This done, run a command
18
+ for generating ``pom.xml``::
19
+
20
+ rasper generate_pom
21
+
22
+ and run Maven to download all dependencies::
23
+
24
+ mvn dependency:copy-dependencies -DoutputDirectory=/dir/for/jars
25
+
26
+ where ``/dir/for/jars`` is the directory in which JARs will be downloaded.
27
+
28
+ For running tests, JAR files should be stored in ``java/jars`` directory.
29
+
30
+
31
+ Usage
32
+ -----
33
+
34
+ To compile a JRXML file, just run::
35
+
36
+ Rasper::Compiler.compile("path-to-jrxml-file", "output-directory")
37
+
38
+ and Rasper will compile JRXML file and generate a ``jasper`` file. The second
39
+ argument is optional and, if provided, should point to directory in which you
40
+ want jasper file be stored. If it is omitted, jasper file is stored at the same
41
+ directory as JRXML file.
42
+
43
+
44
+ Having a compiled jasper file, you can generate a PDF report::
45
+
46
+ Rasper::Report.jasper_dir = "/home/user/jasper/directory"
47
+ Rasper::Report.image_dir = "/home/user/image/directory"
48
+ pdf_content = Rasper::Report.generate('programmers', [
49
+ { name: 'Linus', software: 'Linux' },
50
+ { name: 'Yukihiro', software: 'Ruby' },
51
+ { name: 'Guido', software: 'Python' } ],
52
+ { 'CITY' => 'Campos dos Goytacazes, Rio de Janeiro, Brazil',
53
+ 'DATE' => '02/01/2013' })
54
+
55
+
56
+ In example above, jasper directory and image directory (if there's some)
57
+ should be configured.
58
+
59
+ ``Rasper::Report.generate`` returns an array containing PDF bytes. It takes
60
+ the jasper file name, an array of hashes having the fields and values for the
61
+ report, and an optional third hash argument containing the report parameters.
62
+ All the hash keys should match the fields and parameter names within the JRXML
63
+ report.
64
+
65
+
66
+ Contributing
67
+ ------------
68
+
69
+ 1. Fork it
70
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
71
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
72
+ 4. Push to the branch (`git push origin my-new-feature`)
73
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ namespace :rasper do
2
+ task :pom do
3
+ print "Generating pom.xml..."
4
+ path = File.join(File.expand_path(File.dirname(__FILE__)), 'java', 'pom.xml')
5
+ File.open('./pom.xml', 'w') {|f| f.write(File.read(path)) }
6
+ end
7
+ end
data/bin/rasper ADDED
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ if ARGV[0] == 'generate_pom'
4
+ STDOUT.puts "Generating pom.xml..."
5
+ File.open('./pom.xml', 'w') {|f| f.write('''<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
7
+ <modelVersion>4.0.0</modelVersion>
8
+ <groupId>rasper</groupId>
9
+ <artifactId>rasper-dependencies</artifactId>
10
+ <packaging>jar</packaging>
11
+ <version>0.1.0</version>
12
+ <name>rasper-dependencies</name>
13
+ <url>https://github.com/rodrigomanhaes/rasper</url>
14
+
15
+ <dependencies>
16
+ <dependency>
17
+ <groupId>commons-beanutils</groupId>
18
+ <artifactId>commons-beanutils</artifactId>
19
+ <version>1.8.0</version>
20
+ </dependency>
21
+ <dependency>
22
+ <groupId>commons-digester</groupId>
23
+ <artifactId>commons-digester</artifactId>
24
+ <version>2.0</version>
25
+ </dependency>
26
+ <dependency>
27
+ <groupId>commons-collections</groupId>
28
+ <artifactId>commons-collections</artifactId>
29
+ <version>3.2</version>
30
+ </dependency>
31
+ <dependency>
32
+ <groupId>commons-logging</groupId>
33
+ <artifactId>commons-logging</artifactId>
34
+ <version>1.1.1</version>
35
+ </dependency>
36
+ <dependency>
37
+ <groupId>com.lowagie</groupId>
38
+ <artifactId>itext</artifactId>
39
+ <version>2.1.0</version>
40
+ </dependency>
41
+ <dependency>
42
+ <groupId>jasperreports</groupId>
43
+ <artifactId>jasperreports</artifactId>
44
+ <version>3.5.3</version>
45
+ </dependency>
46
+ <dependency>
47
+ <groupId>xalan</groupId>
48
+ <artifactId>xalan</artifactId>
49
+ <version>2.7.1</version>
50
+ </dependency>
51
+ </dependencies>
52
+
53
+ <build>
54
+ </build>
55
+ </project>
56
+ ''') }
57
+ else
58
+ STDOUT.puts "Usage: rasper generate_pom"
59
+ end
@@ -0,0 +1,15 @@
1
+ require 'java'
2
+
3
+ Rasper::JARLoader.load
4
+
5
+ java_import Java::net::sf::jasperreports::engine::JasperCompileManager
6
+
7
+ module Rasper
8
+ class Compiler
9
+ def self.compile(jrxml_file, output_dir = nil)
10
+ output_dir ||= File.dirname(jrxml_file)
11
+ output_file = File.join(output_dir, File.basename(jrxml_file, '.jrxml') + '.jasper')
12
+ JasperCompileManager.compile_report_to_file(jrxml_file, output_file)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ module Rasper
2
+ class JARLoader
3
+ class << self
4
+ attr_accessor :jar_dir
5
+
6
+ def load
7
+ Dir.entries(jar_dir).each do |lib|
8
+ require File.join(jar_dir, lib) if lib =~ /\.jar$/
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,47 @@
1
+ require 'java'
2
+
3
+ Rasper::JARLoader.load
4
+
5
+ java_import Java::net::sf::jasperreports::engine::data::JRXmlDataSource
6
+ java_import Java::net::sf::jasperreports::engine::util::FileResolver
7
+ java_import Java::net::sf::jasperreports::engine::JasperRunManager
8
+ java_import Java::java::io::ByteArrayInputStream
9
+ java_import Java::java::io::BufferedInputStream
10
+
11
+ require 'active_support/core_ext'
12
+
13
+ module Rasper
14
+ class Report
15
+ class << self
16
+ attr_accessor :jasper_dir, :image_dir
17
+
18
+ def generate(jasper_name, data, params = {})
19
+ set_file_resolver(params)
20
+
21
+ file_name = File.join(jasper_dir || '.', jasper_name + '.jasper')
22
+ jasper_content = File.read(file_name)
23
+ data = { jasper_name => data }.to_xml
24
+ xpath_criteria = "/hash/#{jasper_name}/#{jasper_name.singularize}"
25
+ source = JRXmlDataSource.new(
26
+ ByteArrayInputStream.new(data.to_java_bytes), xpath_criteria)
27
+ input = BufferedInputStream.new(
28
+ ByteArrayInputStream.new(jasper_content.to_java_bytes))
29
+ String.from_java_bytes(
30
+ JasperRunManager.runReportToPdf(input, params, source))
31
+ end
32
+
33
+ private
34
+
35
+ def set_file_resolver(params)
36
+ resolver = FileResolver.new
37
+ image_directory = image_dir
38
+ resolver.singleton_class.instance_eval do
39
+ define_method :resolve_file do |filename|
40
+ java::io::File.new("#{image_directory}/#{filename}")
41
+ end
42
+ end
43
+ params['REPORT_FILE_RESOLVER'] = resolver
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module Rasper
2
+ VERSION = "0.1.1"
3
+ end
data/lib/rasper.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "rasper/version"
2
+
3
+ module Rasper
4
+ autoload :Compiler, 'rasper/compiler'
5
+ autoload :Report, 'rasper/report'
6
+ autoload :JARLoader, 'rasper/jar_loader'
7
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rasper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rodrigo Manhães
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: builder
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: !binary |-
21
+ MA==
22
+ none: false
23
+ requirement: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: !binary |-
28
+ MA==
29
+ none: false
30
+ prerelease: false
31
+ type: :runtime
32
+ - !ruby/object:Gem::Dependency
33
+ name: activesupport
34
+ version_requirements: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: !binary |-
39
+ MA==
40
+ none: false
41
+ requirement: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: !binary |-
46
+ MA==
47
+ none: false
48
+ prerelease: false
49
+ type: :runtime
50
+ - !ruby/object:Gem::Dependency
51
+ name: rake
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: !binary |-
57
+ MA==
58
+ none: false
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: !binary |-
64
+ MA==
65
+ none: false
66
+ prerelease: false
67
+ type: :runtime
68
+ - !ruby/object:Gem::Dependency
69
+ name: rspec
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: !binary |-
75
+ MA==
76
+ none: false
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: !binary |-
82
+ MA==
83
+ none: false
84
+ prerelease: false
85
+ type: :development
86
+ - !ruby/object:Gem::Dependency
87
+ name: docsplit
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: !binary |-
93
+ MA==
94
+ none: false
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: !binary |-
100
+ MA==
101
+ none: false
102
+ prerelease: false
103
+ type: :development
104
+ description: JRuby client to JasperReports API.
105
+ email:
106
+ - rmanhaes@gmail.com
107
+ executables:
108
+ - rasper
109
+ extensions: []
110
+ extra_rdoc_files: []
111
+ files:
112
+ - lib/rasper.rb
113
+ - lib/rasper/compiler.rb
114
+ - lib/rasper/report.rb
115
+ - lib/rasper/version.rb
116
+ - lib/rasper/jar_loader.rb
117
+ - README.rst
118
+ - LICENSE.txt
119
+ - Rakefile
120
+ - Gemfile
121
+ - bin/rasper
122
+ homepage: https://github.com/rodrigomanhaes/rasper
123
+ licenses:
124
+ - MIT
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: !binary |-
134
+ MA==
135
+ none: false
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: !binary |-
141
+ MA==
142
+ none: false
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 1.8.24
146
+ signing_key:
147
+ specification_version: 3
148
+ summary: JRuby client to JasperReports API. Currently, only does compilation of JRXML files and generation of PDF reports.
149
+ test_files: []