rack-jekyll 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +7 -0
- data/README.markdown +52 -44
- data/Rakefile +42 -0
- data/features/requests.feature +36 -0
- data/features/step_definitions/rack_jekyll_steps.rb +58 -0
- data/features/support/env.rb +9 -0
- data/lib/rack/jekyll.rb +73 -50
- data/lib/rack/jekyll/version.rb +1 -1
- data/rack-jekyll.gemspec +41 -0
- data/test/helper.rb +72 -0
- data/test/source/_config.yml +1 -0
- data/test/source/_posts/2015-10-05-hello-world.md +3 -0
- data/test/source/buenos_dias.md +3 -0
- data/test/source/css/test.css +0 -0
- data/test/source/index.md +3 -0
- data/test/source/js/test.js +0 -0
- data/test/source/js/test.min.js +0 -0
- data/test/test_build.rb +55 -0
- data/test/test_configuration.rb +110 -0
- data/test/test_requests.rb +91 -0
- metadata +86 -43
- data/lib/rack/jekyll/test.rb +0 -43
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 65a9a75b71d00f183b26748662eee97d23ab42cf
|
4
|
+
data.tar.gz: af266d768a47a4fc17050955626480e437e67388
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7be8456d67a62653587ff1282b771abd5899766d0a9a4eb9ff82c467dbb1551a887b7d8baa1c7b31ea0ac387c5088d65857158c226036408651144e3cf116aaf
|
7
|
+
data.tar.gz: b11490d802a8ffc92654dcd6a24fe26f78e7d880364c0df37ba50352c9d116c5ad07972b304897e0ae155fca43b20dd3da82457f3dc46e36d2ef17e838157a42
|
data/Gemfile
ADDED
data/README.markdown
CHANGED
@@ -1,75 +1,86 @@
|
|
1
1
|
Rack-Jekyll
|
2
2
|
===========
|
3
3
|
|
4
|
-
Transform your [Jekyll](
|
4
|
+
Transform your [Jekyll](https://jekyllrb.com/) app
|
5
|
+
into a [Rack](https://github.com/rack/rack) application.
|
5
6
|
|
6
|
-
-
|
7
|
+
- You can run it with rackup, [shotgun](https://github.com/rtomayko/shotgun),
|
8
|
+
[unicorn](http://unicorn.bogomips.org/), and more.
|
9
|
+
- You can run Rack-Jekyll with any modified Jekyll.
|
10
|
+
- You can deploy Rack-Jekyll to Heroku, EC2, Rackspace,
|
11
|
+
dedicated servers, VPS, etc.
|
7
12
|
|
8
|
-
- Can run rack-jekyll with any modified jekyll
|
9
13
|
|
10
|
-
|
14
|
+
## How to use it
|
11
15
|
|
16
|
+
A `config.ru` file is required in order to run with shotgun and rackup.
|
17
|
+
You can even deploy your Jekyll app to [Heroku](https://www.heroku.com/)!
|
12
18
|
|
13
|
-
|
19
|
+
Copy this into `config.ru` in your Jekyll site's root directory:
|
14
20
|
|
15
|
-
|
21
|
+
``` ruby
|
22
|
+
require "rack/jekyll"
|
16
23
|
|
17
|
-
|
24
|
+
run Rack::Jekyll.new
|
25
|
+
```
|
18
26
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
config.ru:
|
23
|
-
|
24
|
-
require "rack/jekyll"
|
25
|
-
|
26
|
-
run Rack::Jekyll.new
|
27
|
+
That's it.
|
27
28
|
|
29
|
+
Heroku provides a read-only filesystem, so you need to generate pages
|
30
|
+
and git-commit them *before* you deploy your Jekyll site to Heroku.
|
28
31
|
|
29
|
-
|
32
|
+
1. `cd` to your Jekyll directory
|
33
|
+
2. add a `config.ru` file (see example above)
|
34
|
+
3. build pages with `jekyll build`
|
35
|
+
4. add `gem "rack-jekyll"` to your `Gemfile`
|
36
|
+
5. `git init && git add .`
|
37
|
+
6. `git commit -m "Initial commit"`
|
38
|
+
7. `heroku create`
|
39
|
+
8. `git push heroku master`
|
30
40
|
|
31
41
|
|
32
|
-
|
42
|
+
## Configuration
|
33
43
|
|
34
|
-
|
44
|
+
Jekyll configuration options can be specified in a `_config.yml` file
|
45
|
+
or as Rack-Jekyll initialization options in `config.ru`.
|
35
46
|
|
36
|
-
|
47
|
+
Example:
|
37
48
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
4) echo "rack-jekyll" > .gems
|
43
|
-
|
44
|
-
5) git init && git add .
|
45
|
-
|
46
|
-
6) git commit -m "first heroku app"
|
47
|
-
|
48
|
-
7) heroku create
|
49
|
-
|
50
|
-
8) git push heroku master
|
49
|
+
``` ruby
|
50
|
+
run Rack::Jekyll.new(:destination => "mysite")
|
51
|
+
```
|
51
52
|
|
53
|
+
This will set a custom destination path, overriding the default (`_site`)
|
54
|
+
and settings from a config file.
|
52
55
|
|
53
|
-
|
56
|
+
See [Jekyll's configuration docs](https://jekyllrb.com/docs/configuration/)
|
57
|
+
for more settings.
|
54
58
|
|
55
|
-
|
59
|
+
Additional Rack-Jekyll initialization options:
|
56
60
|
|
61
|
+
:config - use given config file (default: "_config.yml")
|
62
|
+
:force_build - whether to always generate the site at startup, even
|
63
|
+
when the destination path is not empty (default: false)
|
64
|
+
:auto - whether to watch for changes and rebuild (default: false)
|
57
65
|
|
58
|
-
|
66
|
+
Note that on read-only filesystems a site build will fail,
|
67
|
+
so do not set `:force_build => true` in these cases.
|
59
68
|
|
60
|
-
run Rack::Jekyll.new(:destination => "mysite")
|
61
69
|
|
70
|
+
## 404 page
|
62
71
|
|
63
|
-
|
72
|
+
In your site's root directory you can provide a custom `404.html` file
|
73
|
+
with YAML front matter.
|
64
74
|
|
65
|
-
It now can read the `_config.yml` file for destination path. Read [Jekyll Configuration](http://wiki.github.com/mojombo/jekyll/configuration)
|
66
75
|
|
76
|
+
## Contributing
|
67
77
|
|
68
|
-
|
78
|
+
Contributions are more than just welcome.
|
79
|
+
Fork this repo and create a new branch, then submit a pull request.
|
69
80
|
|
70
|
-
You can create a new file: `404.html` with YAML Front Matter. See my [Heroku Demo 404](http://bry4n.heroku.com/show/me/404/)
|
71
81
|
|
72
82
|
## Contributors
|
83
|
+
|
73
84
|
* adaoraul (Adão Raul)
|
74
85
|
* Nerian (Gonzalo Rodríguez-Baltanás Díaz)
|
75
86
|
* scottwater (Scott Watermasysk)
|
@@ -79,7 +90,4 @@ You can create a new file: `404.html` with YAML Front Matter. See my [Heroku Dem
|
|
79
90
|
* bemurphy (Brendon Murphy)
|
80
91
|
* imajes (James Cox)
|
81
92
|
* mattr- (Matt Rogers)
|
82
|
-
|
83
|
-
## Contribution
|
84
|
-
|
85
|
-
Contributing this is more than just welcome. Fork this and create a new branch then pull request.
|
93
|
+
* stomar (Marcus Stollsteimer)
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rubygems/specification'
|
3
|
+
require 'rubygems/package_task'
|
4
|
+
require 'rake/testtask'
|
5
|
+
#require 'extensions/all'
|
6
|
+
require_relative 'lib/rack/jekyll'
|
7
|
+
|
8
|
+
task :default => :test
|
9
|
+
|
10
|
+
Rake::TestTask.new do |t|
|
11
|
+
t.pattern = 'test/test_*.rb'
|
12
|
+
t.verbose = true
|
13
|
+
t.warning = true
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "Build gem"
|
17
|
+
task :build do
|
18
|
+
sh "gem build rack-jekyll.gemspec"
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "Install gem"
|
22
|
+
task :install => :build do
|
23
|
+
sh "gem install rack-jekyll-#{Rack::Jekyll.version}.gem"
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "Push gem to rubygems.org"
|
27
|
+
task :push do
|
28
|
+
sh "gem push rack-jekyll-#{Rack::Jekyll.version}.gem"
|
29
|
+
end
|
30
|
+
|
31
|
+
desc "Clean up gem"
|
32
|
+
task :clean do
|
33
|
+
sh "rm *.gem"
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Run demo"
|
37
|
+
task :demo do
|
38
|
+
puts " ==> Starting demo: http://localhost:3000/"
|
39
|
+
Dir.chdir("example") do
|
40
|
+
sh "rackup -p 3000"
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
Feature: Rack-Jekyll
|
2
|
+
In order to ensure results are correct
|
3
|
+
As a Jekyll
|
4
|
+
I want to become a Rack application
|
5
|
+
|
6
|
+
Scenario: Request 200 page
|
7
|
+
Given I have entered the path /
|
8
|
+
When I request a page
|
9
|
+
Then the http status should be 200
|
10
|
+
Then the content-type should be text/html
|
11
|
+
And the content-length should be 24
|
12
|
+
And the data should show <p>Rack-Jekyll Test</p>
|
13
|
+
|
14
|
+
Scenario: Request 304 page
|
15
|
+
Given I have entered the path /
|
16
|
+
When I request a page with a date of Last-Modified
|
17
|
+
Then the http status should be 304
|
18
|
+
And there should be no 'Content-Length' header
|
19
|
+
|
20
|
+
Scenario: Request 404 page
|
21
|
+
Given I have entered the path /show/me/404/
|
22
|
+
When I request a page
|
23
|
+
Then the http status should be 404
|
24
|
+
And the content-type should be text/html
|
25
|
+
And the content-length should be 9
|
26
|
+
|
27
|
+
Scenario: Request static pages
|
28
|
+
Given I have entered the path /css/test.css
|
29
|
+
When I request a page
|
30
|
+
Then the http status should be 200
|
31
|
+
Then the content-type should be text/css
|
32
|
+
|
33
|
+
Given I have entered the path /js/test.js
|
34
|
+
When I request a page
|
35
|
+
Then the http status should be 200
|
36
|
+
Then the content-type should be application/javascript
|
@@ -0,0 +1,58 @@
|
|
1
|
+
Before do
|
2
|
+
@old_pwd = Dir.pwd
|
3
|
+
FileUtils.mkdir_p(TEMP_DIR) unless File.exist?(TEMP_DIR)
|
4
|
+
Dir.chdir(TEMP_DIR)
|
5
|
+
|
6
|
+
FileUtils.mkdir_p(SOURCE_DIR) unless File.exist?(SOURCE_DIR)
|
7
|
+
FileUtils.mkdir_p(DEST_DIR) unless File.exist?(DEST_DIR)
|
8
|
+
|
9
|
+
@jekyll = Rack::Jekyll.new(:force_build => true,
|
10
|
+
:source => SOURCE_DIR,
|
11
|
+
:destination => DEST_DIR)
|
12
|
+
end
|
13
|
+
|
14
|
+
After do
|
15
|
+
FileUtils.rm_rf(TEMP_DIR) if File.exist?(TEMP_DIR)
|
16
|
+
Dir.chdir(@old_pwd)
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
Given /^I have entered the path (.*)$/ do |path|
|
21
|
+
@path = path
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
When /^I request a page$/ do
|
26
|
+
@response = get(@path)
|
27
|
+
end
|
28
|
+
|
29
|
+
When /^I request a page with a date of Last-Modified$/ do
|
30
|
+
modify_time = get(@path).headers["Last-Modified"]
|
31
|
+
@response = get(@path, {'HTTP_IF_MODIFIED_SINCE' => modify_time})
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
Then /^the http status should be (.*)$/ do |code|
|
36
|
+
assert_equal(code, @response.status.to_s)
|
37
|
+
end
|
38
|
+
|
39
|
+
Then /^the content\-type should be (.*)$/ do |type|
|
40
|
+
assert_equal(type, @response.headers["Content-Type"])
|
41
|
+
end
|
42
|
+
|
43
|
+
Then /^the content\-length should be (.*)$/ do |length|
|
44
|
+
assert_equal(length, @response.original_headers["Content-Length"])
|
45
|
+
end
|
46
|
+
|
47
|
+
Then /^the data should show (.*)$/ do |body|
|
48
|
+
assert_equal(body.chomp, @response.body.chomp)
|
49
|
+
end
|
50
|
+
|
51
|
+
Then /^there should be no '(.*)' header$/ do |header|
|
52
|
+
refute @response.headers.has_key?(header)
|
53
|
+
end
|
54
|
+
|
55
|
+
def get(path, headers={})
|
56
|
+
req = Rack::MockRequest.new(@jekyll)
|
57
|
+
req.get(path,headers)
|
58
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require "minitest"
|
2
|
+
require "rack/mock"
|
3
|
+
|
4
|
+
require_relative "../../lib/rack/jekyll"
|
5
|
+
|
6
|
+
TEST_DIR = File.expand_path("../../../test", __FILE__)
|
7
|
+
TEMP_DIR = File.join(TEST_DIR, "tmp")
|
8
|
+
SOURCE_DIR = File.join(TEST_DIR, "source")
|
9
|
+
DEST_DIR = File.join(TEMP_DIR, "_site")
|
data/lib/rack/jekyll.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require "rack"
|
2
|
-
require "
|
2
|
+
require "jekyll"
|
3
3
|
require "rack/request"
|
4
4
|
require "rack/response"
|
5
5
|
require File.join(File.dirname(__FILE__), 'jekyll', 'helpers')
|
@@ -8,54 +8,65 @@ require File.join(File.dirname(__FILE__), 'jekyll', 'ext')
|
|
8
8
|
|
9
9
|
module Rack
|
10
10
|
class Jekyll
|
11
|
-
@compiling = false
|
12
11
|
|
13
|
-
|
14
|
-
config_file = '_config.yml'
|
15
|
-
if ::File.exist?(config_file)
|
16
|
-
config = YAML.load_file(config_file)
|
17
|
-
@path = (config['destination'].nil? && "_site") || config['destination']
|
12
|
+
attr_reader :config, :destination
|
18
13
|
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
# Initializes a new Rack::Jekyll site.
|
15
|
+
#
|
16
|
+
# Options:
|
17
|
+
#
|
18
|
+
# +:config+:: use given config file (default: "_config.yml")
|
19
|
+
#
|
20
|
+
# +:force_build+:: whether to always generate the site at startup, even
|
21
|
+
# when the destination path is not empty (default: +false+)
|
22
|
+
#
|
23
|
+
# +:auto+:: whether to watch for changes and rebuild (default: +false+)
|
24
|
+
#
|
25
|
+
# Other options are passed on to Jekyll::Site.
|
26
|
+
def initialize(options = {})
|
27
|
+
overrides = options.dup
|
28
|
+
@compiling = false
|
29
|
+
@force_build = overrides.fetch(:force_build, false)
|
30
|
+
@auto = overrides.fetch(:auto, false)
|
31
|
+
|
32
|
+
overrides.delete(:force_build)
|
33
|
+
overrides.delete(:auto)
|
34
|
+
@config = ::Jekyll.configuration(overrides)
|
35
|
+
|
36
|
+
@destination = @config["destination"]
|
37
|
+
@source = @config["source"]
|
38
|
+
|
39
|
+
load_file_list
|
40
|
+
puts @files.inspect if ENV['RACK_DEBUG']
|
22
41
|
|
23
42
|
@mimes = Rack::Mime::MIME_TYPES.map{|k,v| /#{k.gsub('.','\.')}$/i }
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
if ::Dir[@
|
28
|
-
site
|
29
|
-
@compiling = true
|
30
|
-
else
|
31
|
-
@compiling = false
|
43
|
+
|
44
|
+
@site = ::Jekyll::Site.new(@config)
|
45
|
+
|
46
|
+
if ::Dir[@destination + "/**/*"].empty? || @force_build
|
47
|
+
process("Generating site: #{@source} -> #{@destination}")
|
32
48
|
end
|
33
|
-
|
34
|
-
|
49
|
+
|
50
|
+
if @auto
|
51
|
+
require 'listen'
|
52
|
+
require 'listen/version'
|
35
53
|
require 'pathname'
|
36
|
-
source, destination = options['source'], options['destination']
|
37
|
-
puts "Auto-regenerating enabled: #{source} -> #{destination}"
|
38
54
|
|
39
|
-
|
40
|
-
|
41
|
-
|
55
|
+
puts "Auto-regeneration enabled: #{@source} -> #{@destination}"
|
56
|
+
|
57
|
+
source_abs = ::File.expand_path(@source)
|
58
|
+
dest_abs = ::File.expand_path(@destination)
|
59
|
+
relative_path_to_dest = Pathname.new(dest_abs)
|
60
|
+
.relative_path_from(Pathname.new(source_abs))
|
61
|
+
.to_path
|
62
|
+
ignore_pattern = %r{#{Regexp.escape(relative_path_to_dest)}}
|
42
63
|
|
43
|
-
|
64
|
+
listener = Listen.to(@source, :ignore => ignore_pattern) do |modified, added, removed|
|
44
65
|
t = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
45
|
-
|
46
|
-
|
66
|
+
n = modified.length + added.length + removed.length
|
67
|
+
process("[#{t}] Regenerating: #{n} file(s) changed")
|
47
68
|
end
|
48
|
-
|
49
|
-
dw.start
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def globs(source)
|
54
|
-
Dir.chdir(source) do
|
55
|
-
dirs = Dir['*'].select { |x| Pathname(x).directory? }
|
56
|
-
dirs -= ['_site']
|
57
|
-
dirs = dirs.map { |x| "#{x}/**/*" }
|
58
|
-
dirs += ['*']
|
69
|
+
listener.start unless Listen::VERSION =~ /\A[0-1]\./
|
59
70
|
end
|
60
71
|
end
|
61
72
|
|
@@ -63,8 +74,10 @@ module Rack
|
|
63
74
|
@request = Rack::Request.new(env)
|
64
75
|
@response = Rack::Response.new
|
65
76
|
path_info = @request.path_info
|
66
|
-
|
67
|
-
|
77
|
+
while @compiling
|
78
|
+
sleep 0.1
|
79
|
+
end
|
80
|
+
if @files.inspect.include?(path_info)
|
68
81
|
if path_info =~ /(\/?)$/
|
69
82
|
if @mimes.collect {|regex| path_info =~ regex }.compact.empty?
|
70
83
|
path_info += $1.nil? ? "/index.html" : "index.html"
|
@@ -72,7 +85,7 @@ module Rack
|
|
72
85
|
end
|
73
86
|
mime = mime(path_info)
|
74
87
|
|
75
|
-
file = file_info(@
|
88
|
+
file = file_info(@destination + path_info)
|
76
89
|
body = file[:body]
|
77
90
|
time = file[:time]
|
78
91
|
hdrs = { 'Last-Modified' => time }
|
@@ -80,21 +93,31 @@ module Rack
|
|
80
93
|
if time == @request.env['HTTP_IF_MODIFIED_SINCE']
|
81
94
|
[304, hdrs, []]
|
82
95
|
else
|
83
|
-
hdrs.update({ 'Content-
|
96
|
+
hdrs.update({ 'Content-Length' => body.bytesize.to_s,
|
84
97
|
'Content-Type' => mime, } )
|
85
98
|
[@response.status, hdrs, [body]]
|
86
99
|
end
|
87
100
|
|
88
101
|
else
|
89
|
-
status, body, path_info = ::File.exist?(@
|
102
|
+
status, body, path_info = ::File.exist?(@destination+"/404.html") ? [404,file_info(@destination+"/404.html")[:body],"404.html"] : [404,"Not found","404.html"]
|
90
103
|
mime = mime(path_info)
|
91
|
-
|
92
|
-
|
93
|
-
else
|
94
|
-
@compiling = ::Dir[@path + "/**/*"].empty?
|
95
|
-
[200, {"Content-Type" => "text/plain"}, ["This site is currently generating pages. Please reload this page after a couple of seconds."]]
|
96
|
-
end
|
104
|
+
|
105
|
+
[status, {"Content-Type" => mime, "Content-Length" => body.bytesize.to_s}, [body]]
|
97
106
|
end
|
98
107
|
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
def load_file_list
|
112
|
+
@files = ::Dir[@destination + "/**/*"]
|
113
|
+
end
|
114
|
+
|
115
|
+
def process(message = nil)
|
116
|
+
@compiling = true
|
117
|
+
puts message if message
|
118
|
+
@site.process
|
119
|
+
load_file_list
|
120
|
+
@compiling = false
|
121
|
+
end
|
99
122
|
end
|
100
123
|
end
|
data/lib/rack/jekyll/version.rb
CHANGED
data/rack-jekyll.gemspec
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), "lib", "rack", "jekyll", "version")
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.required_rubygems_version = ">= 1.3.6"
|
7
|
+
|
8
|
+
s.name = "rack-jekyll"
|
9
|
+
s.version = Rack::Jekyll.version
|
10
|
+
|
11
|
+
s.summary = "Transform your Jekyll app into a Rack application."
|
12
|
+
s.description = "Rack-Jekyll transforms your Jekyll app into a Rack application."
|
13
|
+
|
14
|
+
s.authors = ["Bryan Goines", "Adão Raul"]
|
15
|
+
s.email = "adao.raul@gmail.com"
|
16
|
+
s.homepage = "https://github.com/adaoraul/rack-jekyll"
|
17
|
+
|
18
|
+
s.files = %w{
|
19
|
+
README.markdown
|
20
|
+
rack-jekyll.gemspec
|
21
|
+
Gemfile
|
22
|
+
Rakefile
|
23
|
+
LICENSE
|
24
|
+
} +
|
25
|
+
Dir.glob("lib/**/*")
|
26
|
+
s.test_files = Dir.glob("{test,features}/**/*")
|
27
|
+
s.require_paths = ["lib"]
|
28
|
+
|
29
|
+
s.extra_rdoc_files = ["README.markdown"]
|
30
|
+
s.rdoc_options = ['--charset=UTF-8', '--main=README.markdown']
|
31
|
+
|
32
|
+
s.add_dependency "jekyll", ">= 1.3"
|
33
|
+
s.add_dependency "rack", "~> 1.5"
|
34
|
+
s.add_dependency "listen", ">= 1.3"
|
35
|
+
|
36
|
+
s.add_development_dependency "rake"
|
37
|
+
s.add_development_dependency "minitest"
|
38
|
+
|
39
|
+
s.platform = Gem::Platform::RUBY
|
40
|
+
s.rubyforge_project = "rack-jekyll"
|
41
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "stringio"
|
3
|
+
require "time"
|
4
|
+
require "rack/mock"
|
5
|
+
|
6
|
+
require_relative "../lib/rack/jekyll"
|
7
|
+
|
8
|
+
TEST_DIR = File.expand_path("..", __FILE__)
|
9
|
+
|
10
|
+
|
11
|
+
def silence_warnings
|
12
|
+
original_verbose, $VERBOSE = $VERBOSE, nil
|
13
|
+
|
14
|
+
yield
|
15
|
+
ensure
|
16
|
+
$VERBOSE = original_verbose
|
17
|
+
end
|
18
|
+
|
19
|
+
def silence_output
|
20
|
+
original_stderr, original_stdout = $stderr, $stdout
|
21
|
+
$stderr, $stdout = StringIO.new, StringIO.new
|
22
|
+
|
23
|
+
yield
|
24
|
+
ensure
|
25
|
+
$stderr, $stdout = original_stderr, original_stdout
|
26
|
+
end
|
27
|
+
|
28
|
+
def without_processing
|
29
|
+
silence_warnings do
|
30
|
+
Jekyll::Site.class_eval do
|
31
|
+
alias :original_process :process
|
32
|
+
def process; end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
yield
|
37
|
+
ensure
|
38
|
+
silence_warnings do
|
39
|
+
Jekyll::Site.class_eval do
|
40
|
+
alias :process :original_process
|
41
|
+
remove_method :original_process
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def rack_jekyll(options = {})
|
47
|
+
jekyll = nil
|
48
|
+
silence_output do
|
49
|
+
jekyll = Rack::Jekyll.new(options)
|
50
|
+
end
|
51
|
+
|
52
|
+
jekyll
|
53
|
+
end
|
54
|
+
|
55
|
+
def rack_jekyll_without_build(options = {})
|
56
|
+
jekyll = nil
|
57
|
+
without_processing do
|
58
|
+
jekyll = rack_jekyll(options)
|
59
|
+
end
|
60
|
+
|
61
|
+
jekyll
|
62
|
+
end
|
63
|
+
|
64
|
+
def file_must_exist(filename)
|
65
|
+
assert File.exist?(filename),
|
66
|
+
"Expected file `#{filename}' to exist."
|
67
|
+
end
|
68
|
+
|
69
|
+
def file_wont_exist(filename)
|
70
|
+
assert !File.exist?(filename),
|
71
|
+
"Expected file `#{filename}' to not exist."
|
72
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
fake_option: "ok"
|
File without changes
|
File without changes
|
File without changes
|
data/test/test_build.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
3
|
+
|
4
|
+
describe "when initializing a Rack::Jekyll instance" do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@tempdir = File.join(TEST_DIR, "tmp")
|
8
|
+
FileUtils.mkdir_p(@tempdir) unless File.exist?(@tempdir)
|
9
|
+
Dir.chdir(@tempdir)
|
10
|
+
|
11
|
+
@sourcedir = File.join(TEST_DIR, "source")
|
12
|
+
@destdir = File.join(@tempdir, "_site")
|
13
|
+
FileUtils.mkdir_p(@sourcedir) unless File.exist?(@sourcedir)
|
14
|
+
FileUtils.mkdir_p(@destdir) unless File.exist?(@destdir)
|
15
|
+
|
16
|
+
@page = File.join(@destdir, "index.html")
|
17
|
+
@fake_page = File.join(@destdir, "fake.html")
|
18
|
+
end
|
19
|
+
|
20
|
+
after do
|
21
|
+
FileUtils.rm_rf(@tempdir) if File.exist?(@tempdir)
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "when non-empty destination directory exists" do
|
25
|
+
|
26
|
+
before do
|
27
|
+
FileUtils.touch(@fake_page)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should not build the site by default" do
|
31
|
+
file_wont_exist(@page)
|
32
|
+
rack_jekyll(:source => @sourcedir,
|
33
|
+
:destination => @destdir)
|
34
|
+
file_wont_exist(@page)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should build the site when :force_build option is set" do
|
38
|
+
file_wont_exist(@page)
|
39
|
+
rack_jekyll(:force_build => true,
|
40
|
+
:source => @sourcedir,
|
41
|
+
:destination => @destdir)
|
42
|
+
file_must_exist(@page)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "when empty destination directory exists" do
|
47
|
+
|
48
|
+
it "should build the site" do
|
49
|
+
file_wont_exist(@page)
|
50
|
+
rack_jekyll(:source => @sourcedir,
|
51
|
+
:destination => @destdir)
|
52
|
+
file_must_exist(@page)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
3
|
+
|
4
|
+
describe "when configuring site" do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@tempdir = File.join(TEST_DIR, "tmp")
|
8
|
+
FileUtils.mkdir_p(@tempdir) unless File.exist?(@tempdir)
|
9
|
+
Dir.chdir(@tempdir)
|
10
|
+
end
|
11
|
+
|
12
|
+
after do
|
13
|
+
FileUtils.rmdir(@tempdir) if File.exist?(@tempdir)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "when no options are given and no config file exists" do
|
17
|
+
|
18
|
+
it "loads the correct default destination" do
|
19
|
+
jekyll = rack_jekyll_without_build
|
20
|
+
jekyll.destination.must_equal File.join(Dir.pwd, "_site")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "when using default config file" do
|
25
|
+
|
26
|
+
it "loads the configuration from file" do
|
27
|
+
begin
|
28
|
+
File.open("_config.yml", "w") do |f|
|
29
|
+
f.puts "config_file_opt: ok"
|
30
|
+
end
|
31
|
+
|
32
|
+
jekyll = rack_jekyll_without_build
|
33
|
+
jekyll.config.must_include "config_file_opt"
|
34
|
+
jekyll.config["config_file_opt"].must_equal "ok"
|
35
|
+
ensure
|
36
|
+
FileUtils.rm("_config.yml")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "when using custom config file" do
|
42
|
+
|
43
|
+
it "loads the configuration from file" do
|
44
|
+
begin
|
45
|
+
File.open("_my_config.yml", "w") do |f|
|
46
|
+
f.puts "config_file_opt: ok"
|
47
|
+
end
|
48
|
+
|
49
|
+
jekyll = rack_jekyll_without_build(:config => "_my_config.yml")
|
50
|
+
jekyll.config.must_include "config_file_opt"
|
51
|
+
jekyll.config["config_file_opt"].must_equal "ok"
|
52
|
+
ensure
|
53
|
+
FileUtils.rm("_my_config.yml")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "when initialization options are given" do
|
59
|
+
|
60
|
+
it "has the initialization options" do
|
61
|
+
jekyll = rack_jekyll_without_build(:init_opt => "ok")
|
62
|
+
jekyll.config.must_include "init_opt"
|
63
|
+
jekyll.config["init_opt"].must_equal "ok"
|
64
|
+
end
|
65
|
+
|
66
|
+
it "has the correct destination" do
|
67
|
+
jekyll = rack_jekyll_without_build(:destination => "/project/_site")
|
68
|
+
jekyll.destination.must_equal "/project/_site"
|
69
|
+
end
|
70
|
+
|
71
|
+
it ":auto is not passed on to Jekyll" do
|
72
|
+
jekyll = rack_jekyll_without_build(:auto => "ok")
|
73
|
+
jekyll.config.wont_include "auto"
|
74
|
+
end
|
75
|
+
|
76
|
+
it ":force_build is not passed on to Jekyll" do
|
77
|
+
jekyll = rack_jekyll_without_build(:force_build => "ok")
|
78
|
+
jekyll.config.wont_include "force_build"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "when initialization options are given and a config file exists" do
|
83
|
+
|
84
|
+
before do
|
85
|
+
File.open("_config.yml", "w") do |f|
|
86
|
+
f.puts "config_file_opt: ok"
|
87
|
+
f.puts "common_opt: from config"
|
88
|
+
f.puts "destination: /project/_site_from_config"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
after do
|
93
|
+
FileUtils.rm("_config.yml")
|
94
|
+
end
|
95
|
+
|
96
|
+
it "has all options and initialization options override file options" do
|
97
|
+
jekyll = rack_jekyll_without_build(:init_opt => "ok",
|
98
|
+
:common_opt => "from init")
|
99
|
+
jekyll.config.must_include "init_opt"
|
100
|
+
jekyll.config.must_include "config_file_opt"
|
101
|
+
jekyll.config.must_include "common_opt"
|
102
|
+
jekyll.config["common_opt"].must_equal "from init"
|
103
|
+
end
|
104
|
+
|
105
|
+
it "has the correct destination" do
|
106
|
+
jekyll = rack_jekyll_without_build(:destination => "/project/_site_from_init")
|
107
|
+
jekyll.destination.must_equal "/project/_site_from_init"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require_relative "helper"
|
4
|
+
|
5
|
+
|
6
|
+
describe "when handling requests" do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@tempdir = File.join(TEST_DIR, "tmp")
|
10
|
+
FileUtils.mkdir_p(@tempdir) unless File.exist?(@tempdir)
|
11
|
+
Dir.chdir(@tempdir)
|
12
|
+
|
13
|
+
@sourcedir = File.join(TEST_DIR, "source")
|
14
|
+
@destdir = File.join(@tempdir, "_site")
|
15
|
+
FileUtils.mkdir_p(@sourcedir) unless File.exist?(@sourcedir)
|
16
|
+
FileUtils.mkdir_p(@destdir) unless File.exist?(@destdir)
|
17
|
+
|
18
|
+
@jekyll = rack_jekyll(:force_build => true,
|
19
|
+
:source => @sourcedir,
|
20
|
+
:destination => @destdir)
|
21
|
+
@request = Rack::MockRequest.new(@jekyll)
|
22
|
+
end
|
23
|
+
|
24
|
+
after do
|
25
|
+
FileUtils.rm_rf(@tempdir) if File.exist?(@tempdir)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "can be created" do
|
29
|
+
@jekyll.wont_be_nil
|
30
|
+
@request.wont_be_nil
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return correct http status code" do
|
34
|
+
@request.get("/").status.must_equal 200
|
35
|
+
@request.get("/show/me/404").status.must_equal 404
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should return correct http status code for If-Modified-Since" do
|
39
|
+
modify_time = @request.get("/").headers["Last-Modified"]
|
40
|
+
earlier_time = (Time.parse(modify_time) - 3600).httpdate
|
41
|
+
|
42
|
+
@request.get("/", {"HTTP_IF_MODIFIED_SINCE" => modify_time}).status.must_equal 304
|
43
|
+
@request.get("/", {"HTTP_IF_MODIFIED_SINCE" => earlier_time}).status.must_equal 200
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should return correct http status code for If-Modified-Since with 404s" do
|
47
|
+
modify_time = @request.get("/").headers["Last-Modified"]
|
48
|
+
earlier_time = (Time.parse(modify_time) - 3600).httpdate
|
49
|
+
|
50
|
+
@request.get("/show/me/404", {"HTTP_IF_MODIFIED_SINCE" => earlier_time}).status.must_equal 404
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should return correct Content-Type header" do
|
54
|
+
@request.get("/").headers["Content-Type"].must_equal "text/html"
|
55
|
+
@request.get("/css/test.css").headers["Content-Type"].must_equal "text/css"
|
56
|
+
@request.get("/js/test.js").headers["Content-Type"].must_equal "application/javascript"
|
57
|
+
@request.get("/js/test.min.js").headers["Content-Type"].must_equal "application/javascript"
|
58
|
+
@request.get("/show/me/404").headers["Content-Type"].must_equal "text/html"
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should return correct Content-Length header" do
|
62
|
+
@request.get("/").original_headers["Content-Length"].to_i.must_equal 24
|
63
|
+
@request.get("/show/me/404").original_headers["Content-Length"].to_i.must_equal 9
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should return correct Content-Length header for If-Modified-Since" do
|
67
|
+
modify_time = @request.get("/").headers["Last-Modified"]
|
68
|
+
@request.get("/", {"HTTP_IF_MODIFIED_SINCE" => modify_time}).original_headers["Content-Length"].must_be_nil
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should return correct body" do
|
72
|
+
@request.get("/").body.must_equal "<p>Rack-Jekyll Test</p>\n"
|
73
|
+
@request.get("/show/me/404").body.must_equal "Not found"
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
describe "when page contains multibyte characters" do
|
78
|
+
|
79
|
+
before do
|
80
|
+
@response = @request.get("/buenos_dias.html")
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should return correct body" do
|
84
|
+
@response.body.must_equal "<p>¡Buenos días!</p>\n"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should return the bytesize as Content-Length header" do
|
88
|
+
@response.original_headers["Content-Length"].to_i.must_equal 23
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-jekyll
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
5
|
-
prerelease:
|
4
|
+
version: 0.4.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Bryan Goines
|
@@ -10,101 +9,145 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 2015-10-12 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: jekyll
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
|
-
- -
|
18
|
+
- - ">="
|
21
19
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
23
|
-
- - <
|
24
|
-
- !ruby/object:Gem::Version
|
25
|
-
version: '2.0'
|
20
|
+
version: '1.3'
|
26
21
|
type: :runtime
|
27
22
|
prerelease: false
|
28
23
|
version_requirements: !ruby/object:Gem::Requirement
|
29
|
-
none: false
|
30
24
|
requirements:
|
31
|
-
- -
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 0.12.0
|
34
|
-
- - <
|
25
|
+
- - ">="
|
35
26
|
- !ruby/object:Gem::Version
|
36
|
-
version: '
|
27
|
+
version: '1.3'
|
37
28
|
- !ruby/object:Gem::Dependency
|
38
29
|
name: rack
|
39
30
|
requirement: !ruby/object:Gem::Requirement
|
40
|
-
none: false
|
41
31
|
requirements:
|
42
|
-
- - ~>
|
32
|
+
- - "~>"
|
43
33
|
- !ruby/object:Gem::Version
|
44
|
-
version: 1.5
|
34
|
+
version: '1.5'
|
45
35
|
type: :runtime
|
46
36
|
prerelease: false
|
47
37
|
version_requirements: !ruby/object:Gem::Requirement
|
48
|
-
none: false
|
49
38
|
requirements:
|
50
|
-
- - ~>
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.5'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: listen
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.3'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '1.3'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
51
68
|
- !ruby/object:Gem::Version
|
52
|
-
version:
|
69
|
+
version: '0'
|
53
70
|
- !ruby/object:Gem::Dependency
|
54
|
-
name:
|
71
|
+
name: minitest
|
55
72
|
requirement: !ruby/object:Gem::Requirement
|
56
|
-
none: false
|
57
73
|
requirements:
|
58
|
-
- -
|
74
|
+
- - ">="
|
59
75
|
- !ruby/object:Gem::Version
|
60
76
|
version: '0'
|
61
77
|
type: :development
|
62
78
|
prerelease: false
|
63
79
|
version_requirements: !ruby/object:Gem::Requirement
|
64
|
-
none: false
|
65
80
|
requirements:
|
66
|
-
- -
|
81
|
+
- - ">="
|
67
82
|
- !ruby/object:Gem::Version
|
68
83
|
version: '0'
|
69
|
-
description:
|
84
|
+
description: Rack-Jekyll transforms your Jekyll app into a Rack application.
|
70
85
|
email: adao.raul@gmail.com
|
71
86
|
executables: []
|
72
87
|
extensions: []
|
73
88
|
extra_rdoc_files:
|
74
89
|
- README.markdown
|
75
90
|
files:
|
76
|
-
-
|
91
|
+
- Gemfile
|
77
92
|
- LICENSE
|
93
|
+
- README.markdown
|
94
|
+
- Rakefile
|
95
|
+
- features/requests.feature
|
96
|
+
- features/step_definitions/rack_jekyll_steps.rb
|
97
|
+
- features/support/env.rb
|
78
98
|
- lib/rack/jekyll.rb
|
79
|
-
- lib/rack/jekyll/
|
99
|
+
- lib/rack/jekyll/ext.rb
|
80
100
|
- lib/rack/jekyll/helpers.rb
|
81
101
|
- lib/rack/jekyll/version.rb
|
82
|
-
-
|
83
|
-
|
102
|
+
- rack-jekyll.gemspec
|
103
|
+
- test/helper.rb
|
104
|
+
- test/source/_config.yml
|
105
|
+
- test/source/_posts/2015-10-05-hello-world.md
|
106
|
+
- test/source/buenos_dias.md
|
107
|
+
- test/source/css/test.css
|
108
|
+
- test/source/index.md
|
109
|
+
- test/source/js/test.js
|
110
|
+
- test/source/js/test.min.js
|
111
|
+
- test/test_build.rb
|
112
|
+
- test/test_configuration.rb
|
113
|
+
- test/test_requests.rb
|
114
|
+
homepage: https://github.com/adaoraul/rack-jekyll
|
84
115
|
licenses: []
|
116
|
+
metadata: {}
|
85
117
|
post_install_message:
|
86
|
-
rdoc_options:
|
118
|
+
rdoc_options:
|
119
|
+
- "--charset=UTF-8"
|
120
|
+
- "--main=README.markdown"
|
87
121
|
require_paths:
|
88
122
|
- lib
|
89
123
|
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
-
none: false
|
91
124
|
requirements:
|
92
|
-
- -
|
125
|
+
- - ">="
|
93
126
|
- !ruby/object:Gem::Version
|
94
127
|
version: '0'
|
95
|
-
segments:
|
96
|
-
- 0
|
97
|
-
hash: -1218847350686625781
|
98
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
-
none: false
|
100
129
|
requirements:
|
101
|
-
- -
|
130
|
+
- - ">="
|
102
131
|
- !ruby/object:Gem::Version
|
103
132
|
version: 1.3.6
|
104
133
|
requirements: []
|
105
134
|
rubyforge_project: rack-jekyll
|
106
|
-
rubygems_version:
|
135
|
+
rubygems_version: 2.4.5.1
|
107
136
|
signing_key:
|
108
|
-
specification_version:
|
109
|
-
summary:
|
110
|
-
test_files:
|
137
|
+
specification_version: 4
|
138
|
+
summary: Transform your Jekyll app into a Rack application.
|
139
|
+
test_files:
|
140
|
+
- test/helper.rb
|
141
|
+
- test/source/_config.yml
|
142
|
+
- test/source/_posts/2015-10-05-hello-world.md
|
143
|
+
- test/source/buenos_dias.md
|
144
|
+
- test/source/css/test.css
|
145
|
+
- test/source/index.md
|
146
|
+
- test/source/js/test.js
|
147
|
+
- test/source/js/test.min.js
|
148
|
+
- test/test_build.rb
|
149
|
+
- test/test_configuration.rb
|
150
|
+
- test/test_requests.rb
|
151
|
+
- features/requests.feature
|
152
|
+
- features/step_definitions/rack_jekyll_steps.rb
|
153
|
+
- features/support/env.rb
|
data/lib/rack/jekyll/test.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require "rack"
|
2
|
-
require "rack/request"
|
3
|
-
require "rack/response"
|
4
|
-
require File.join(File.dirname(__FILE__), 'ext')
|
5
|
-
|
6
|
-
module Rack
|
7
|
-
class Jekyll
|
8
|
-
class Test
|
9
|
-
def initialize
|
10
|
-
@files = %w{_fake/ _fake/index.html _fake/3/2/1/helloworld/index.html _fake/css/test.css _fake/js/test.js _fake/js/test.min.js}
|
11
|
-
@mimes = Rack::Mime::MIME_TYPES.reject{|k,v|k=~%r{html?}}.map{|k,v|%r{#{k.gsub('.','\.')}$}i}
|
12
|
-
end
|
13
|
-
|
14
|
-
def call(env)
|
15
|
-
request = Request.new(env)
|
16
|
-
path_info = "_fake" + request.path_info
|
17
|
-
if @files.include?(path_info)
|
18
|
-
if path_info =~ /(\/?)$/
|
19
|
-
if @mimes.collect {|regex| path_info =~ regex }.compact.empty?
|
20
|
-
path_info += $1.nil? ? "/index.html" : "index.html"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
mime = mime(path_info)
|
24
|
-
body = "Jekyll/Rack"
|
25
|
-
time = "Thu, 01 Apr 2010 15:27:52 GMT"
|
26
|
-
if time == request.env['HTTP_IF_MODIFIED_SINCE']
|
27
|
-
[304, {'Last-Modified' => time}, []]
|
28
|
-
else
|
29
|
-
[200, {"Content-Type" => mime, "Content-length" => body.bytesize.to_s, "Last-Modified" => "Thu, 01 Apr 2010 15:27:52 GMT"}, [body]]
|
30
|
-
end
|
31
|
-
else
|
32
|
-
status, body, path_info = [404,"Not found","404.html"]
|
33
|
-
mime = mime(path_info)
|
34
|
-
[status, {"Content-Type" => mime, "Content-Type" => body.bytesize.to_s}, [body]]
|
35
|
-
end
|
36
|
-
end
|
37
|
-
def mime(path_info)
|
38
|
-
ext = $1 if path_info =~ /(\.[\S&&[^.]]+)$/
|
39
|
-
Mime.mime_type((ext.nil? ? ".html" : ext))
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|