toto 0.4.5 → 0.4.6
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.
- data/Rakefile +5 -1
- data/TODO +0 -3
- data/VERSION +1 -1
- data/lib/toto.rb +12 -5
- data/test/toto_test.rb +62 -3
- data/toto.gemspec +2 -2
- metadata +2 -2
data/Rakefile
CHANGED
@@ -13,7 +13,11 @@ begin
|
|
13
13
|
gem.add_development_dependency "riot"
|
14
14
|
gem.add_dependency "builder"
|
15
15
|
gem.add_dependency "rack"
|
16
|
-
|
16
|
+
if RUBY_PLATFORM =~ /win32/
|
17
|
+
gem.add_dependency "maruku"
|
18
|
+
else
|
19
|
+
gem.add_dependency "rdiscount"
|
20
|
+
end
|
17
21
|
end
|
18
22
|
Jeweler::GemcutterTasks.new
|
19
23
|
rescue LoadError
|
data/TODO
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.6
|
data/lib/toto.rb
CHANGED
@@ -5,7 +5,13 @@ require 'rack'
|
|
5
5
|
require 'digest'
|
6
6
|
require 'open-uri'
|
7
7
|
|
8
|
-
|
8
|
+
if RUBY_PLATFORM =~ /win32/
|
9
|
+
require 'maruku'
|
10
|
+
Markdown = Maruku
|
11
|
+
else
|
12
|
+
require 'rdiscount'
|
13
|
+
end
|
14
|
+
|
9
15
|
require 'builder'
|
10
16
|
|
11
17
|
$:.unshift File.dirname(__FILE__)
|
@@ -265,7 +271,7 @@ module Toto
|
|
265
271
|
end
|
266
272
|
|
267
273
|
def path
|
268
|
-
@config[:prefix]
|
274
|
+
"/#{@config[:prefix]}#{self[:date].strftime("/%Y/%m/%d/#{slug}/")}".squeeze('/')
|
269
275
|
end
|
270
276
|
|
271
277
|
def title() self[:title] || "an article" end
|
@@ -311,11 +317,12 @@ module Toto
|
|
311
317
|
end
|
312
318
|
|
313
319
|
class Server
|
314
|
-
attr_reader :config
|
320
|
+
attr_reader :config, :site
|
315
321
|
|
316
322
|
def initialize config = {}, &blk
|
317
323
|
@config = config.is_a?(Config) ? config : Config.new(config)
|
318
324
|
@config.instance_eval(&blk) if block_given?
|
325
|
+
@site = Toto::Site.new(@config)
|
319
326
|
end
|
320
327
|
|
321
328
|
def call env
|
@@ -327,7 +334,7 @@ module Toto
|
|
327
334
|
path, mime = @request.path_info.split('.')
|
328
335
|
route = (path || '/').split('/').reject {|i| i.empty? }
|
329
336
|
|
330
|
-
response =
|
337
|
+
response = @site.go(route, *(mime ? mime : []))
|
331
338
|
|
332
339
|
@response.body = [response[:body]]
|
333
340
|
@response['Content-Length'] = response[:body].length.to_s unless response[:body].empty?
|
@@ -340,7 +347,7 @@ module Toto
|
|
340
347
|
"no-cache, must-revalidate"
|
341
348
|
end
|
342
349
|
|
343
|
-
@response['
|
350
|
+
@response['ETag'] = %("#{Digest::SHA1.hexdigest(response[:body])}")
|
344
351
|
|
345
352
|
@response.status = response[:status]
|
346
353
|
@response.finish
|
data/test/toto_test.rb
CHANGED
@@ -42,6 +42,8 @@ context Toto do
|
|
42
42
|
asserts("content type is set properly") { topic.content_type }.equals "text/html"
|
43
43
|
should("include a couple of article") { topic.body }.includes_elements("#articles li", 3)
|
44
44
|
should("include an archive") { topic.body }.includes_elements("#archives li", 2)
|
45
|
+
asserts("Etag header present") { topic.headers.include? "ETag" }
|
46
|
+
asserts("Etag header has a value") { not topic.headers["ETag"].empty? }
|
45
47
|
end
|
46
48
|
end
|
47
49
|
|
@@ -78,9 +80,14 @@ context Toto do
|
|
78
80
|
end
|
79
81
|
end
|
80
82
|
|
81
|
-
context "GET to an unknown route" do
|
82
|
-
setup
|
83
|
+
context "GET to an unknown route with a custom error" do
|
84
|
+
setup do
|
85
|
+
@config[:error] = lambda {|code| "error: #{code}" }
|
86
|
+
@toto.get('/unknown')
|
87
|
+
end
|
88
|
+
|
83
89
|
should("returns a 404") { topic.status }.equals 404
|
90
|
+
should("return the custom error") { topic.body }.equals "error: 404"
|
84
91
|
end
|
85
92
|
|
86
93
|
context "Request is invalid" do
|
@@ -184,6 +191,47 @@ context Toto do
|
|
184
191
|
should("create a valid summary") { topic.summary.size }.within 75..80
|
185
192
|
end
|
186
193
|
end
|
194
|
+
|
195
|
+
context "in a subdirectory" do
|
196
|
+
context "with implicit leading forward slash" do
|
197
|
+
setup do
|
198
|
+
conf = Toto::Config.new({})
|
199
|
+
conf.set(:prefix, "blog")
|
200
|
+
Toto::Article.new({
|
201
|
+
:title => "Toto & The Wizard of Oz.",
|
202
|
+
:body => "#Chapter I\nhello, *stranger*."
|
203
|
+
}, conf)
|
204
|
+
end
|
205
|
+
|
206
|
+
should("be in the directory") { topic.path }.equals Date.today.strftime("/blog/%Y/%m/%d/toto-and-the-wizard-of-oz/")
|
207
|
+
end
|
208
|
+
|
209
|
+
context "with explicit leading forward slash" do
|
210
|
+
setup do
|
211
|
+
conf = Toto::Config.new({})
|
212
|
+
conf.set(:prefix, "/blog")
|
213
|
+
Toto::Article.new({
|
214
|
+
:title => "Toto & The Wizard of Oz.",
|
215
|
+
:body => "#Chapter I\nhello, *stranger*."
|
216
|
+
}, conf)
|
217
|
+
end
|
218
|
+
|
219
|
+
should("be in the directory") { topic.path }.equals Date.today.strftime("/blog/%Y/%m/%d/toto-and-the-wizard-of-oz/")
|
220
|
+
end
|
221
|
+
|
222
|
+
context "with explicit trailing forward slash" do
|
223
|
+
setup do
|
224
|
+
conf = Toto::Config.new({})
|
225
|
+
conf.set(:prefix, "blog/")
|
226
|
+
Toto::Article.new({
|
227
|
+
:title => "Toto & The Wizard of Oz.",
|
228
|
+
:body => "#Chapter I\nhello, *stranger*."
|
229
|
+
}, conf)
|
230
|
+
end
|
231
|
+
|
232
|
+
should("be in the directory") { topic.path }.equals Date.today.strftime("/blog/%Y/%m/%d/toto-and-the-wizard-of-oz/")
|
233
|
+
end
|
234
|
+
end
|
187
235
|
end
|
188
236
|
|
189
237
|
context "using Config#set with a hash" do
|
@@ -207,8 +255,19 @@ context Toto do
|
|
207
255
|
should("set the value to a proc") { topic[:to_html] }.respond_to :call
|
208
256
|
end
|
209
257
|
|
210
|
-
context "
|
258
|
+
context "testing individual configuration parameters" do
|
259
|
+
context "generate error pages" do
|
260
|
+
setup do
|
261
|
+
conf = Toto::Config.new({})
|
262
|
+
conf.set(:error) {|code| "error code #{code}" }
|
263
|
+
conf
|
264
|
+
end
|
265
|
+
|
266
|
+
should("create an error page") { topic[:error].call(400) }.equals "error code 400"
|
267
|
+
end
|
268
|
+
end
|
211
269
|
|
270
|
+
context "extensions to the core Ruby library" do
|
212
271
|
should("respond to iso8601") { Date.today }.respond_to?(:iso8601)
|
213
272
|
end
|
214
273
|
end
|
data/toto.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{toto}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["cloudhead"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-05-11}
|
13
13
|
s.description = %q{the tiniest blog-engine in Oz.}
|
14
14
|
s.email = %q{self@cloudhead.net}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cloudhead
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-05-11 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|