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 CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -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(route[1..-1])
14
- %Q{<h2 id="location">#{route_name}</h2><div id="content">#{Flannel.quilt(data)}</div>}
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
- repository = Grit::Repo.new(@repo_path)
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
@@ -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
- response_body = builder.build(path)
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
@@ -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
@@ -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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{wonki}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["rubyyot"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wonki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - rubyyot