rack-xslview 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/LICENSE +21 -0
- data/README.md +44 -0
- data/Rakefile +62 -0
- data/VERSION +1 -0
- data/lib/output.xhtml10.xsl +32 -0
- data/lib/rack-xslview.rb +68 -0
- data/test/rack-xslview_test.rb +40 -0
- data/test/test_helper.rb +15 -0
- data/test/test_install.rb +2 -0
- metadata +76 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2009 Savonix Corporation
|
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,44 @@
|
|
1
|
+
Rack XSLView README
|
2
|
+
===================
|
3
|
+
|
4
|
+
Summary
|
5
|
+
-------
|
6
|
+
|
7
|
+
A rack middleware for transforming XML with XSL.
|
8
|
+
|
9
|
+
Configuration
|
10
|
+
-------------
|
11
|
+
|
12
|
+
This is how I would like it to work, but its not there yet:
|
13
|
+
|
14
|
+
<pre class="sh_ruby">
|
15
|
+
# Create the xslt object
|
16
|
+
xslt = ::XML::XSLT.new()
|
17
|
+
|
18
|
+
# Set the default XSL
|
19
|
+
xslt.xsl = REXML::Document.new File.open('/path/to/output.xhtml10.xsl')
|
20
|
+
|
21
|
+
# Paths to exclude
|
22
|
+
noxsl = [/^\/raw/, '/s/js/', '/s/css/']
|
23
|
+
|
24
|
+
# NOTE: multiple stylesheets is still in planning
|
25
|
+
xslhash = { "/path/alskjddf" => "test.xsl", /specific\.xml$/ => 'different.xsl' }
|
26
|
+
xslhash.default("/path/to/output.xhtml10.xsl")
|
27
|
+
|
28
|
+
# Use the middleware
|
29
|
+
use Rack::XSLView, :myxsl => default_xsl, :noxsl => noxsl, :xslhash => xslhash
|
30
|
+
|
31
|
+
|
32
|
+
</pre>
|
33
|
+
|
34
|
+
|
35
|
+
Resources
|
36
|
+
---------
|
37
|
+
|
38
|
+
* <http://github.com/docunext/Rack-XSLView>
|
39
|
+
|
40
|
+
|
41
|
+
Thanks
|
42
|
+
------
|
43
|
+
|
44
|
+
The rack-rewrite gem was very helpful in figuring out how to write rack middleware with lots of options.
|
data/Rakefile
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "rack-xslview"
|
8
|
+
gem.summary = %Q{XSL rack middleware.}
|
9
|
+
gem.description = %Q{A rack middleware for transforming XML with XSL.}
|
10
|
+
gem.email = "albert.lash@docunext.com"
|
11
|
+
gem.homepage = "http://www.docunext.com/wiki/Rack-XSLView"
|
12
|
+
gem.authors = ["Albert Lash"]
|
13
|
+
gem.rubyforge_project = ""
|
14
|
+
gem.add_development_dependency "shoulda"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
Jeweler::RubyforgeTasks.new do |rubyforge|
|
19
|
+
rubyforge.doc_task = "rdoc"
|
20
|
+
end
|
21
|
+
rescue LoadError
|
22
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
require 'rake/testtask'
|
27
|
+
Rake::TestTask.new(:test) do |test|
|
28
|
+
test.libs << 'lib' << 'test'
|
29
|
+
test.pattern = 'test/**/*_test.rb'
|
30
|
+
test.verbose = true
|
31
|
+
end
|
32
|
+
|
33
|
+
begin
|
34
|
+
require 'rcov/rcovtask'
|
35
|
+
Rcov::RcovTask.new do |test|
|
36
|
+
test.libs << 'test'
|
37
|
+
test.pattern = 'test/**/*_test.rb'
|
38
|
+
test.verbose = true
|
39
|
+
end
|
40
|
+
rescue LoadError
|
41
|
+
task :rcov do
|
42
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
task :test => :check_dependencies
|
47
|
+
|
48
|
+
task :default => :test
|
49
|
+
|
50
|
+
require 'rake/rdoctask'
|
51
|
+
Rake::RDocTask.new do |rdoc|
|
52
|
+
if File.exist?('VERSION')
|
53
|
+
version = File.read('VERSION')
|
54
|
+
else
|
55
|
+
version = ""
|
56
|
+
end
|
57
|
+
|
58
|
+
rdoc.rdoc_dir = 'rdoc'
|
59
|
+
rdoc.title = "rack-rewrite #{version}"
|
60
|
+
rdoc.rdoc_files.include('README*')
|
61
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
62
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<!--
|
2
|
+
Program: 1bb02b59
|
3
|
+
Component: output.xhtml10.xsl
|
4
|
+
Copyright: Savonix Corporation
|
5
|
+
Author: Albert L. Lash, IV
|
6
|
+
License: Apache License, Version 2.0
|
7
|
+
|
8
|
+
Copyright 2009 Savonix Corporation
|
9
|
+
|
10
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
11
|
+
you may not use this file except in compliance with the License.
|
12
|
+
You may obtain a copy of the License at
|
13
|
+
|
14
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
15
|
+
|
16
|
+
Unless required by applicable law or agreed to in writing, software
|
17
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
18
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19
|
+
See the License for the specific language governing permissions and
|
20
|
+
limitations under the License.
|
21
|
+
-->
|
22
|
+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
23
|
+
xmlns="http://www.w3.org/1999/xhtml">
|
24
|
+
|
25
|
+
<xsl:import href="http://github.com/docunext/1bb02b59/raw/master/standard.html.xsl"/>
|
26
|
+
|
27
|
+
|
28
|
+
<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="no"
|
29
|
+
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
|
30
|
+
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" indent="yes"/>
|
31
|
+
|
32
|
+
</xsl:stylesheet>
|
data/lib/rack-xslview.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'xml/libxml'
|
2
|
+
require 'xml/libxslt'
|
3
|
+
|
4
|
+
|
5
|
+
module Rack
|
6
|
+
class XSLView
|
7
|
+
def initialize(app, options)
|
8
|
+
@my_path_info = String.new
|
9
|
+
@app = app
|
10
|
+
@myhash = {}
|
11
|
+
@options = {:myxsl => nil}.merge(options)
|
12
|
+
if @options[:myxsl] == nil
|
13
|
+
@xslt = ::XML::XSLT.new()
|
14
|
+
@xslt.xsl = File.join(File.dirname(__FILE__), 'output.xhtml10.xsl')
|
15
|
+
else
|
16
|
+
@xslt = @options[:myxsl]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def call(env)
|
21
|
+
if checknoxsl(env)
|
22
|
+
@app.call(env)
|
23
|
+
else
|
24
|
+
unless @options[:passenv] == nil
|
25
|
+
@options[:passenv].each { |envkey|
|
26
|
+
if (mp = env[envkey])
|
27
|
+
@myhash[envkey] = "#{mp}"
|
28
|
+
end
|
29
|
+
}
|
30
|
+
@xslt.parameters = @myhash
|
31
|
+
end
|
32
|
+
status, headers, @response = @app.call(env)
|
33
|
+
[status, headers, self]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
#response.each { |part| response_body += part }
|
37
|
+
def each(&block)
|
38
|
+
mycontent = ""
|
39
|
+
@response.each { |part|
|
40
|
+
mycontent += part
|
41
|
+
}
|
42
|
+
if ((mycontent.include? "<html") || !(mycontent.include? "<"))
|
43
|
+
yield mycontent
|
44
|
+
else
|
45
|
+
@xslt.xml = mycontent
|
46
|
+
yield @xslt.serve
|
47
|
+
end
|
48
|
+
end
|
49
|
+
private
|
50
|
+
def choosesheet(env)
|
51
|
+
@options[:xslhash].each_key { |path|
|
52
|
+
if env["PATH_INFO"].index(path)
|
53
|
+
return @options[:xslhash][path]
|
54
|
+
end
|
55
|
+
}
|
56
|
+
return false
|
57
|
+
end
|
58
|
+
def checknoxsl(env)
|
59
|
+
@options[:noxsl].each { |path|
|
60
|
+
if env["PATH_INFO"].index(path)
|
61
|
+
return true
|
62
|
+
end
|
63
|
+
}
|
64
|
+
return false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RackXslviewTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def call_args(overrides={})
|
6
|
+
{'REQUEST_URI' => '/rlksdjfkj', 'PATH_INFO' => '/notsure', 'RACK_MOUNT_PATH' => '/something'}.merge(overrides)
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.should_not_halt
|
11
|
+
should "not halt the rack chain" do
|
12
|
+
@app.expects(:call).once
|
13
|
+
@rack.call(call_args)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'Given an app' do
|
18
|
+
setup do
|
19
|
+
@app = Class.new { def call(app); true; end }.new
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'Still learning how to write these tests...' do
|
23
|
+
setup {
|
24
|
+
omitpaths = [/^\/raw/, '/s/js/', '/s/css/']
|
25
|
+
passenv = ['PATH_INFO', 'RACK_MOUNT_PATH']
|
26
|
+
@rack = Rack::XSLView.new(@app, :noxsl => omitpaths, :passenv => passenv)
|
27
|
+
}
|
28
|
+
should_not_halt
|
29
|
+
end
|
30
|
+
context 'Trying out the xslhash' do
|
31
|
+
setup {
|
32
|
+
omitpaths = [/^\/raw/, '/s/js/', '/s/css/']
|
33
|
+
xslhash = { "/path/alskjddf" => "test.xsl", /specific\.xml$/ => 'different.xsl' }
|
34
|
+
xslhash.default("/path/to/output.xhtml10.xsl")
|
35
|
+
@rack = Rack::XSLView.new(@app, :noxsl => omitpaths, :xslhash => xslhash)
|
36
|
+
}
|
37
|
+
should_not_halt
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
gem 'shoulda', '~> 2.10.2'
|
4
|
+
require 'shoulda'
|
5
|
+
gem 'mocha', '~> 0.9.7'
|
6
|
+
require 'mocha'
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
9
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
10
|
+
require 'rack-xslview'
|
11
|
+
|
12
|
+
class Test::Unit::TestCase
|
13
|
+
end
|
14
|
+
|
15
|
+
TEST_ROOT = File.dirname(__FILE__)
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-xslview
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Albert Lash
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-26 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: shoulda
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: A rack middleware for transforming XML with XSL.
|
26
|
+
email: albert.lash@docunext.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.md
|
34
|
+
files:
|
35
|
+
- .gitignore
|
36
|
+
- LICENSE
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- VERSION
|
40
|
+
- lib/output.xhtml10.xsl
|
41
|
+
- lib/rack-xslview.rb
|
42
|
+
- test/rack-xslview_test.rb
|
43
|
+
- test/test_helper.rb
|
44
|
+
- test/test_install.rb
|
45
|
+
has_rdoc: true
|
46
|
+
homepage: http://www.docunext.com/wiki/Rack-XSLView
|
47
|
+
licenses: []
|
48
|
+
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options:
|
51
|
+
- --charset=UTF-8
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project: ""
|
69
|
+
rubygems_version: 1.3.5
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: XSL rack middleware.
|
73
|
+
test_files:
|
74
|
+
- test/test_install.rb
|
75
|
+
- test/test_helper.rb
|
76
|
+
- test/rack-xslview_test.rb
|