rack-ssi 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rack-ssi.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 tohosaku
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ # Rack::SSI
2
+
3
+ rack-ssi is a middleware to realize the function of SSI on the rack. (Currently only supports include)
4
+
5
+ have been affected much from rack-esi of qerub.
6
+
7
+ By default, only the target ".shtml"
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'rack-ssi'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rack-ssi
22
+
23
+ ## Usage
24
+
25
+ same as apache
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,74 @@
1
+ require "rack"
2
+
3
+ class Rack::SSI
4
+
5
+ def initialize(app, options={ :max_depth => 5, :ext => ".shtml", :tag => '(<!--#include virtual="(.*)"\s*-->)' } )
6
+ @app = app
7
+ @max_depth = options[:max_depth]
8
+ @ext = options[:ext]
9
+ @tag_regexp = Regexp.new(options[:tag])
10
+ end
11
+
12
+ def call(env)
13
+ process_request(env)
14
+ end
15
+
16
+ private
17
+
18
+ MAX_DEPTH = 5
19
+
20
+ class Error < ::RuntimeError
21
+ end
22
+
23
+ def process_request(env)
24
+ status, headers, enumerable_body = original_response = @app.call(env.dup)
25
+
26
+ return original_response unless headers["Content-Type"].to_s.match(/(ht|x)ml/)
27
+
28
+ return original_response unless @ext == ::File.extname(env['PATH_INFO'])
29
+
30
+ body = join_body(enumerable_body)
31
+
32
+ processed_body = process_include(env, body)
33
+
34
+ processed_headers = headers.merge({
35
+ "Content-Length" => processed_body.size.to_s,
36
+ "Cache-Control" => "private, max-age=0, must-revalidate"
37
+ })
38
+ processed_headers.delete("Expires")
39
+ processed_headers.delete("Last-Modified")
40
+ processed_headers.delete("ETag")
41
+
42
+ [status, processed_headers, [processed_body]]
43
+ end
44
+
45
+ def process_include(env, body, level=0)
46
+ raise(Error, "Too many levels of SSI processing: level #{level} reached. We were about to request: #{env['REQUEST_URI']} // #{env['PATH_INFO']}") if level > (@max_depth || MAX_DEPTH)
47
+
48
+ new_body = body.split("\n").map do |line|
49
+ line.gsub(@tag_regexp) do |w|
50
+ include_env = env.merge({
51
+ "PATH_INFO" => $2 ,
52
+ "QUERY_STRING" => "",
53
+ "REQUEST_METHOD" => "GET",
54
+ "SCRIPT_NAME" => ""
55
+ })
56
+ include_env.delete("HTTP_ACCEPT_ENCODING")
57
+ include_env.delete("REQUEST_PATH")
58
+ include_env.delete("REQUEST_URI")
59
+
60
+ status, headers, enumerable_body = @app.call(include_env.dup)
61
+ inc = process_include(include_env, join_body(enumerable_body), level + 1)
62
+
63
+ inc ? inc : "file not found !!"
64
+ end
65
+ end
66
+ new_body.join("\n")
67
+ end
68
+
69
+ def join_body(enumerable_body)
70
+ parts = []
71
+ enumerable_body.each { |part| parts << part }
72
+ return parts.join("")
73
+ end
74
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ class SSI
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/rack/ssi/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["tohosaku"]
6
+ gem.email = ["ny@cosmichorror.org"]
7
+ gem.description = %q{rack-ssi is a middleware to realize the function of SSI on the rack. (Currently only supports include) }
8
+ gem.summary = %q{rack-ssi is a middleware to realize the function of SSI on the rack. (Currently only supports include) }
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "rack-ssi"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Rack::SSI::VERSION
17
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-ssi
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - tohosaku
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-08-16 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: "rack-ssi is a middleware to realize the function of SSI on the rack. (Currently only supports include) "
22
+ email:
23
+ - ny@cosmichorror.org
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - LICENSE
34
+ - README.md
35
+ - Rakefile
36
+ - lib/rack/ssi.rb
37
+ - lib/rack/ssi/version.rb
38
+ - rack-ssi.gemspec
39
+ homepage: ""
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ hash: 3
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ requirements: []
66
+
67
+ rubyforge_project:
68
+ rubygems_version: 1.8.17
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: rack-ssi is a middleware to realize the function of SSI on the rack. (Currently only supports include)
72
+ test_files: []
73
+