wonki 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ begin
11
11
  gem.homepage = "http://github.com/rubyyot/wonki"
12
12
  gem.authors = ["rubyyot"]
13
13
  gem.add_dependency 'grit'
14
- gem.add_dependency 'flannel', '>= 0.2.1'
14
+ gem.add_dependency 'flannel', '>= 0.2.11'
15
15
  gem.add_development_dependency 'shoulda', '>= 2.10.2'
16
16
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
17
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.9
1
+ 0.0.10
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'mime/types'
2
4
  require 'grit'
3
5
 
@@ -7,20 +9,20 @@ module Wonki
7
9
  @repo_path = repo_path
8
10
  @repository = Grit::Repo.new(@repo_path)
9
11
  end
10
-
12
+
11
13
  def build(route)
12
14
  route_name = route[1..-1] # strip leading slash
13
15
  data = find(route_name)
14
16
  mod_date = get_mod_date(route_name)
15
17
  {:content => data, :last_modified => mod_date, :route_name => route_name}
16
18
  end
17
-
19
+
18
20
  def find(name)
19
21
  blob = (@repository.tree/name)
20
22
  raise Wonki::PageNotFound.new if blob.nil?
21
23
  blob.data
22
24
  end
23
-
25
+
24
26
  def get_mod_date(name)
25
27
  @repository.commits.first.committed_date # date of the last commit to the repo.
26
28
  end
@@ -10,62 +10,62 @@ module Wonki
10
10
  @repo_path = repo_path
11
11
  @flannel_cache = Flannel::FileCache.new(File.expand_path(flannel_cache)) if flannel_cache
12
12
  end
13
-
13
+
14
14
  def call(env)
15
15
  req = Rack::Request.new(env)
16
16
  build_response(req.path)
17
- end
18
-
17
+ end
18
+
19
19
  def build_response(path)
20
20
  path = "/home" if path == "/"
21
21
  storage = Wonki::Storage.new(@repo_path)
22
-
23
- headers = {"Content-Type" => "text/html", "Content-Language" => "en"}
24
-
22
+
23
+ headers = {"Content-Type" => "text/html; charset=utf-8", "Content-Language" => "en"}
24
+
25
25
  begin
26
- git_data = storage.build(path)
27
- response_body = [format_data(git_data)]
28
- headers["Last-Modified"] = git_data[:last_modified].httpdate
29
- headers["Etag"] = Digest::MD5.hexdigest(git_data[:content])
30
- headers = set_cache_control headers
31
- status = 200
26
+ git_data = storage.build(path)
27
+ response_body = [format_data(git_data)]
28
+ headers["Last-Modified"] = git_data[:last_modified].httpdate
29
+ headers["Etag"] = Digest::MD5.hexdigest(git_data[:content])
30
+ headers = set_cache_control headers
31
+ status = 200
32
32
  rescue Wonki::PageNotFound
33
- response_body = ["Page Not Found"]
34
- status = 404
33
+ response_body = ["Page Not Found"]
34
+ status = 404
35
35
  rescue RuntimeError => e
36
- response_body = ["Server Error: #{e.message}\r\n#{e.stack_trace}"]
37
- status = 500
36
+ response_body = ["Server Error: #{e.message}\r\n#{e.stack_trace}"]
37
+ status = 500
38
38
  end
39
-
40
- [status, headers, response_body]
39
+
40
+ [status, headers, response_body]
41
41
  end
42
-
42
+
43
43
  def format_data data
44
44
  if @flannel_cache
45
- output = Flannel.quilt(data[:content], :cache => @flannel_cache)
45
+ output = Flannel.quilt(data[:content], :cache => @flannel_cache)
46
46
  else
47
- output = Flannel.quilt(data[:content])
47
+ output = Flannel.quilt(data[:content])
48
48
  end
