rack-xslview 0.2.2 → 0.2.3

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.
Files changed (4) hide show
  1. data/Rakefile +0 -2
  2. data/VERSION +1 -1
  3. data/lib/rack-xslview.rb +18 -7
  4. metadata +18 -9
data/Rakefile CHANGED
@@ -43,8 +43,6 @@ rescue LoadError
43
43
  end
44
44
  end
45
45
 
46
- task :test => :check_dependencies
47
-
48
46
  task :default => :test
49
47
  task :spec => :test
50
48
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
data/lib/rack-xslview.rb CHANGED
@@ -21,10 +21,10 @@ module Rack
21
21
  def call(env)
22
22
 
23
23
  # No matter what, @app will be called
24
- status, headers, body = original_response = @app.call(env)
25
-
24
+ status, headers, body = @app.call(env)
25
+ original_response = Array[status, headers, body]
26
26
  exluded_status = Array[204, 301, 302, 304]
27
- return original_response if exluded_status.include?(status)
27
+ return original_response if exluded_status.include?(status) || body.nil?
28
28
 
29
29
  return original_response unless headers["Content-Type"].to_s.match(/(ht|x)ml/)
30
30
 
@@ -33,9 +33,12 @@ module Rack
33
33
 
34
34
  # Obtain entire request body, ensuring sure it can be processed
35
35
  myxml = getResponse(body)
36
+
37
+ # One more check for an empty respone
38
+ return original_response if myxml.empty?
36
39
 
37
40
  # Should XSL file be reloaded?
38
- if @options[:reload] == true
41
+ unless @options[:reload] == true
39
42
  @xslt = XML::XSLT.new()
40
43
  @xslt.xsl = REXML::Document.new @options[:xslfile]
41
44
  end
@@ -59,6 +62,12 @@ module Rack
59
62
  # If we've made it this far, we can alter the headers
60
63
  headers.delete('Content-Length')
61
64
  headers['Content-Length'] = newbody[0].length.to_s
65
+
66
+ # Content type override?
67
+ unless @options[:content_type].nil?
68
+ headers["Content-Type"] = @options[:content_type]
69
+ end
70
+
62
71
  [status, headers, newbody]
63
72
 
64
73
  rescue XSLViewError
@@ -73,18 +82,20 @@ module Rack
73
82
  }
74
83
  end
75
84
  def getResponse(body)
76
- raise XSLViewError if body.nil?
77
- newbody = ''
85
+ newbody = []
78
86
  body.each { |part|
79
87
  # Only check the first chunk to ensure 1) its not HTML and 2) its XML
80
88
  checkForXml(part) if newbody.empty?
81
89
  newbody << part.to_s
82
90
  }
83
- return newbody
91
+ return newbody.join('')
84
92
  end
85
93
  def checkForXml(x)
86
94
  # Abort processing if content cannot be processed by libxslt
95
+ #puts "test for xml"
96
+ #puts x[0]
87
97
  raise XSLViewError unless x[0] == '<'
98
+ #puts "end xml test"
88
99
  if @options[:excludehtml] == true
89
100
  raise XSLViewError if x.include? '<html'
90
101
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-xslview
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 3
9
+ version: 0.2.3
5
10
  platform: ruby
6
11
  authors:
7
12
  - Albert Lash
@@ -9,19 +14,21 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-03-20 00:00:00 -04:00
17
+ date: 2010-05-22 00:00:00 -04:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: shoulda
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
23
29
  version: "0"
24
- version:
30
+ type: :development
31
+ version_requirements: *id001
25
32
  description: A rack middleware for transforming XML with XSL.
26
33
  email: albert.lash@docunext.com
27
34
  executables: []
@@ -55,18 +62,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
55
62
  requirements:
56
63
  - - ">="
57
64
  - !ruby/object:Gem::Version
65
+ segments:
66
+ - 0
58
67
  version: "0"
59
- version:
60
68
  required_rubygems_version: !ruby/object:Gem::Requirement
61
69
  requirements:
62
70
  - - ">="
63
71
  - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
64
74
  version: "0"
65
- version:
66
75
  requirements: []
67
76
 
68
77
  rubyforge_project: ""
69
- rubygems_version: 1.3.5
78
+ rubygems_version: 1.3.6
70
79
  signing_key:
71
80
  specification_version: 3
72
81
  summary: XSL rack middleware.