hashed-jasper-rails 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.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +19 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +57 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/hashed-jasper-rails.gemspec +77 -0
- data/lib/hashed-jasper-rails/jasper-rails.rb +75 -0
- data/lib/hashed-jasper-rails/jasper_source_builder.rb +47 -0
- data/lib/hashed-jasper-rails.rb +4 -0
- data/lib/java/commons-beanutils-1.8.2.jar +0 -0
- data/lib/java/commons-collections-3.2.1.jar +0 -0
- data/lib/java/commons-digester-2.1.jar +0 -0
- data/lib/java/commons-logging-1.1.jar +0 -0
- data/lib/java/groovy-all-1.7.5.jar +0 -0
- data/lib/java/iText-2.1.7.jar +0 -0
- data/lib/java/iTextAsian.jar +0 -0
- data/lib/java/jasperreports-4.5.1.jar +0 -0
- data/lib/java/jcommon-1.0.15.jar +0 -0
- data/lib/java/jfreechart-1.0.12.jar +0 -0
- data/lib/java/xalan.jar +0 -0
- data/spec/fake_app.rb +9 -0
- data/spec/hashed-jasper-rails_spec.rb +90 -0
- data/spec/spec_helper.rb +13 -0
- metadata +131 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.8.0"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler", "~> 1.0.0"
|
12
|
+
gem "jeweler", "~> 1.8.3"
|
13
|
+
end
|
14
|
+
|
15
|
+
gem 'rjb', '>= 1.4.0'
|
16
|
+
|
17
|
+
group :test do
|
18
|
+
gem 'rr', "~> 1.0.0"
|
19
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.8.3)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rdoc
|
11
|
+
json (1.7.3)
|
12
|
+
rake (0.9.2.2)
|
13
|
+
rdoc (3.12)
|
14
|
+
json (~> 1.4)
|
15
|
+
rjb (1.4.0)
|
16
|
+
rr (1.0.4)
|
17
|
+
rspec (2.8.0)
|
18
|
+
rspec-core (~> 2.8.0)
|
19
|
+
rspec-expectations (~> 2.8.0)
|
20
|
+
rspec-mocks (~> 2.8.0)
|
21
|
+
rspec-core (2.8.0)
|
22
|
+
rspec-expectations (2.8.0)
|
23
|
+
diff-lcs (~> 1.1.2)
|
24
|
+
rspec-mocks (2.8.0)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
bundler (~> 1.0.0)
|
31
|
+
jeweler (~> 1.8.3)
|
32
|
+
rdoc (~> 3.12)
|
33
|
+
rjb (>= 1.4.0)
|
34
|
+
rr (~> 1.0.0)
|
35
|
+
rspec (~> 2.8.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Kazuhisa Yamamoto
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
= hashed-jasper-rails
|
2
|
+
|
3
|
+
Hashed-jasper-rails was inspired by jasper-rails.(https://github.com/fortesinformatica/jasper-rails)
|
4
|
+
This can use hash as a data source.
|
5
|
+
|
6
|
+
== How to use
|
7
|
+
|
8
|
+
(1) Add your Gemfile.
|
9
|
+
gem "hashed-jasper-rails"
|
10
|
+
|
11
|
+
(2) Add action method.
|
12
|
+
# app/controllers/users_controller.rb
|
13
|
+
|
14
|
+
def print
|
15
|
+
users = [
|
16
|
+
{:name => "Izumi Konata", :email => "konata@example.com"},
|
17
|
+
{:name => "Hiiragi Tsukasa", :email => "tsukasa@example.com"},
|
18
|
+
{:name => "Hiiragi Kagami", :email => "kagami@example.com"}
|
19
|
+
]
|
20
|
+
jasper_pdf :resource => users
|
21
|
+
end
|
22
|
+
|
23
|
+
(3) Edit a jasper template file.
|
24
|
+
Template propaties.
|
25
|
+
Query Text: /jasper/record
|
26
|
+
The language for the dataset query: xPath
|
27
|
+
|
28
|
+
for Japanese.
|
29
|
+
Text Field propaties.
|
30
|
+
Pdf Font: HeiseiMin-W3 or HeiseiKakuGo-W5
|
31
|
+
Pdf Encoding: UniJIS-UCS2-H (Japanese)
|
32
|
+
|
33
|
+
(4) Set a jasper template file.
|
34
|
+
# app/views/users/print.jaster
|
35
|
+
|
36
|
+
== Options.
|
37
|
+
|
38
|
+
(1) Set a model and record name.
|
39
|
+
jasper_pdf :resource => users, :model => "foo", :record => "baa"
|
40
|
+
|
41
|
+
Then template propaties.
|
42
|
+
Query Text: /foo/baa
|
43
|
+
|
44
|
+
(2) Set a template file.
|
45
|
+
jasper_pdf :resource => users, :template => "list"
|
46
|
+
|
47
|
+
Then use this template file.
|
48
|
+
# app/views/users/list.jaster
|
49
|
+
|
50
|
+
(3) Use ActiveRecord resource.
|
51
|
+
user = User.all
|
52
|
+
jasper_pdf :resource => users
|
53
|
+
|
54
|
+
== Copyright
|
55
|
+
|
56
|
+
Copyright (c) 2012 Kazuhisa Yamamoto. See LICENSE.txt for
|
57
|
+
further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "hashed-jasper-rails"
|
18
|
+
gem.homepage = "http://github.com/kazuhisa/hashed-jasper-rails"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Report tool}
|
21
|
+
gem.description = %Q{Generate pdf reports on Rails using Jasper Reports reporting tool}
|
22
|
+
gem.email = "ak.hisashi@gmail.com"
|
23
|
+
gem.authors = ["Kazuhisa Yamamoto"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "hashed-jasper-rails #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "hashed-jasper-rails"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kazuhisa Yamamoto"]
|
12
|
+
s.date = "2012-05-28"
|
13
|
+
s.description = "Generate pdf reports on Rails using Jasper Reports reporting tool"
|
14
|
+
s.email = "ak.hisashi@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"hashed-jasper-rails.gemspec",
|
29
|
+
"lib/hashed-jasper-rails.rb",
|
30
|
+
"lib/hashed-jasper-rails/jasper-rails.rb",
|
31
|
+
"lib/hashed-jasper-rails/jasper_source_builder.rb",
|
32
|
+
"lib/java/commons-beanutils-1.8.2.jar",
|
33
|
+
"lib/java/commons-collections-3.2.1.jar",
|
34
|
+
"lib/java/commons-digester-2.1.jar",
|
35
|
+
"lib/java/commons-logging-1.1.jar",
|
36
|
+
"lib/java/groovy-all-1.7.5.jar",
|
37
|
+
"lib/java/iText-2.1.7.jar",
|
38
|
+
"lib/java/iTextAsian.jar",
|
39
|
+
"lib/java/jasperreports-4.5.1.jar",
|
40
|
+
"lib/java/jcommon-1.0.15.jar",
|
41
|
+
"lib/java/jfreechart-1.0.12.jar",
|
42
|
+
"lib/java/xalan.jar",
|
43
|
+
"spec/fake_app.rb",
|
44
|
+
"spec/hashed-jasper-rails_spec.rb",
|
45
|
+
"spec/spec_helper.rb"
|
46
|
+
]
|
47
|
+
s.homepage = "http://github.com/kazuhisa/hashed-jasper-rails"
|
48
|
+
s.licenses = ["MIT"]
|
49
|
+
s.require_paths = ["lib"]
|
50
|
+
s.rubygems_version = "1.8.15"
|
51
|
+
s.summary = "Report tool"
|
52
|
+
|
53
|
+
if s.respond_to? :specification_version then
|
54
|
+
s.specification_version = 3
|
55
|
+
|
56
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
57
|
+
s.add_runtime_dependency(%q<rjb>, [">= 1.4.0"])
|
58
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
59
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
60
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
61
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<rjb>, [">= 1.4.0"])
|
64
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
65
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
66
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
67
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
68
|
+
end
|
69
|
+
else
|
70
|
+
s.add_dependency(%q<rjb>, [">= 1.4.0"])
|
71
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
72
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
73
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
74
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# see.
|
2
|
+
# https://github.com/fortesinformatica/jasper-rails
|
3
|
+
|
4
|
+
require "rjb"
|
5
|
+
|
6
|
+
module JasperRails
|
7
|
+
|
8
|
+
classpath = '.'
|
9
|
+
Dir["#{File.dirname(__FILE__)}/../java/*.jar"].each do |jar|
|
10
|
+
classpath << File::PATH_SEPARATOR + File.expand_path(jar)
|
11
|
+
end
|
12
|
+
|
13
|
+
Rjb::load( classpath, ['-Djava.awt.headless=true','-Xms128M', '-Xmx256M'] )
|
14
|
+
|
15
|
+
JRException = Rjb::import 'net.sf.jasperreports.engine.JRException'
|
16
|
+
JasperCompileManager = Rjb::import 'net.sf.jasperreports.engine.JasperCompileManager'
|
17
|
+
JasperExportManager = Rjb::import 'net.sf.jasperreports.engine.JasperExportManager'
|
18
|
+
JasperFillManager = Rjb::import 'net.sf.jasperreports.engine.JasperFillManager'
|
19
|
+
JasperPrint = Rjb::import 'net.sf.jasperreports.engine.JasperPrint'
|
20
|
+
JRXmlUtils = Rjb::import 'net.sf.jasperreports.engine.util.JRXmlUtils'
|
21
|
+
JRXPathQueryExecuterFactory = Rjb::import 'net.sf.jasperreports.engine.query.JRXPathQueryExecuterFactory'
|
22
|
+
InputSource = Rjb::import 'org.xml.sax.InputSource'
|
23
|
+
StringReader = Rjb::import 'java.io.StringReader'
|
24
|
+
HashMap = Rjb::import 'java.util.HashMap'
|
25
|
+
ByteArrayInputStream = Rjb::import 'java.io.ByteArrayInputStream'
|
26
|
+
JavaString = Rjb::import 'java.lang.String'
|
27
|
+
JFreeChart = Rjb::import 'org.jfree.chart.JFreeChart'
|
28
|
+
|
29
|
+
module Jasper
|
30
|
+
module Rails
|
31
|
+
def self.render_pdf(jasper_file, datasource, parameters, options)
|
32
|
+
options ||= {}
|
33
|
+
parameters ||= {}
|
34
|
+
jrxml_file = jasper_file.sub(/\.jasper$/, ".jrxml")
|
35
|
+
|
36
|
+
begin
|
37
|
+
# Convert the ruby parameters' hash to a java HashMap.
|
38
|
+
# Pay attention that, for now, all parameters are converted to string!
|
39
|
+
jasper_params = HashMap.new
|
40
|
+
parameters.each do |k,v|
|
41
|
+
jasper_params.put(JavaString.new(k.to_s), JavaString.new(v.to_s))
|
42
|
+
end
|
43
|
+
|
44
|
+
# Compile it, if needed
|
45
|
+
if !File.exist?(jasper_file) || (File.exist?(jrxml_file) && File.mtime(jrxml_file) > File.mtime(jasper_file))
|
46
|
+
JasperCompileManager.compileReportToFile(jrxml_file, jasper_file)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Fill the report
|
50
|
+
input_source = InputSource.new
|
51
|
+
input_source.setCharacterStream(StringReader.new(datasource.to_xml(options).to_s))
|
52
|
+
data_document = silence_warnings do
|
53
|
+
# This is here to avoid the "already initialized constant DOCUMENT_POSITION_*" warnings.
|
54
|
+
# It's harmless. But pretty annoying.
|
55
|
+
JRXmlUtils._invoke('parse', 'Lorg.xml.sax.InputSource;', input_source)
|
56
|
+
end
|
57
|
+
|
58
|
+
jasper_params.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, data_document)
|
59
|
+
jasper_print = JasperFillManager.fillReport(jasper_file, jasper_params)
|
60
|
+
|
61
|
+
# Export it!
|
62
|
+
JasperExportManager._invoke('exportReportToPdf', 'Lnet.sf.jasperreports.engine.JasperPrint;', jasper_print)
|
63
|
+
rescue Exception=>e
|
64
|
+
if e.respond_to? 'printStackTrace'
|
65
|
+
puts e.message
|
66
|
+
e.printStackTrace
|
67
|
+
else
|
68
|
+
puts e.message
|
69
|
+
puts e.backtrace
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "rexml/document"
|
3
|
+
|
4
|
+
class JasperSourceBuilder
|
5
|
+
def initialize(data_source, model, record)
|
6
|
+
@out_doc = REXML::Document.new()
|
7
|
+
@out_doc.add(REXML::XMLDecl.new(version="1.0", encoding="UTF-8"))
|
8
|
+
elem = REXML::Element.new(model)
|
9
|
+
elem.add_attribute("type","array")
|
10
|
+
|
11
|
+
data_source.each do |data|
|
12
|
+
row = REXML::Element.new(record)
|
13
|
+
data.each_pair do |k,v|
|
14
|
+
cell = REXML::Element.new(k.to_s)
|
15
|
+
cell.add_text(v.to_s)
|
16
|
+
row.add_element(cell)
|
17
|
+
end
|
18
|
+
elem.add_element(row)
|
19
|
+
end
|
20
|
+
@out_doc.add(elem)
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_xml(dummy)
|
24
|
+
@out_doc.to_s
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class ActionController::Base
|
29
|
+
private
|
30
|
+
def jasper_pdf(arg)
|
31
|
+
model_name = arg[:model] || "jasper"
|
32
|
+
record_name = arg[:record] || "record"
|
33
|
+
unless arg[:template].nil?
|
34
|
+
jasper_file = File.join("app/views",arg[:template])
|
35
|
+
jasper_file += ".jasper" unless jasper_file =~ /.jasper$/
|
36
|
+
else
|
37
|
+
jasper_file = File.join("app/views",params[:controller],params[:action]) + ".jasper"
|
38
|
+
end
|
39
|
+
if arg[:resource].size > 0 && arg[:resource][0].kind_of?(Hash)
|
40
|
+
resource = JasperSourceBuilder.new(arg[:resource], model_name, record_name)
|
41
|
+
else
|
42
|
+
resource = arg[:resource]
|
43
|
+
end
|
44
|
+
options = arg[:options] || {}
|
45
|
+
send_data JasperRails::Jasper::Rails.render_pdf(jasper_file, resource, params, options), :type => Mime::PDF
|
46
|
+
end
|
47
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/java/xalan.jar
ADDED
Binary file
|
data/spec/fake_app.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'fake_app')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
+
|
4
|
+
module RR::Adapters::RRMethods
|
5
|
+
def rrsatisfy(&block)
|
6
|
+
RR::WildcardMatchers::Satisfy.new(block)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "JasperSourceBuilder" do
|
11
|
+
before "create jasper source" do
|
12
|
+
record = [
|
13
|
+
{:name => "Izumi Konata", :email => "konata@example.com"},
|
14
|
+
{:name => "Hiiragi Tsukasa", :email => "tsukasa@example.com"},
|
15
|
+
{:name => "Hiiragi Kagami", :email => "kagami@example.com"}
|
16
|
+
]
|
17
|
+
@jasper_source_builder = JasperSourceBuilder.new(record,"jasper","record")
|
18
|
+
end
|
19
|
+
it "create xml" do
|
20
|
+
xml = <<-EOS
|
21
|
+
<?xml version='1.0' encoding='UTF-8'?>
|
22
|
+
<jasper type='array'>
|
23
|
+
<record>
|
24
|
+
<name>Izumi Konata</name>
|
25
|
+
<email>konata@example.com</email>
|
26
|
+
</record>
|
27
|
+
<record>
|
28
|
+
<name>Hiiragi Tsukasa</name>
|
29
|
+
<email>tsukasa@example.com</email>
|
30
|
+
</record>
|
31
|
+
<record>
|
32
|
+
<name>Hiiragi Kagami</name>
|
33
|
+
<email>kagami@example.com</email>
|
34
|
+
</record>
|
35
|
+
</jasper>
|
36
|
+
EOS
|
37
|
+
@jasper_source_builder.to_xml(nil).should == xml.gsub("\n","").gsub(/ +</,"<")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "jasper_pdf method" do
|
42
|
+
before "output pdf" do
|
43
|
+
class Controller < ActionController::Base
|
44
|
+
def output(arg)
|
45
|
+
jasper_pdf(arg)
|
46
|
+
end
|
47
|
+
|
48
|
+
def params
|
49
|
+
{:controller => "people",:action => "index"}
|
50
|
+
end
|
51
|
+
|
52
|
+
def send_data(*arg)
|
53
|
+
# pass
|
54
|
+
end
|
55
|
+
end
|
56
|
+
@controller = Controller.new
|
57
|
+
|
58
|
+
end
|
59
|
+
it "args in resource" do
|
60
|
+
arg = {:resource => [{:name => "Konata", :age => 16}]}
|
61
|
+
mock(JasperRails::Jasper::Rails).render_pdf("app/views/people/index.jasper",
|
62
|
+
rrsatisfy{|arg| arg.to_xml(0) == "<?xml version='1.0' encoding='UTF-8'?><jasper type='array'><record><name>Konata</name><age>16</age></record></jasper>"},
|
63
|
+
{:controller=>"people", :action=>"index"},{}){nil}
|
64
|
+
@controller.output(arg)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "args in resource and model and record" do
|
68
|
+
arg = {:resource => [{:name => "Konata", :age => 16}], :model => "model_name", :record => "record_name"}
|
69
|
+
mock(JasperRails::Jasper::Rails).render_pdf("app/views/people/index.jasper",
|
70
|
+
rrsatisfy{|arg| arg.to_xml(0) == "<?xml version='1.0' encoding='UTF-8'?><model_name type='array'><record_name><name>Konata</name><age>16</age></record_name></model_name>"},
|
71
|
+
{:controller=>"people", :action=>"index"},{}){nil}
|
72
|
+
@controller.output(arg)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "args in resource and template" do
|
76
|
+
arg = {:resource => [{:name => "Konata", :age => 16}],:template => "people/print"}
|
77
|
+
mock(JasperRails::Jasper::Rails).render_pdf("app/views/people/print.jasper",
|
78
|
+
rrsatisfy{|arg| arg.to_xml(0) == "<?xml version='1.0' encoding='UTF-8'?><jasper type='array'><record><name>Konata</name><age>16</age></record></jasper>"},
|
79
|
+
{:controller=>"people", :action=>"index"},{}){nil}
|
80
|
+
@controller.output(arg)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "args in resource and template with extention" do
|
84
|
+
arg = {:resource => [{:name => "Konata", :age => 16}],:template => "people/print.jasper"}
|
85
|
+
mock(JasperRails::Jasper::Rails).render_pdf("app/views/people/print.jasper",
|
86
|
+
rrsatisfy{|arg| arg.to_xml(0) == "<?xml version='1.0' encoding='UTF-8'?><jasper type='array'><record><name>Konata</name><age>16</age></record></jasper>"},
|
87
|
+
{:controller=>"people", :action=>"index"},{}){nil}
|
88
|
+
@controller.output(arg)
|
89
|
+
end
|
90
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'hashed-jasper-rails'
|
5
|
+
require 'rspec'
|
6
|
+
|
7
|
+
# Requires supporting files with custom matchers and macros, etc,
|
8
|
+
# in ./support/ and its subdirectories.
|
9
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.mock_with :rr
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hashed-jasper-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kazuhisa Yamamoto
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-28 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rjb
|
16
|
+
requirement: &70167451417620 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.4.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70167451417620
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70167451415840 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.8.0
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70167451415840
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rdoc
|
38
|
+
requirement: &70167451415120 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '3.12'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70167451415120
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: &70167451414220 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.0
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70167451414220
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: jeweler
|
60
|
+
requirement: &70167451412300 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.8.3
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70167451412300
|
69
|
+
description: Generate pdf reports on Rails using Jasper Reports reporting tool
|
70
|
+
email: ak.hisashi@gmail.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files:
|
74
|
+
- LICENSE.txt
|
75
|
+
- README.rdoc
|
76
|
+
files:
|
77
|
+
- .document
|
78
|
+
- .rspec
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.rdoc
|
83
|
+
- Rakefile
|
84
|
+
- VERSION
|
85
|
+
- hashed-jasper-rails.gemspec
|
86
|
+
- lib/hashed-jasper-rails.rb
|
87
|
+
- lib/hashed-jasper-rails/jasper-rails.rb
|
88
|
+
- lib/hashed-jasper-rails/jasper_source_builder.rb
|
89
|
+
- lib/java/commons-beanutils-1.8.2.jar
|
90
|
+
- lib/java/commons-collections-3.2.1.jar
|
91
|
+
- lib/java/commons-digester-2.1.jar
|
92
|
+
- lib/java/commons-logging-1.1.jar
|
93
|
+
- lib/java/groovy-all-1.7.5.jar
|
94
|
+
- lib/java/iText-2.1.7.jar
|
95
|
+
- lib/java/iTextAsian.jar
|
96
|
+
- lib/java/jasperreports-4.5.1.jar
|
97
|
+
- lib/java/jcommon-1.0.15.jar
|
98
|
+
- lib/java/jfreechart-1.0.12.jar
|
99
|
+
- lib/java/xalan.jar
|
100
|
+
- spec/fake_app.rb
|
101
|
+
- spec/hashed-jasper-rails_spec.rb
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
homepage: http://github.com/kazuhisa/hashed-jasper-rails
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
hash: -2600483218779018077
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 1.8.15
|
128
|
+
signing_key:
|
129
|
+
specification_version: 3
|
130
|
+
summary: Report tool
|
131
|
+
test_files: []
|