casper_server 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/casper_server.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'rubygems'
1
2
  require 'sinatra'
2
3
  require 'haml'
3
4
  require 'crack'
@@ -5,7 +6,7 @@ require 'casper_reports'
5
6
  require 'base64'
6
7
 
7
8
  class CasperServer < Sinatra::Base
8
- VERSION = '0.0.3'
9
+ VERSION = '0.0.4'
9
10
  FORM = /multipart\/form-data/
10
11
  XML = /application\/xml/
11
12
  JSON = /application\/json/
@@ -24,29 +25,31 @@ class CasperServer < Sinatra::Base
24
25
 
25
26
  def get_input_data
26
27
  if request.content_type =~ FORM
27
- [ params['casper']['jrxml'][:tempfile].read, params['casper']['data'][:tempfile].read, params['casper']['xpath']]
28
+ [ params['casper']['jrxml'][:tempfile].read, params['casper']['data'][:tempfile].read, params['casper']['xpath'], params['casper']['type']]
28
29
  elsif request.content_type =~ XML
29
30
  #parse xml...
30
31
  xml = Crack::XML.parse(request.body.read)
31
- [ decode(xml['casper']['jrxml']), decode(xml['casper']['data']), xml['casper']['xpath']]
32
+ [ decode(xml['casper']['jrxml']), decode(xml['casper']['data']), xml['casper']['xpath'], params['casper']['type']]
32
33
  elsif request.content_type =~ JSON
33
34
  json = Crack::JSON.parse(request.body.read)
34
- [ decode(json['casper']['jrxml']), decode(json['casper']['data']), json['casper']['xpath']]
35
-
35
+ [ decode(json['casper']['jrxml']), decode(json['casper']['data']), json['casper']['xpath'], params['casper']['type']]
36
36
  end
37
37
  end
38
38
  end
39
39
 
40
40
  post '/' do
41
41
 
42
- jrxml, xmldata, xpath = get_input_data
42
+ jrxml, xmldata, xpath, type = get_input_data
43
+ type = 'pdf' unless type
43
44
 
44
45
  casper = CasperReports.new
45
- pdf = casper.compile jrxml, xmldata, xpath
46
+ report = casper.compile jrxml, xmldata, xpath, type
47
+
48
+ content_type "application/pdf" if type.eql?('pdf')
49
+ content_type "application/vnd.ms-excel" if type.eql?('xls')
46
50
 
47
- content_type "application/pdf"
48
- attachment "casper.pdf"
49
- pdf
51
+ attachment "casper.#{type}"
52
+ report
50
53
  end
51
54
 
52
55
  end
data/lib/views/index.haml CHANGED
@@ -16,6 +16,14 @@
16
16
  %p
17
17
  %label Enter Query String:
18
18
  %input{:type => 'text', :name => 'casper[xpath]', :id => 'casper_xpath'}
19
+ %fieldset
20
+ %legend Report type
21
+ %p
22
+ %label Enter Report Type:
23
+ %select{:name => "casper[type]", :id => 'casper_type'}
24
+ %option{:value => 'pdf'} Pdf
25
+ %option{:value => 'xls'} Xls
26
+
19
27
  %fieldset
20
28
  %p
21
29
  %button Generate Report
data/readme.md CHANGED
@@ -80,9 +80,10 @@ On the web page you will be presented with three inputs and a process button.
80
80
  The first input will be requesting the jrxml file
81
81
  The second input will be requesting the xml document
82
82
  The third input will be requesting xpath query string
83
+ The fourth input will be requesting the report type (pdf, xls)
83
84
 
84
- Click Generate Report, and a pdf should stream to your browser.
85
-
86
-
85
+ Click Generate Report, and a pdf/xls should stream to your browser.
87
86
 
87
+ # Contributers
88
88
 
89
+ [https://github.com/twilson63/casper_server/contributors](https://github.com/twilson63/casper_server/contributors)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: casper_server
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.3
5
+ version: 0.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Tom Wilson
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-10 00:00:00 -04:00
13
+ date: 2011-06-10 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -65,7 +65,7 @@ dependencies:
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: "0"
68
+ version: 0.0.2
69
69
  type: :runtime
70
70
  version_requirements: *id005
71
71
  description: The JRuby Reports Server for JasperReports