lanyon 0.3.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.md +4 -0
- data/README.md +14 -0
- data/lib/lanyon/router.rb +12 -2
- data/lib/lanyon/version.rb +2 -2
- data/test/test_router.rb +38 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aefd2bc5a51fecb9a125d2d0fda7727c396bd5f6
|
4
|
+
data.tar.gz: 6a992436a95497be137628d08f07457a2b0c30ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bdcfb2568a03f545a0044e3ad2acd197e591d77dec45df66a95e4f7afa597c2860e2f1c2599f879b6afbe21734dce572667d1712c53e0e28253a4487fc3f235c
|
7
|
+
data.tar.gz: 5670446e50079db5aac69946e5b3615ac3834705afe993506a35d63a69cf2b6d59edb9dd0f53a0d8afb38192fac82d2b1a59beb8180ff6074b0655036cef4012
|
data/History.md
CHANGED
data/README.md
CHANGED
@@ -83,6 +83,20 @@ This can also be a file generated by Jekyll from e.g. Markdown sources.
|
|
83
83
|
|
84
84
|
- Gem dependencies (runtime): `jekyll`, `rack`
|
85
85
|
|
86
|
+
## How URLs are resolved
|
87
|
+
|
88
|
+
Lanyon maps URLs to corresponding files as follows:
|
89
|
+
|
90
|
+
1. a `path/` with a trailing slash is changed to `path/index.html`,
|
91
|
+
2. then, Lanyon checks for an exactly corresponding file,
|
92
|
+
3. when `path` does not exist but `path/index.html` does,
|
93
|
+
the response will be a redirect to `path/`,
|
94
|
+
4. when neither 2. nor 3. apply, +path.html+ is tried.
|
95
|
+
|
96
|
+
To avoid confusion, it's probably a good idea to have only one
|
97
|
+
of `resource`, `resource/index.html`, and `resource.html` present
|
98
|
+
as file in your site.
|
99
|
+
|
86
100
|
## Reporting Bugs
|
87
101
|
|
88
102
|
Report bugs on the Lanyon home page: <https://github.com/stomar/lanyon/>
|
data/lib/lanyon/router.rb
CHANGED
@@ -16,9 +16,17 @@ module Lanyon
|
|
16
16
|
# Returns the full file system path of the file corresponding to
|
17
17
|
# the given URL +path+, or
|
18
18
|
#
|
19
|
-
# - +:
|
20
|
-
# - +:
|
19
|
+
# - +:must_redirect+ if the request must be redirected to +path/+,
|
20
|
+
# - +:not_found+ if no corresponding file exists.
|
21
21
|
#
|
22
|
+
# The return value is found as follows:
|
23
|
+
#
|
24
|
+
# 1. a +path/+ with a trailing slash is changed to +path/index.html+,
|
25
|
+
# 2. then, the method checks for an exactly corresponding file,
|
26
|
+
# 3. when +path+ does not exist but +path/index.html+ does,
|
27
|
+
# a redirect will be indicated,
|
28
|
+
# 4. finally, when no exactly corresponding file or redirect
|
29
|
+
# can be found, +path.html+ is tried.
|
22
30
|
def endpoint(path)
|
23
31
|
normalized = normalize_path_info(path)
|
24
32
|
|
@@ -27,6 +35,8 @@ module Lanyon
|
|
27
35
|
fullpath
|
28
36
|
elsif needs_redirect_to_dir?(fullpath)
|
29
37
|
:must_redirect
|
38
|
+
elsif FileTest.file?(fullpath_html = "#{fullpath}.html")
|
39
|
+
fullpath_html
|
30
40
|
else
|
31
41
|
:not_found
|
32
42
|
end
|
data/lib/lanyon/version.rb
CHANGED
data/test/test_router.rb
CHANGED
@@ -17,6 +17,10 @@ describe Lanyon::Router do
|
|
17
17
|
dir-with-index/index.html
|
18
18
|
dir-without-index/page.html
|
19
19
|
dir1/dir2/dir3/index.html
|
20
|
+
foo
|
21
|
+
foo.html
|
22
|
+
bar.html
|
23
|
+
bar/index.html
|
20
24
|
]
|
21
25
|
|
22
26
|
files.each do |path|
|
@@ -79,6 +83,40 @@ describe Lanyon::Router do
|
|
79
83
|
end
|
80
84
|
|
81
85
|
|
86
|
+
describe "when automatically adding .html extension" do
|
87
|
+
|
88
|
+
it "returns existing path" do
|
89
|
+
filename = File.join(@sitedir, "page.html")
|
90
|
+
@router.endpoint("/page").must_equal filename
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "when both `foo' and `foo.html' exist" do
|
94
|
+
|
95
|
+
it "returns `foo' and not `foo.html' when asked for `foo'" do
|
96
|
+
filename = File.join(@sitedir, "foo")
|
97
|
+
@router.endpoint("/foo").must_equal filename
|
98
|
+
end
|
99
|
+
|
100
|
+
it "can also serve `foo.html'" do
|
101
|
+
filename = File.join(@sitedir, "foo.html")
|
102
|
+
@router.endpoint("/foo.html").must_equal filename
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "when both `bar.html' and `bar/index.html' exist" do
|
107
|
+
|
108
|
+
it "returns :must_redirect and not `bar.html' when asked for `bar'" do
|
109
|
+
@router.endpoint("/bar").must_equal :must_redirect
|
110
|
+
end
|
111
|
+
|
112
|
+
it "can also serve `bar.html'" do
|
113
|
+
filename = File.join(@sitedir, "bar.html")
|
114
|
+
@router.endpoint("/bar.html").must_equal filename
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
|
82
120
|
describe "when asked for paths with directory traversal" do
|
83
121
|
|
84
122
|
it "discards leading '..' for existing path" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lanyon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcus Stollsteimer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|