rack-jekyll_dispatch 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +1 -0
- data/lib/rack/jekyll_dispatch.rb +25 -0
- data/lib/rack/jekyll_dispatch/file_handler.rb +44 -0
- data/lib/rack/jekyll_dispatch/version.rb +5 -0
- data/rack-jekyll_dispatch.gemspec +24 -0
- metadata +111 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Simon Reed
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Rack::JekyllDispatch
|
2
|
+
|
3
|
+
Rack middleware that allows Jekyll content to be served from a static directory within your Rack application. Derived from how Rails serves static content from ActionDispatch::Static.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rack-jekyll_dispatch'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rack-jekyll_dispatch
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Within a Rails app.
|
22
|
+
|
23
|
+
config.middleware.insert_before('Rack::Lock', 'Rack::JekyllDispatch')
|
24
|
+
|
25
|
+
The default source for the generated Jekyll files is 'public/jekyll', if you want specify the source then :
|
26
|
+
|
27
|
+
config.middleware.insert_before('Rack::Lock', 'Rack::JekyllDispatch', :source => "#{config.root}/public/zomglolz")
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create new Pull Request
|
36
|
+
|
37
|
+
## TODO
|
38
|
+
|
39
|
+
Add tests!
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Rack
|
2
|
+
autoload :VERSION, 'rack/jekyll_dispatch/version'
|
3
|
+
autoload :FileHandler, 'rack/jekyll_dispatch/file_handler'
|
4
|
+
|
5
|
+
class JekyllDispatch
|
6
|
+
def initialize(app,opts={})
|
7
|
+
@app = app
|
8
|
+
path = (opts[:source].nil?) ? Dir.pwd + "/public/jekyll" : opts[:source]
|
9
|
+
@file_handler = FileHandler.new(path)
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
case env['REQUEST_METHOD']
|
14
|
+
when 'GET', 'HEAD'
|
15
|
+
path = env['PATH_INFO'].chomp('/')
|
16
|
+
if match = @file_handler.match?(path)
|
17
|
+
env["PATH_INFO"] = match
|
18
|
+
return @file_handler.call(env)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
@app.call(env)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Rack
|
2
|
+
class JekyllDispatch
|
3
|
+
class FileHandler
|
4
|
+
def initialize(root)
|
5
|
+
@root = root.chomp('/')
|
6
|
+
@compiled_root = /^#{Regexp.escape(root)}/
|
7
|
+
@file_server = ::Rack::File.new(@root)
|
8
|
+
end
|
9
|
+
|
10
|
+
def match?(path)
|
11
|
+
path = path.dup
|
12
|
+
|
13
|
+
full_path = path.empty? ? @root : ::File.join(@root, escape_glob_chars(unescape_path(path)))
|
14
|
+
paths = "#{full_path}{,.html,/index.html}"
|
15
|
+
|
16
|
+
matches = Dir[paths]
|
17
|
+
match = matches.detect { |m| ::File.file?(m) }
|
18
|
+
if match
|
19
|
+
match.sub!(@compiled_root, '')
|
20
|
+
::Rack::Utils.escape(match)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def call(env)
|
25
|
+
@file_server.call(env)
|
26
|
+
end
|
27
|
+
|
28
|
+
def ext
|
29
|
+
@ext ||= begin
|
30
|
+
"{,.html,/index.html}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def unescape_path(path)
|
35
|
+
URI.parser.unescape(path)
|
36
|
+
end
|
37
|
+
|
38
|
+
def escape_glob_chars(path)
|
39
|
+
path.force_encoding('binary') if path.respond_to? :force_encoding
|
40
|
+
path.gsub(/[*?{}\[\]]/, "\\\\\\&")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rack/jekyll_dispatch/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rack-jekyll_dispatch"
|
8
|
+
spec.version = Rack::JekyllDispatch::VERSION
|
9
|
+
spec.authors = ["Adaptive Lab"]
|
10
|
+
spec.email = ["simonpreed@gmail.com"]
|
11
|
+
spec.description = "Rack middleware to serve Jekyll static content."
|
12
|
+
spec.summary = "Rack Middleware that allows Jekyll content to be served from a static directory within your Rack application. Derived from how Rails serves static content from ActionDispatch::Static."
|
13
|
+
spec.homepage = "https://github.com/adaptivelab/rack-jekyll_dispatch"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rack"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-jekyll_dispatch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Adaptive Lab
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rack
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Rack middleware to serve Jekyll static content.
|
63
|
+
email:
|
64
|
+
- simonpreed@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- lib/rack/jekyll_dispatch.rb
|
75
|
+
- lib/rack/jekyll_dispatch/file_handler.rb
|
76
|
+
- lib/rack/jekyll_dispatch/version.rb
|
77
|
+
- rack-jekyll_dispatch.gemspec
|
78
|
+
homepage: https://github.com/adaptivelab/rack-jekyll_dispatch
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
hash: 687685869237761412
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
hash: 687685869237761412
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 1.8.23
|
106
|
+
signing_key:
|
107
|
+
specification_version: 3
|
108
|
+
summary: Rack Middleware that allows Jekyll content to be served from a static directory
|
109
|
+
within your Rack application. Derived from how Rails serves static content from
|
110
|
+
ActionDispatch::Static.
|
111
|
+
test_files: []
|