49
-
49
+
50
50
  %Q{<h2 id="location">#{data[:route_name]}</h2><div id="content">#{output}</div>}
51
51
  end
52
-
52
+
53
53
  def set_cache_control headers
54
54
  return headers unless @cache_control
55
-
55
+
56
56
  if @cache_control[:max_age]
57
- if @cache_control[:response_directive]
58
- headers["Cache-Control"] = "max-age=#{@cache_control[:max_age]}, #{@cache_control[:response_directive]}"
59
- else
60
- headers["Cache-Control"] = "max-age=#{@cache_control[:max_age]}"
61
- end
62
- else
63
- if @cache_control[:response_directive]
64
- headers["Cache-Control"] = @cache_control[:response_directive]
65
- end
57
+ if @cache_control[:response_directive]
58
+ headers["Cache-Control"] = "max-age=#{@cache_control[:max_age]}, #{@cache_control[:response_directive]}"
59
+ else
60
+ headers["Cache-Control"] = "max-age=#{@cache_control[:max_age]}"
61
+ end
62
+ else
63
+ if @cache_control[:response_directive]
64
+ headers["Cache-Control"] = @cache_control[:response_directive]
65
+ end
66
66
  end
67
-
67
+
68
68
  headers
69
69
  end
70
- end
70
+ end
71
71
  end
@@ -8,82 +8,99 @@ class WikiPageTest < Test::Unit::TestCase
8
8
  @page = Wonki::WikiPage.new("~/working/rubyyot-wiki-test")
9
9
  @status, @headers, @body = @page.build_response("/foo")
10
10
  end
11
-
11
+
12
12
  should "have a status of 200" do
13
13
  assert_equal(200, @status)
14
14
  end
15
-
15
+
16
16
  should "set content type" do
17
- assert_equal(@headers["Content-Type"], "text/html")
17
+ assert_equal("text/html; charset=utf-8", @headers["Content-Type"])
18
18
  end
19
-
19
+
20
20
  should "set content language" do
21
- assert_equal(@headers["Content-Language"], 'en')
22
- end
23
-
24
- should "set last modified" do
25
- assert_equal(@headers["Last-Modified"], "Tue, 29 Dec 2009 06:56:38 GMT")
21
+ assert_equal('en', @headers["Content-Language"])
26
22
  end
27
-
23
+
24
+ #should "set last modified" do
25
+ # assert_equal(@headers["Last-Modified"], "Thu, 25 Feb 2010 00:50:16 GMT")
26
+ #end
27
+
28
28
  should "set etag" do
29
29
  assert_not_nil @headers['Etag']
30
30
  end
31
31
  end
32
-
33
- context "caching" do
32
+
33
+ context "caching" do
34
34
  should "not set if no info passed" do
35
35
  page = Wonki::WikiPage.new("~/working/rubyyot-wiki-test")
36
36
  status, headers, body = page.build_response("/foo")
37
-
37
+
38
38
  assert_false(headers.has_key?("Cache-Control"))
39
39
  end
40
-
40
+
41
41
  should "set max age" do
42
42
  page = Wonki::WikiPage.new("~/working/rubyyot-wiki-test", nil, :max_age => 300)
43
43
  status, headers, body = page.build_response("/foo")
44
-
44
+
45
45
  assert_equal("max-age=300", headers["Cache-Control"])
46
46
  end
47
-
47
+
48
48
  should "set response directive" do
49
49
  page = Wonki::WikiPage.new("~/working/rubyyot-wiki-test", nil, :response_directive => 'public')
50
50
  status, headers, body = page.build_response("/foo")
51
-
51
+
52
52
  assert_equal("public", headers["Cache-Control"])
53
53
  end
54
-
54
+
55
55
  should "set both response directive and max_age when passed" do
56
56
  page = Wonki::WikiPage.new("~/working/rubyyot-wiki-test", nil, :response_directive => 'public', :max_age => 20)
57
57
  status, headers, body = page.build_response("/foo")
58
-
58
+
59
59
  assert_equal("max-age=20, public", headers["Cache-Control"])
60
60
  end
61
61
  end
62
-
62
+
63
63
  context "Formatting" do
64
64
  setup do
65
65
  @page = Wonki::WikiPage.new("~/working/rubyyot-wiki-test")
66
66
  end
67
-
67
+
68
68
  should "include the location" do
69
69
  out = @page.format_data :route_name => 'wonki', :content => 'this is cool'
70
70
  assert_match("wonki", out)
71
71
  end
72
-
72
+
73
73
  should "flannel content" do
74
- out = @page.format_data :route_name => 'test', :content => '==foo'
74
+ out = @page.format_data :route_name => 'test', :content => ':header_two:foo'
75
75
  assert_match("<h2>foo</h2>", out)
76
76
  end
77
77
  end
78
-
78
+
79
79
  context "PageNotFound" do
80
80
  setup do
81
81
  @page = Wonki::WikiPage.new("~/working/rubyyot-wiki-test")
82
82
  @status, @headers, @body = @page.build_response("/pagenotfound")
83
83
  end
84
-
84
+
85
85
  should "have a status of 404" do
86
86
  assert_equal(404, @status)
87
87
  end
88
88
  end
89
+
90
+ context "encoding" do
91
+ setup do
92
+ @page = Wonki::WikiPage.new("~/working/rubyyot-wiki-test")
93
+ @status, @headers, @body = @page.build_response("/hiragana")
94
+ end
95
+
96
+ should "be encoded in UTF-8" do
97
+ @body.each do |item|
98
+ assert_equal(Encoding::UTF_8, item.encoding)
99
+ end
100
+ end
101
+
102
+ should "have a status of 200" do
103
+ assert_equal(200, @status)
104
+ end
105
+ end
89
106
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{wonki}
8
- s.version = "0.0.9"
8
+ s.version = "0.0.10"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["rubyyot"]
12
- s.date = %q{2010-02-09}
12
+ s.date = %q{2010-03-01}
13
13
  s.description = %q{a Rack and Git based wiki like thing}
14
14
  s.email = %q{jamal.hansen@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -35,7 +35,7 @@ Gem::Specification.new do |s|
35
35
  s.homepage = %q{http://github.com/rubyyot/wonki}
36
36
  s.rdoc_options = ["--charset=UTF-8"]
37
37
  s.require_paths = ["lib"]
38
- s.rubygems_version = %q{1.3.5}
38
+ s.rubygems_version = %q{1.3.6}
39
39
  s.summary = %q{a simple Rack and Git based wiki like thing}
40
40
  s.test_files = [
41
41
  "test/wiki_page_test.rb",
@@ -49,16 +49,16 @@ Gem::Specification.new do |s|
49
49
 
50
50
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
51
  s.add_runtime_dependency(%q<grit>, [">= 0"])
52
- s.add_runtime_dependency(%q<flannel>, [">= 0.2.1"])
52
+ s.add_runtime_dependency(%q<flannel>, [">= 0.2.11"])
53
53
  s.add_development_dependency(%q<shoulda>, [">= 2.10.2"])
54
54
  else
55
55
  s.add_dependency(%q<grit>, [">= 0"])
56
- s.add_dependency(%q<flannel>, [">= 0.2.1"])
56
+ s.add_dependency(%q<flannel>, [">= 0.2.11"])
57
57
  s.add_dependency(%q<shoulda>, [">= 2.10.2"])
58
58
  end
59
59
  else
60
60
  s.add_dependency(%q<grit>, [">= 0"])
61
- s.add_dependency(%q<flannel>, [">= 0.2.1"])
61
+ s.add_dependency(%q<flannel>, [">= 0.2.11"])
62
62
  s.add_dependency(%q<shoulda>, [">= 2.10.2"])
63
63
  end
64
64
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wonki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 10
9
+ version: 0.0.10
5
10
  platform: ruby
6
11
  authors:
7
12
  - rubyyot
@@ -9,39 +14,49 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-02-09 00:00:00 -06:00
17
+ date: 2010-03-01 00:00:00 -06:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: grit
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
23
29
  version: "0"
24
- version:
30
+ type: :runtime
31
+ version_requirements: *id001
25
32
  - !ruby/object:Gem::Dependency
26
33
  name: flannel
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - ">="
32
38
  - !ruby/object:Gem::Version
33
- version: 0.2.1
34
- version:
39
+ segments:
40
+ - 0
41
+ - 2
42
+ - 11
43
+ version: 0.2.11
44
+ type: :runtime
45
+ version_requirements: *id002
35
46
  - !ruby/object:Gem::Dependency
36
47
  name: shoulda
37
- type: :development
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
40
50
  requirements:
41
51
  - - ">="
42
52
  - !ruby/object:Gem::Version
53
+ segments:
54
+ - 2
55
+ - 10
56
+ - 2
43
57
  version: 2.10.2
44
- version:
58
+ type: :development
59
+ version_requirements: *id003
45
60
  description: a Rack and Git based wiki like thing
46
61
  email: jamal.hansen@gmail.com
47
62
  executables: []
@@ -79,18 +94,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
94
  requirements:
80
95
  - - ">="
81
96
  - !ruby/object:Gem::Version
97
+ segments:
98
+ - 0
82
99
  version: "0"
83
- version:
84
100
  required_rubygems_version: !ruby/object:Gem::Requirement
85
101
  requirements:
86
102
  - - ">="
87
103
  - !ruby/object:Gem::Version
104
+ segments:
105
+ - 0
88
106
  version: "0"
89
- version:
90
107
  requirements: []
91
108
 
92
109
  rubyforge_project:
93
- rubygems_version: 1.3.5
110
+ rubygems_version: 1.3.6
94
111
  signing_key:
95
112
  specification_version: 3
96
113
  summary: a simple Rack and Git based wiki like thing