toto 0.3.3 → 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.
- data/README.md +3 -0
- data/VERSION +1 -1
- data/lib/toto.rb +26 -23
- data/test/toto_test.rb +15 -0
- data/toto.gemspec +2 -2
- metadata +2 -2
data/README.md
CHANGED
@@ -142,6 +142,9 @@ you could add `set :author, 'John Galt'` inside the `Toto::Server.new` block. He
|
|
142
142
|
set :summary, :max => 150, :delim => /~\n/ # length of article summary and delimiter
|
143
143
|
set :ext, 'txt' # file extension for articles
|
144
144
|
set :cache, 28800 # cache site for 8 hours
|
145
|
+
set :to_html, lambda {|path, page, ctx| # returns an html, from a path & context
|
146
|
+
ERB.new(File.read("#{path}/#{page}.rhtml")).result(ctx)
|
147
|
+
}
|
145
148
|
|
146
149
|
thanks
|
147
150
|
------
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/toto.rb
CHANGED
@@ -28,9 +28,9 @@ module Toto
|
|
28
28
|
end
|
29
29
|
|
30
30
|
module Template
|
31
|
-
def to_html page, &blk
|
31
|
+
def to_html page, config, &blk
|
32
32
|
path = ([:layout, :repo].include?(page) ? Paths[:templates] : Paths[:pages])
|
33
|
-
|
33
|
+
config[:to_html].call(path, page, binding)
|
34
34
|
end
|
35
35
|
|
36
36
|
def markdown text
|
@@ -87,7 +87,7 @@ module Toto
|
|
87
87
|
Article.new article, @config
|
88
88
|
end : []
|
89
89
|
|
90
|
-
return :archives => Archives.new(entries)
|
90
|
+
return :archives => Archives.new(entries, @config)
|
91
91
|
end
|
92
92
|
|
93
93
|
def article route
|
@@ -165,7 +165,7 @@ module Toto
|
|
165
165
|
end
|
166
166
|
|
167
167
|
def render page, type
|
168
|
-
type == :html ? to_html(:layout, &Proc.new { to_html page }) : send(:"to_#{type}", :feed)
|
168
|
+
type == :html ? to_html(:layout, @config, &Proc.new { to_html page, @config }) : send(:"to_#{type}", :feed)
|
169
169
|
end
|
170
170
|
|
171
171
|
def to_xml page
|
@@ -201,12 +201,17 @@ module Toto
|
|
201
201
|
class Archives < Array
|
202
202
|
include Template
|
203
203
|
|
204
|
-
def initialize articles
|
204
|
+
def initialize articles, config
|
205
205
|
self.replace articles
|
206
|
+
@config = config
|
207
|
+
end
|
208
|
+
|
209
|
+
def [] a
|
210
|
+
a.is_a?(Range) ? self.class.new(self.slice(a) || [], @config) : super
|
206
211
|
end
|
207
212
|
|
208
213
|
def to_html
|
209
|
-
super(:archives)
|
214
|
+
super(:archives, @config)
|
210
215
|
end
|
211
216
|
alias :to_s to_html
|
212
217
|
alias :archive archives
|
@@ -263,10 +268,10 @@ module Toto
|
|
263
268
|
end
|
264
269
|
|
265
270
|
def title() self[:title] || "an article" end
|
266
|
-
def date() @config[:date
|
271
|
+
def date() @config[:date].call(self[:date]) end
|
267
272
|
def path() self[:date].strftime("/%Y/%m/%d/#{slug}/") end
|
268
273
|
def author() self[:author] || @config[:author] end
|
269
|
-
def to_html() self.load; super(:article)
|
274
|
+
def to_html() self.load; super(:article, @config) end
|
270
275
|
|
271
276
|
alias :to_s to_html
|
272
277
|
|
@@ -274,17 +279,20 @@ module Toto
|
|
274
279
|
|
275
280
|
class Config < Hash
|
276
281
|
Defaults = {
|
277
|
-
:author => ENV['USER'],
|
278
|
-
:title => Dir.pwd.split('/').last,
|
279
|
-
:root => "index",
|
282
|
+
:author => ENV['USER'], # blog author
|
283
|
+
:title => Dir.pwd.split('/').last, # site title
|
284
|
+
:root => "index", # site index
|
280
285
|
:url => "http://127.0.0.1",
|
281
|
-
:date => lambda {|now| now.strftime("%d/%m/%Y") },
|
282
|
-
:markdown => :smart,
|
283
|
-
:disqus => false,
|
284
|
-
:summary => {:max => 150, :delim => /~\n/},
|
285
|
-
:ext => 'txt',
|
286
|
-
:cache => 28800,
|
287
|
-
:github => {:user => "", :repos => [], :ext => 'md'}# Github username and list of repos
|
286
|
+
:date => lambda {|now| now.strftime("%d/%m/%Y") }, # date function
|
287
|
+
:markdown => :smart, # use markdown
|
288
|
+
:disqus => false, # disqus name
|
289
|
+
:summary => {:max => 150, :delim => /~\n/}, # length of summary and delimiter
|
290
|
+
:ext => 'txt', # extension for articles
|
291
|
+
:cache => 28800, # cache duration (seconds)
|
292
|
+
:github => {:user => "", :repos => [], :ext => 'md'}, # Github username and list of repos
|
293
|
+
:to_html => lambda {|path, page, ctx| # returns an html, from a path & context
|
294
|
+
ERB.new(File.read("#{path}/#{page}.rhtml")).result(ctx)
|
295
|
+
}
|
288
296
|
}
|
289
297
|
def initialize obj
|
290
298
|
self.update Defaults
|
@@ -298,11 +306,6 @@ module Toto
|
|
298
306
|
self[key] = val
|
299
307
|
end
|
300
308
|
end
|
301
|
-
|
302
|
-
def [] key, *args
|
303
|
-
val = super(key)
|
304
|
-
val.respond_to?(:call) ? val.call(*args) : val
|
305
|
-
end
|
306
309
|
end
|
307
310
|
|
308
311
|
class Server
|
data/test/toto_test.rb
CHANGED
@@ -27,6 +27,21 @@ context Toto do
|
|
27
27
|
asserts("body is not empty") { not topic.body.empty? }
|
28
28
|
asserts("returns a 200") { topic.status }.equals 200
|
29
29
|
end
|
30
|
+
|
31
|
+
context "with a user-defined to_html" do
|
32
|
+
setup do
|
33
|
+
@config[:to_html] = lambda do |path, page, binding|
|
34
|
+
ERB.new(File.read("#{path}/#{page}.rhtml")).result(binding)
|
35
|
+
end
|
36
|
+
@toto.get('/')
|
37
|
+
end
|
38
|
+
|
39
|
+
asserts("returns a 200") { topic.status }.equals 200
|
40
|
+
asserts("body is not empty") { not topic.body.empty? }
|
41
|
+
asserts("content type is set properly") { topic.content_type }.equals "text/html"
|
42
|
+
should("include a couple of article") { topic.body }.includes_elements("#articles li", 3)
|
43
|
+
should("include an archive") { topic.body }.includes_elements("#archives li", 2)
|
44
|
+
end
|
30
45
|
end
|
31
46
|
|
32
47
|
context "GET /about" do
|
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.
|
8
|
+
s.version = "0.4.0"
|
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-02-
|
12
|
+
s.date = %q{2010-02-17}
|
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
|
+
version: 0.4.0
|
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-02-
|
12
|
+
date: 2010-02-17 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|