wonki 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/wonki/page_builder.rb +11 -5
- data/lib/wonki/wiki_page.rb +5 -3
- data/test/page_builder_test.rb +22 -8
- data/test/wiki_page_test.rb +4 -0
- data/wonki.gemspec +1 -1
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/lib/wonki/page_builder.rb
CHANGED
@@ -6,19 +6,25 @@ module Wonki
|
|
6
6
|
class PageBuilder
|
7
7
|
def initialize(repo_path)
|
8
8
|
@repo_path = repo_path
|
9
|
+
@repository = Grit::Repo.new(@repo_path)
|
9
10
|
end
|
10
11
|
|
11
12
|
def build(route)
|
12
|
-
route_name = route[1..-1]
|
13
|
-
data = find(
|
14
|
-
|
13
|
+
route_name = route[1..-1] # strip leading slash
|
14
|
+
data = find(route_name)
|
15
|
+
mod_date = get_mod_date(route_name)
|
16
|
+
content = %Q{<h2 id="location">#{route_name}</h2><div id="content">#{Flannel.quilt(data)}</div>}
|
17
|
+
{:content => content, :last_modified => mod_date}
|
15
18
|
end
|
16
19
|
|
17
20
|
def find(name)
|
18
|
-
|
19
|
-
blob = (repository.tree/name)
|
21
|
+
blob = (@repository.tree/name)
|
20
22
|
raise Wonki::PageNotFound.new if blob.nil?
|
21
23
|
blob.data
|
22
24
|
end
|
25
|
+
|
26
|
+
def get_mod_date(name)
|
27
|
+
@repository.commits.first.committed_date
|
28
|
+
end
|
23
29
|
end
|
24
30
|
end
|
data/lib/wonki/wiki_page.rb
CHANGED
@@ -16,8 +16,12 @@ module Wonki
|
|
16
16
|
path = "/home" if path == "/"
|
17
17
|
builder = Wonki::PageBuilder.new(@repo_path)
|
18
18
|
|
19
|
+
headers = {"Content-Type" => "text/html", "Content-Language" => "en"}
|
20
|
+
|
19
21
|
begin
|
20
|
-
|
22
|
+
git_data = builder.build(path)
|
23
|
+
response_body = git_data[:content]
|
24
|
+
headers["Last-Modified"] = git_data[:last_modified].httpdate
|
21
25
|
status = 200
|
22
26
|
rescue Wonki::PageNotFound
|
23
27
|
response_body = "Page Not Found"
|
@@ -27,8 +31,6 @@ module Wonki
|
|
27
31
|
status = 500
|
28
32
|
end
|
29
33
|
|
30
|
-
headers = {"Content-Type" => "text/html", "Content-Language" => "en"}
|
31
|
-
|
32
34
|
[status, headers, response_body]
|
33
35
|
end
|
34
36
|
end
|
data/test/page_builder_test.rb
CHANGED
@@ -10,22 +10,36 @@ class PageBuilderTest < Test::Unit::TestCase
|
|
10
10
|
|
11
11
|
should "include the location" do
|
12
12
|
out = @builder.build("/cheese")
|
13
|
-
assert_match("cheese", out)
|
13
|
+
assert_match("cheese", out[:content])
|
14
14
|
end
|
15
15
|
|
16
16
|
should "include the content" do
|
17
17
|
out = @builder.build("/cheese")
|
18
|
-
assert_match("swiss", out)
|
19
|
-
end
|
20
|
-
|
21
|
-
should "find page contents in the git repo" do
|
22
|
-
out = @builder.find("foo")
|
23
|
-
assert_match("bar bar", out)
|
18
|
+
assert_match("swiss", out[:content])
|
24
19
|
end
|
25
20
|
|
26
21
|
should "flannel content" do
|
27
22
|
out = @builder.build("/header")
|
28
|
-
assert_match("<h2>foo</h2>", out)
|
23
|
+
assert_match("<h2>foo</h2>", out[:content])
|
24
|
+
end
|
25
|
+
|
26
|
+
context "finding blob data" do
|
27
|
+
should "find page contents in the git repo" do
|
28
|
+
blob_data = @builder.find("foo")
|
29
|
+
assert_match("bar bar", blob_data)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "last_modified date" do
|
34
|
+
should "not be nil" do
|
35
|
+
out = @builder.build("/foo")
|
36
|
+
assert_not_nil out[:last_modified]
|
37
|
+
end
|
38
|
+
|
39
|
+
should "return the commited date" do
|
40
|
+
out = @builder.build("/foo")
|
41
|
+
assert_equal Time, out[:last_modified].class
|
42
|
+
end
|
29
43
|
end
|
30
44
|
|
31
45
|
context "page doesn't exist" do
|
data/test/wiki_page_test.rb
CHANGED
@@ -20,6 +20,10 @@ class WikiPageTest < Test::Unit::TestCase
|
|
20
20
|
should "set content language" do
|
21
21
|
assert_equal(@headers["Content-Language"], 'en')
|
22
22
|
end
|
23
|
+
|
24
|
+
should "set last modified" do
|
25
|
+
assert_equal(@headers["Last-Modified"], "Tue, 29 Dec 2009 06:56:38 GMT")
|
26
|
+
end
|
23
27
|
end
|
24
28
|
|
25
29
|
context "PageNotFound" do
|
data/wonki.gemspec
CHANGED