jasper-reports-rails 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f77e1a68b815b93791820660adce15ca7933a72e
4
+ data.tar.gz: 921ddd84e6cf3cbd15df0f4492fd7e59cf52ea7b
5
+ SHA512:
6
+ metadata.gz: d615bf30814b44047f144a426ef848beeb9ed2a241f65080dd86c450297c972747fbfae17267ed3fce9e828008fa9086cf629542d013f5824b4d6ceffcecab65
7
+ data.tar.gz: 20a1c6ac76bb4b11c514023b13ba12d0a738fcd93f759c3814cc06194ec8a3deee455d3b6d0b9c909629c462f75e1277c2a909f3383f60d2827717aad0a8f8fa
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea/
11
+ *.iml
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.14.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at duy@dwork.vn. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jasper-reports-rails.gemspec
4
+ gemspec
data/Jarfile ADDED
File without changes
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Le Duc Duy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Jasper::Reports::Rails
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/jasper/reports/rails`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'jasper-reports-rails'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install jasper-reports-rails
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/jasper-reports-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jasper/reports/rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jasper-reports-rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jasper-reports-rails"
8
+ spec.version = JasperReportsRails::VERSION
9
+ spec.authors = ["Le Duc Duy"]
10
+ spec.email = ["duy@dwork.vn"]
11
+
12
+ spec.summary = %q{jasper reports for rails}
13
+ spec.description = %q{jasper reports for rails}
14
+ spec.homepage = "http://dwork.vn"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_dependency "jbundler"
34
+ spec.add_development_dependency "rails", '~> 4.0'
35
+ spec.add_dependency "responders", '~> 2.0'
36
+ spec.requirements << "jar 'net.sf.jasperreports:jasperreports', '6.4.0'"
37
+ end
@@ -0,0 +1,25 @@
1
+ require 'bundler'
2
+ require "rails"
3
+ require "jbundler"
4
+ require "active_support/core_ext"
5
+ require "jasper-reports-rails/jasper_renderer"
6
+
7
+ module JasperReportsRails
8
+ class << self
9
+ attr_accessor :config
10
+ end
11
+
12
+ self.config = {
13
+ :report_params => {},
14
+ :response_options => {},
15
+ :xml_options => {}
16
+ }
17
+
18
+ JasperRenderer.register :pdf, :mime_type => Mime::PDF do |jasper_print, options|
19
+ JasperExportManager.export_report_to_pdf(jasper_print)
20
+ end
21
+
22
+ JasperRenderer.register :xml, :mime_type => Mime::PDF do |jasper_print, options|
23
+ JasperExportManager.export_report_to_xml(jasper_print)
24
+ end
25
+ end
@@ -0,0 +1,83 @@
1
+ require 'action_controller/responder'
2
+ java_import Java::net.sf.jasperreports.engine.JRException
3
+ java_import Java::net.sf.jasperreports.engine.JasperCompileManager
4
+ java_import Java::net.sf.jasperreports.engine.JasperExportManager
5
+ java_import Java::net.sf.jasperreports.engine.JasperFillManager
6
+ java_import Java::net.sf.jasperreports.engine.JasperPrint
7
+ java_import Java::net.sf.jasperreports.engine.JasperReport
8
+ java_import Java::net.sf.jasperreports.engine.data.ListOfArrayDataSource
9
+
10
+ module JasperReportsRails
11
+ class JasperRenderer
12
+ def self.register(file_extension, options = {}, &block)
13
+ renderer = self.new(file_extension, options, &block)
14
+
15
+ if Mime::Type.lookup_by_extension(file_extension).nil?
16
+ Mime::Type.register options[:mime_type], file_extension.to_sym
17
+ end
18
+
19
+ ActionController::Responder.send(:define_method, "to_#{file_extension}") do
20
+ if template_name = self.options[:template]
21
+ else
22
+ template_name = "#{controller.controller_path}/#{controller.action_name}"
23
+ end
24
+ details_options = {:formats => [:jrxml], :handlers => []}
25
+
26
+ jasper_file = controller.lookup_context.find_template(template_name,[],false,[],details_options).identifier
27
+
28
+ params = {}
29
+ controller.instance_variables.each do |v|
30
+ params[v.to_s[1..-1]] = controller.instance_variable_get(v)
31
+ end
32
+
33
+ response_options = JasperReportsRails.config[:response_options].merge(:type => options[:mime_type])
34
+ controller.send_data renderer.render(jasper_file, resource, params, self.options), response_options
35
+ end
36
+ end
37
+
38
+ attr_accessor :file_extension
39
+ attr_accessor :options
40
+ attr_accessor :block
41
+
42
+ def initialize file_extension, options, &block
43
+ self.file_extension = file_extension
44
+ self.options = options
45
+ self.block = block
46
+ end
47
+
48
+
49
+ def render jasper_file, datasource, parameters, controller_options
50
+ begin
51
+ #Compile
52
+ compiled_report = compiled_report = JasperCompileManager.compileReport(jasper_file)
53
+
54
+ #Fill
55
+
56
+ #PARAMETERS
57
+ params = java.util.HashMap.new(parameters)
58
+
59
+ #DATA SOURCE
60
+ case datasource
61
+ when Array
62
+ keys = datasource.first.keys.map(&:to_s).to_java :String
63
+ values = java.util.ArrayList.new(datasource.map(&:values).map(&:to_java))
64
+ ds = ListOfArrayDataSource.new(values, keys)
65
+ jasper_print = JasperFillManager.fillReport(compiled_report, params, ds)
66
+ instance_exec(jasper_print, controller_options, &block)
67
+ else
68
+ raise "Unsupported type #{datasource}"
69
+ end
70
+ rescue Exception=>e
71
+ if e.respond_to? 'printStackTrace'
72
+ ::Rails.logger.error e.message
73
+ e.printStackTrace
74
+ else
75
+ ::Rails.logger.error e.message + "\n " + e.backtrace.join("\n ")
76
+ end
77
+ raise e
78
+ end
79
+ end
80
+
81
+
82
+ end
83
+ end
@@ -0,0 +1,4 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module JasperReportsRails
3
+ VERSION = "1.0.0.pre"
4
+ end
data/lib/test.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'jbundler'
2
+ require 'bundler'
3
+
4
+ java_import Java::net.sf.jasperreports.engine.JRException
5
+ java_import Java::net.sf.jasperreports.engine.JasperCompileManager
6
+ java_import Java::net.sf.jasperreports.engine.JasperExportManager
7
+ java_import Java::net.sf.jasperreports.engine.JasperFillManager
8
+ java_import Java::net.sf.jasperreports.engine.JasperPrint
9
+ java_import Java::net.sf.jasperreports.engine.JasperReport
10
+ java_import Java::net.sf.jasperreports.engine.data.ListOfArrayDataSource
11
+
12
+ compiled_report = JasperCompileManager.compileReport("/Users/duyleekun/JaspersoftWorkspace/MyReports/Blank_A4_Table_Based.jrxml")
13
+ JasperCompileManager.java_method(:compileReport,[java.io.InputStream]).call(StringIO.new("").to_inputstream)
14
+ params = java.util.HashMap.new(:a => 123)
15
+ values = java.util.ArrayList.new([['1','2','3'].to_java])
16
+ keys = ["F","b","c"].to_java :String
17
+ ds = ListOfArrayDataSource.new(values,keys)
18
+ print = JasperFillManager.fillReport(compiled_report, params, ds)
19
+ JasperExportManager.export_report_to_pdf(print)
20
+ # JasperExportManager.java_method(:exportReportToPdfFile, [JasperPrint, java.lang.String]).call(print,"/Users/duyleekun/Downloads/test.pdf")
data/src/Test.java ADDED
@@ -0,0 +1,29 @@
1
+ import net.sf.jasperreports.engine.JRException;
2
+ import net.sf.jasperreports.engine.JasperCompileManager;
3
+ import net.sf.jasperreports.engine.JasperExportManager;
4
+ import net.sf.jasperreports.engine.JasperFillManager;
5
+ import net.sf.jasperreports.engine.JasperPrint;
6
+ import net.sf.jasperreports.engine.JasperReport;
7
+ import net.sf.jasperreports.engine.data.ListOfArrayDataSource;
8
+
9
+ import java.util.HashMap;
10
+ import java.util.LinkedList;
11
+ import java.util.List;
12
+
13
+ class Test {
14
+ public static void main(String[] args) {
15
+ try {
16
+ JasperReport compiledRecord = JasperCompileManager.compileReport("/Users/duyleekun/JaspersoftWorkspace/MyReports/Blank_A4_Table_Based.jrxml");
17
+ HashMap<String, Object> params = new HashMap<>();
18
+ List<Object[]> values = new LinkedList<>();
19
+ values.add(new String[]{"1", "2", "3"});
20
+
21
+ String[] keys = {"F","s","t"};
22
+ JasperPrint print = JasperFillManager.fillReport(compiledRecord,params,new ListOfArrayDataSource(values,keys));
23
+
24
+ JasperExportManager.exportReportToPdfFile(print,"/Users/duyleekun/Downloads/test.pdf");
25
+ } catch (JRException e) {
26
+ e.printStackTrace();
27
+ }
28
+ }
29
+ }
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jasper-reports-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.pre
5
+ platform: ruby
6
+ authors:
7
+ - Le Duc Duy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jbundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: responders
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ description: jasper reports for rails
56
+ email:
57
+ - duy@dwork.vn
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - CODE_OF_CONDUCT.md
65
+ - Gemfile
66
+ - Jarfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - jasper-reports-rails.gemspec
73
+ - lib/jasper-reports-rails.rb
74
+ - lib/jasper-reports-rails/jasper_renderer.rb
75
+ - lib/jasper-reports-rails/version.rb
76
+ - lib/test.rb
77
+ - src/Test.java
78
+ homepage: http://dwork.vn
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">"
94
+ - !ruby/object:Gem::Version
95
+ version: 1.3.1
96
+ requirements:
97
+ - jar 'net.sf.jasperreports:jasperreports', '6.4.0'
98
+ rubyforge_project:
99
+ rubygems_version: 2.5.1
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: jasper reports for rails
103
+ test_files: []