rack-jekyll 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -5
- data/example/404.md +10 -0
- data/example/_config.yml +5 -0
- data/example/_layouts/default.html +15 -0
- data/example/_layouts/post.html +7 -0
- data/example/_posts/2009-12-21-hello-world.md +8 -0
- data/example/config.ru +6 -0
- data/example/css/site.css +6 -0
- data/example/index.md +16 -0
- data/lib/rack/jekyll.rb +47 -37
- data/lib/rack/jekyll/filehandler.rb +56 -0
- data/lib/rack/jekyll/utils.rb +21 -0
- data/lib/rack/jekyll/version.rb +1 -1
- data/rack-jekyll.gemspec +6 -3
- data/test/source/dir-with-index/index.md +3 -0
- data/test/source/dir-without-index/page.md +3 -0
- data/test/source/no-extension +1 -0
- data/test/test_filehandler.rb +91 -0
- data/test/test_requests.rb +95 -7
- data/test/test_utils.rb +54 -0
- metadata +24 -5
- data/lib/rack/jekyll/ext.rb +0 -7
- data/lib/rack/jekyll/helpers.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd2b0682778934b95fb214c1ea9513534d4bb9da
|
4
|
+
data.tar.gz: 669fb5b28bd62cff68d1a963c1456e6994aeab21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf6a882bf48cc66254af840440d479cff60f6c9c0170ca46039b909cf31e0605d635f0722d7fc0abfcf7e11e70f7c84913ed2b0eda750f75ca023ffb5cf0742c
|
7
|
+
data.tar.gz: da4666f7f6893f7d407b2643e58f6bff8cf4a9e7fac344a6b7a8d749d1e3cc09939dfbe9fdc1f278925d181291507c3dc818fdcf4591d88b22da095e783babd8
|
data/Rakefile
CHANGED
data/example/404.md
ADDED
data/example/_config.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<link rel="stylesheet" type="text/css" href="/css/site.css">
|
6
|
+
{% if page.title != null %}
|
7
|
+
<title>Rack-Jekyll Demo - {{ page.title }}</title>
|
8
|
+
{% else %}
|
9
|
+
<title>Rack-Jekyll Demo</title>
|
10
|
+
{% endif %}
|
11
|
+
</head>
|
12
|
+
<body>
|
13
|
+
{{ content }}
|
14
|
+
</body>
|
15
|
+
</html>
|
data/example/config.ru
ADDED
data/example/index.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
---
|
2
|
+
layout: default
|
3
|
+
---
|
4
|
+
|
5
|
+
# Rack-Jekyll Demo
|
6
|
+
|
7
|
+
Blog posts:
|
8
|
+
|
9
|
+
<ul>
|
10
|
+
{% for post in site.posts %}
|
11
|
+
<li>
|
12
|
+
<span class="date">{{ post.date | date_to_string }}:</span>
|
13
|
+
<a href="{{ post.url }}">{{ post.title }}</a>
|
14
|
+
</li>
|
15
|
+
{% endfor %}
|
16
|
+
</ul>
|
data/lib/rack/jekyll.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
require "rack"
|
2
2
|
require "jekyll"
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
require File.join(File.dirname(__FILE__), 'jekyll', 'ext')
|
3
|
+
|
4
|
+
require_relative "jekyll/filehandler"
|
5
|
+
require_relative "jekyll/utils"
|
6
|
+
require_relative "jekyll/version"
|
8
7
|
|
9
8
|
module Rack
|
10
9
|
class Jekyll
|
@@ -36,14 +35,10 @@ module Rack
|
|
36
35
|
@destination = @config["destination"]
|
37
36
|
@source = @config["source"]
|
38
37
|
|
39
|
-
|
40
|
-
puts @files.inspect if ENV['RACK_DEBUG']
|
41
|
-
|
42
|
-
@mimes = Rack::Mime::MIME_TYPES.map{|k,v| /#{k.gsub('.','\.')}$/i }
|
43
|
-
|
38
|
+
@files = FileHandler.new(@destination)
|
44
39
|
@site = ::Jekyll::Site.new(@config)
|
45
40
|
|
46
|
-
if
|
41
|
+
if @files.empty? || @force_build
|
47
42
|
process("Generating site: #{@source} -> #{@destination}")
|
48
43
|
end
|
49
44
|
|
@@ -71,53 +66,68 @@ module Rack
|
|
71
66
|
end
|
72
67
|
|
73
68
|
def call(env)
|
74
|
-
@request = Rack::Request.new(env)
|
75
|
-
@response = Rack::Response.new
|
76
|
-
path_info = @request.path_info
|
77
69
|
while @compiling
|
78
70
|
sleep 0.1
|
79
71
|
end
|
80
|
-
if @files.inspect.include?(path_info)
|
81
|
-
if path_info =~ /(\/?)$/
|
82
|
-
if @mimes.collect {|regex| path_info =~ regex }.compact.empty?
|
83
|
-
path_info += $1.nil? ? "/index.html" : "index.html"
|
84
|
-
end
|
85
|
-
end
|
86
|
-
mime = mime(path_info)
|
87
72
|
|
88
|
-
|
73
|
+
request = Rack::Request.new(env)
|
74
|
+
|
75
|
+
filename = @files.get_filename(request.path_info)
|
76
|
+
|
77
|
+
if filename
|
78
|
+
media_type = Utils.media_type(filename)
|
79
|
+
|
80
|
+
file = Utils.file_info(filename)
|
89
81
|
body = file[:body]
|
90
82
|
time = file[:time]
|
91
|
-
hdrs = {
|
83
|
+
hdrs = { "Last-Modified" => time }
|
92
84
|
|
93
|
-
if time ==
|
94
|
-
[304, hdrs, []]
|
85
|
+
if time == request.env["HTTP_IF_MODIFIED_SINCE"]
|
86
|
+
response = [304, hdrs, []]
|
95
87
|
else
|
96
|
-
hdrs.update({
|
97
|
-
|
98
|
-
[
|
88
|
+
hdrs.update({ "Content-Length" => body.bytesize.to_s,
|
89
|
+
"Content-Type" => media_type })
|
90
|
+
response = [200, hdrs, [body]]
|
99
91
|
end
|
100
92
|
|
101
93
|
else
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
94
|
+
body = not_found_message
|
95
|
+
hdrs = { "Content-Length" => body.bytesize.to_s,
|
96
|
+
"Content-Type" => "text/html" }
|
97
|
+
response = [404, hdrs, [body]]
|
106
98
|
end
|
99
|
+
|
100
|
+
request.head? ? remove_body(response) : response
|
107
101
|
end
|
108
102
|
|
109
103
|
private
|
110
104
|
|
111
|
-
def load_file_list
|
112
|
-
@files = ::Dir[@destination + "/**/*"]
|
113
|
-
end
|
114
|
-
|
115
105
|
def process(message = nil)
|
116
106
|
@compiling = true
|
117
107
|
puts message if message
|
118
108
|
@site.process
|
119
|
-
|
109
|
+
@files.update
|
120
110
|
@compiling = false
|
121
111
|
end
|
112
|
+
|
113
|
+
def not_found_message
|
114
|
+
custom_404 || default_404
|
115
|
+
end
|
116
|
+
|
117
|
+
def default_404
|
118
|
+
"Not found"
|
119
|
+
end
|
120
|
+
|
121
|
+
def custom_404
|
122
|
+
filename = @files.get_filename("/404.html")
|
123
|
+
|
124
|
+
filename ? Utils.file_info(filename)[:body] : nil
|
125
|
+
end
|
126
|
+
|
127
|
+
def remove_body(response)
|
128
|
+
status, headers, _body = response
|
129
|
+
|
130
|
+
[status, headers, []]
|
131
|
+
end
|
122
132
|
end
|
123
133
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Rack
|
2
|
+
class Jekyll
|
3
|
+
class FileHandler
|
4
|
+
|
5
|
+
attr_reader :root, :files
|
6
|
+
|
7
|
+
# Initializes a FileHandler for a given root directory
|
8
|
+
# (for testing only: use a given array of filenames, +files+).
|
9
|
+
def initialize(root, files = nil)
|
10
|
+
@root = ::File.expand_path(root)
|
11
|
+
@files = files || get_file_list
|
12
|
+
end
|
13
|
+
|
14
|
+
def empty?
|
15
|
+
@files.empty?
|
16
|
+
end
|
17
|
+
|
18
|
+
def update
|
19
|
+
@files = get_file_list
|
20
|
+
end
|
21
|
+
|
22
|
+
# Returns the full file system path of the file corresponding to
|
23
|
+
# the given URL path, or +nil+ if no corresponding file exists.
|
24
|
+
def get_filename(path)
|
25
|
+
fullpath = ::File.join(@root, path)
|
26
|
+
|
27
|
+
if fullpath.end_with?("/")
|
28
|
+
normalized = fullpath + "index.html"
|
29
|
+
elsif !@files.include?(fullpath)
|
30
|
+
normalized = fullpath + "/index.html"
|
31
|
+
else
|
32
|
+
normalized = fullpath
|
33
|
+
end
|
34
|
+
|
35
|
+
if @files.include?(normalized)
|
36
|
+
filename = normalized
|
37
|
+
else
|
38
|
+
filename = nil
|
39
|
+
end
|
40
|
+
|
41
|
+
filename
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
# Retrieves and returns a list of all files in the root directory
|
47
|
+
# (excluding directory names).
|
48
|
+
def get_file_list
|
49
|
+
files = ::Dir[@root + "/**/*"]
|
50
|
+
files.delete_if {|file| ::FileTest.directory?(file) }
|
51
|
+
|
52
|
+
files
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Rack
|
2
|
+
class Jekyll
|
3
|
+
module Utils
|
4
|
+
|
5
|
+
def self.media_type(filename)
|
6
|
+
extension = ::File.extname(filename)
|
7
|
+
|
8
|
+
Rack::Mime.mime_type(extension)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.file_info(path)
|
12
|
+
info = {
|
13
|
+
:body => ::File.read(path),
|
14
|
+
:time => ::File.mtime(path).httpdate
|
15
|
+
}
|
16
|
+
|
17
|
+
info
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/rack/jekyll/version.rb
CHANGED
data/rack-jekyll.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
require_relative "lib/rack/jekyll/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.required_rubygems_version = ">= 1.3.6"
|
@@ -22,13 +22,16 @@ Gem::Specification.new do |s|
|
|
22
22
|
Rakefile
|
23
23
|
LICENSE
|
24
24
|
} +
|
25
|
-
Dir.glob("lib/**/*")
|
25
|
+
Dir.glob("lib/**/*") +
|
26
|
+
Dir.glob("example/**/*").reject {|f| f =~ %r(\Aexample/_site/) }
|
26
27
|
s.test_files = Dir.glob("{test,features}/**/*")
|
27
28
|
s.require_paths = ["lib"]
|
28
29
|
|
29
|
-
s.extra_rdoc_files = [
|
30
|
+
s.extra_rdoc_files = %w[README.markdown LICENSE]
|
30
31
|
s.rdoc_options = ['--charset=UTF-8', '--main=README.markdown']
|
31
32
|
|
33
|
+
s.required_ruby_version = '>= 1.9.3'
|
34
|
+
|
32
35
|
s.add_dependency "jekyll", ">= 1.3"
|
33
36
|
s.add_dependency "rack", "~> 1.5"
|
34
37
|
s.add_dependency "listen", ">= 1.3"
|
@@ -0,0 +1 @@
|
|
1
|
+
Test
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
3
|
+
|
4
|
+
describe Rack::Jekyll::FileHandler do
|
5
|
+
|
6
|
+
describe "when asked for filenames with #get_filename" do
|
7
|
+
|
8
|
+
before do
|
9
|
+
files = [
|
10
|
+
"/site/index.html",
|
11
|
+
"/site/page.html",
|
12
|
+
"/site/README",
|
13
|
+
"/site/dir-with-index/index.html",
|
14
|
+
"/site/dir-without-index/page.html",
|
15
|
+
"/site/dir1/dir2/dir3/index.html"
|
16
|
+
]
|
17
|
+
@filehandler = Rack::Jekyll::FileHandler.new("/site", files)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return path for '/'" do
|
21
|
+
@filehandler.get_filename("/").must_equal "/site/index.html"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return existing path" do
|
25
|
+
@filehandler.get_filename("/page.html").must_equal "/site/page.html"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return nil for non-existent path" do
|
29
|
+
@filehandler.get_filename("/not-a-page.html").must_be_nil
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return existing path for resource without extension" do
|
33
|
+
@filehandler.get_filename("/README").must_equal "/site/README"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return nil for partially matching paths" do
|
37
|
+
@filehandler.get_filename("/dir1/dir2/").must_be_nil
|
38
|
+
@filehandler.get_filename("/dir2/dir3").must_be_nil
|
39
|
+
@filehandler.get_filename("ir1/di").must_be_nil
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should return path for directory/ with index" do
|
43
|
+
@filehandler.get_filename("/dir-with-index/").must_equal "/site/dir-with-index/index.html"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should return path for directory with index" do
|
47
|
+
@filehandler.get_filename("/dir-with-index").must_equal "/site/dir-with-index/index.html"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should return nil for directory/ without index" do
|
51
|
+
@filehandler.get_filename("/dir-without-index/").must_be_nil
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should return nil for directory without index" do
|
55
|
+
@filehandler.get_filename("/dir-without-index").must_be_nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
describe "when retrieving the file list from root directory" do
|
61
|
+
|
62
|
+
before do
|
63
|
+
sourcedir = File.join(TEST_DIR, "source")
|
64
|
+
@filehandler = Rack::Jekyll::FileHandler.new(sourcedir)
|
65
|
+
@existing_file = File.join(sourcedir, "index.md")
|
66
|
+
@existing_dir = File.join(sourcedir, "css")
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should include regular files" do
|
70
|
+
@filehandler.files.must_include @existing_file
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should not include directories" do
|
74
|
+
@filehandler.files.wont_include @existing_dir
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
describe "when initialized" do
|
80
|
+
|
81
|
+
it "should strip trailing slash from root" do
|
82
|
+
filehandler = Rack::Jekyll::FileHandler.new("/site/", [])
|
83
|
+
filehandler.root.must_equal "/site"
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should not append a trailing slash to root" do
|
87
|
+
filehandler = Rack::Jekyll::FileHandler.new("/site", [])
|
88
|
+
filehandler.root.must_equal "/site"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/test/test_requests.rb
CHANGED
@@ -30,12 +30,24 @@ describe "when handling requests" do
|
|
30
30
|
@request.wont_be_nil
|
31
31
|
end
|
32
32
|
|
33
|
-
it "should return
|
33
|
+
it "should return status 200 for existing path" do
|
34
34
|
@request.get("/").status.must_equal 200
|
35
|
+
@request.get("/2015/10/05/hello-world.html").status.must_equal 200
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should return status 404 for nonexistent path" do
|
35
39
|
@request.get("/show/me/404").status.must_equal 404
|
36
40
|
end
|
37
41
|
|
38
|
-
it "should return
|
42
|
+
it "should return status 404 for partially matching path 1" do
|
43
|
+
@request.get("/2015/10/05/hello").status.must_equal 404
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should return status 404 for partially matching path 2" do
|
47
|
+
@request.get("/10/05/hello-world.html").status.must_equal 404
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should return correct status code for If-Modified-Since" do
|
39
51
|
modify_time = @request.get("/").headers["Last-Modified"]
|
40
52
|
earlier_time = (Time.parse(modify_time) - 3600).httpdate
|
41
53
|
|
@@ -43,7 +55,7 @@ describe "when handling requests" do
|
|
43
55
|
@request.get("/", {"HTTP_IF_MODIFIED_SINCE" => earlier_time}).status.must_equal 200
|
44
56
|
end
|
45
57
|
|
46
|
-
it "should return correct
|
58
|
+
it "should return correct status code for If-Modified-Since with 404s" do
|
47
59
|
modify_time = @request.get("/").headers["Last-Modified"]
|
48
60
|
earlier_time = (Time.parse(modify_time) - 3600).httpdate
|
49
61
|
|
@@ -58,9 +70,8 @@ describe "when handling requests" do
|
|
58
70
|
@request.get("/show/me/404").headers["Content-Type"].must_equal "text/html"
|
59
71
|
end
|
60
72
|
|
61
|
-
it "should return correct Content-Length header" do
|
73
|
+
it "should return correct Content-Length header for '/'" do
|
62
74
|
@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
75
|
end
|
65
76
|
|
66
77
|
it "should return correct Content-Length header for If-Modified-Since" do
|
@@ -68,9 +79,42 @@ describe "when handling requests" do
|
|
68
79
|
@request.get("/", {"HTTP_IF_MODIFIED_SINCE" => modify_time}).original_headers["Content-Length"].must_be_nil
|
69
80
|
end
|
70
81
|
|
71
|
-
it "should return correct body" do
|
82
|
+
it "should return correct body for '/'" do
|
72
83
|
@request.get("/").body.must_equal "<p>Rack-Jekyll Test</p>\n"
|
73
|
-
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
describe "when a directory is requested" do
|
88
|
+
|
89
|
+
it "should redirect with status 301 to 'directory/' for 'directory' with index.html" do
|
90
|
+
skip
|
91
|
+
@request.get("/dir-with-index").status.must_equal 301
|
92
|
+
@request.get("/dir-with-index").headers["Location"].must_equal "/dir-with-index/"
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should return status 200 for 'directory/' with index.html" do
|
96
|
+
@request.get("/dir-with-index/").status.must_equal 200
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should return status 404 for 'directory' without index.html" do
|
100
|
+
@request.get("/dir-without-index").status.must_equal 404
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should return status 404 for 'directory/' without index.html" do
|
104
|
+
@request.get("/dir-without-index/").status.must_equal 404
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
describe "when a resource of unknown mime type is requested" do
|
110
|
+
|
111
|
+
it "should return status 200" do
|
112
|
+
@request.get("/no-extension").status.must_equal 200
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should return Content-Type 'application/octet-stream'" do
|
116
|
+
@request.get("/no-extension").headers["Content-Type"].must_equal "application/octet-stream"
|
117
|
+
end
|
74
118
|
end
|
75
119
|
|
76
120
|
|
@@ -88,4 +132,48 @@ describe "when handling requests" do
|
|
88
132
|
@response.original_headers["Content-Length"].to_i.must_equal 23
|
89
133
|
end
|
90
134
|
end
|
135
|
+
|
136
|
+
|
137
|
+
describe "when returning 404s" do
|
138
|
+
|
139
|
+
it "should return correct body for default 404" do
|
140
|
+
@request.get("/show/me/404").body.must_equal "Not found"
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should return correct Content-Length header for default 404" do
|
144
|
+
@request.get("/show/me/404").original_headers["Content-Length"].to_i.must_equal 9
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should return correct body for custom 404" do
|
148
|
+
begin
|
149
|
+
filename = File.join(@sourcedir, "404.html")
|
150
|
+
File.open(filename, "w") {|f| f.puts "Custom 404" }
|
151
|
+
|
152
|
+
jekyll = rack_jekyll(:force_build => true,
|
153
|
+
:source => @sourcedir,
|
154
|
+
:destination => @destdir)
|
155
|
+
request = Rack::MockRequest.new(jekyll)
|
156
|
+
|
157
|
+
request.get("/show/me/404").body.must_match %r{Custom 404}
|
158
|
+
ensure
|
159
|
+
FileUtils.rm(filename)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
|
165
|
+
describe "when handling HEAD requests" do
|
166
|
+
|
167
|
+
it "should return status 200 for '/'" do
|
168
|
+
@request.head("/").status.must_equal 200
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should return correct Content-Length header for '/'" do
|
172
|
+
@request.head("/").original_headers["Content-Length"].to_i.must_equal 24
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should not return a body" do
|
176
|
+
@request.head("/").body.must_equal ""
|
177
|
+
end
|
178
|
+
end
|
91
179
|
end
|
data/test/test_utils.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
3
|
+
|
4
|
+
describe Rack::Jekyll::Utils do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@utils = Rack::Jekyll::Utils
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
describe "when asked for #media_type" do
|
12
|
+
|
13
|
+
it "returns correct type for HTML" do
|
14
|
+
@utils.media_type("index.html").must_equal "text/html"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns correct type for HTML with full path" do
|
18
|
+
@utils.media_type("/path/index.html").must_equal "text/html"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns correct type for CSS" do
|
22
|
+
@utils.media_type("/path/style.css").must_equal "text/css"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns correct type for *.min.js" do
|
26
|
+
@utils.media_type("script.min.js").must_equal "application/javascript"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns correct default type for files without extension" do
|
30
|
+
@utils.media_type("README").must_equal "application/octet-stream"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "ignores lower/upper case in file extensions" do
|
34
|
+
@utils.media_type("image.JpG").must_equal "image/jpeg"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
describe "when asked for #file_info" do
|
40
|
+
|
41
|
+
before do
|
42
|
+
@filename = __FILE__
|
43
|
+
@info = @utils.file_info(@filename)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "has the file content" do
|
47
|
+
@info[:body].must_equal ::File.read(@filename)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "has the modification time in httpdate format" do
|
51
|
+
@info[:time].must_equal ::File.mtime(@filename).httpdate
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-jekyll
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Goines
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-11-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jekyll
|
@@ -87,17 +87,26 @@ executables: []
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files:
|
89
89
|
- README.markdown
|
90
|
+
- LICENSE
|
90
91
|
files:
|
91
92
|
- Gemfile
|
92
93
|
- LICENSE
|
93
94
|
- README.markdown
|
94
95
|
- Rakefile
|
96
|
+
- example/404.md
|
97
|
+
- example/_config.yml
|
98
|
+
- example/_layouts/default.html
|
99
|
+
- example/_layouts/post.html
|
100
|
+
- example/_posts/2009-12-21-hello-world.md
|
101
|
+
- example/config.ru
|
102
|
+
- example/css/site.css
|
103
|
+
- example/index.md
|
95
104
|
- features/requests.feature
|
96
105
|
- features/step_definitions/rack_jekyll_steps.rb
|
97
106
|
- features/support/env.rb
|
98
107
|
- lib/rack/jekyll.rb
|
99
|
-
- lib/rack/jekyll/
|
100
|
-
- lib/rack/jekyll/
|
108
|
+
- lib/rack/jekyll/filehandler.rb
|
109
|
+
- lib/rack/jekyll/utils.rb
|
101
110
|
- lib/rack/jekyll/version.rb
|
102
111
|
- rack-jekyll.gemspec
|
103
112
|
- test/helper.rb
|
@@ -105,12 +114,17 @@ files:
|
|
105
114
|
- test/source/_posts/2015-10-05-hello-world.md
|
106
115
|
- test/source/buenos_dias.md
|
107
116
|
- test/source/css/test.css
|
117
|
+
- test/source/dir-with-index/index.md
|
118
|
+
- test/source/dir-without-index/page.md
|
108
119
|
- test/source/index.md
|
109
120
|
- test/source/js/test.js
|
110
121
|
- test/source/js/test.min.js
|
122
|
+
- test/source/no-extension
|
111
123
|
- test/test_build.rb
|
112
124
|
- test/test_configuration.rb
|
125
|
+
- test/test_filehandler.rb
|
113
126
|
- test/test_requests.rb
|
127
|
+
- test/test_utils.rb
|
114
128
|
homepage: https://github.com/adaoraul/rack-jekyll
|
115
129
|
licenses: []
|
116
130
|
metadata: {}
|
@@ -124,7 +138,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
138
|
requirements:
|
125
139
|
- - ">="
|
126
140
|
- !ruby/object:Gem::Version
|
127
|
-
version:
|
141
|
+
version: 1.9.3
|
128
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
143
|
requirements:
|
130
144
|
- - ">="
|
@@ -142,12 +156,17 @@ test_files:
|
|
142
156
|
- test/source/_posts/2015-10-05-hello-world.md
|
143
157
|
- test/source/buenos_dias.md
|
144
158
|
- test/source/css/test.css
|
159
|
+
- test/source/dir-with-index/index.md
|
160
|
+
- test/source/dir-without-index/page.md
|
145
161
|
- test/source/index.md
|
146
162
|
- test/source/js/test.js
|
147
163
|
- test/source/js/test.min.js
|
164
|
+
- test/source/no-extension
|
148
165
|
- test/test_build.rb
|
149
166
|
- test/test_configuration.rb
|
167
|
+
- test/test_filehandler.rb
|
150
168
|
- test/test_requests.rb
|
169
|
+
- test/test_utils.rb
|
151
170
|
- features/requests.feature
|
152
171
|
- features/step_definitions/rack_jekyll_steps.rb
|
153
172
|
- features/support/env.rb
|
data/lib/rack/jekyll/ext.rb
DELETED
data/lib/rack/jekyll/helpers.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module Rack
|
2
|
-
class Jekyll
|
3
|
-
def mime(path_info)
|
4
|
-
if path_info !~ /html$/i
|
5
|
-
ext = $1 if path_info =~ /(\.[\S&&[^.]]+)$/
|
6
|
-
Mime.mime_type((ext.nil? ? ".html" : ext))
|
7
|
-
else
|
8
|
-
Mime.mime_type(".html")
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def file_info(path)
|
13
|
-
expand_path = ::File.expand_path(path)
|
14
|
-
::File.open(expand_path, 'r') do |f|
|
15
|
-
{:body => f.read, :time => f.mtime.httpdate, :expand_path => expand_path}
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|