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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6cb7a805a0eb3c37772d55e691f36ac3e1c2ab6
4
- data.tar.gz: 3269b6445233679a7aa0f5cdf120950e8674bb78
3
+ metadata.gz: aefd2bc5a51fecb9a125d2d0fda7727c396bd5f6
4
+ data.tar.gz: 6a992436a95497be137628d08f07457a2b0c30ad
5
5
  SHA512:
6
- metadata.gz: ec3bc073134f90350a6b8129c811fae79c6f4284b95c830ee01662e2480f3fbf97eea1e75e232ef5e3a97a83f8a9b8e5fb65d0c94d4988b4b2906c804739fdb4
7
- data.tar.gz: 573de99ab0c5d7255dbdde58464797a64f7c2f9f3c54b7bd3e0874b007ea115d6e3cd594e03ff26d534d76a96a54ba6224fdd3b22e584417dd53553dc37ad1af
6
+ metadata.gz: bdcfb2568a03f545a0044e3ad2acd197e591d77dec45df66a95e4f7afa597c2860e2f1c2599f879b6afbe21734dce572667d1712c53e0e28253a4487fc3f235c
7
+ data.tar.gz: 5670446e50079db5aac69946e5b3615ac3834705afe993506a35d63a69cf2b6d59edb9dd0f53a0d8afb38192fac82d2b1a59beb8180ff6074b0655036cef4012
data/History.md CHANGED
@@ -1,6 +1,10 @@
1
1
  Release History
2
2
  ===============
3
3
 
4
+ ## 0.4.0
5
+
6
+ * Support .html extension stripping
7
+
4
8
  ## 0.3.4
5
9
 
6
10
  * Allow Rack 2
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/>
@@ -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
- # - +:not_found+ if no corresponding file exists,
20
- # - +:must_redirect+ if the request must be redirected to <tt>path/</tt>.
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
@@ -1,4 +1,4 @@
1
1
  module Lanyon
2
- VERSION = "0.3.4"
3
- DATE = "2016-08-01"
2
+ VERSION = "0.4.0"
3
+ DATE = "2016-09-01"
4
4
  end
@@ -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.3.4
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-08-01 00:00:00.000000000 Z
11
+ date: 2016-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll