Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/cloudhead/toto
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudhead committed Feb 18, 2010
2 parents dab5291 + dd106ad commit 7f262d8
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 27 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ the tiniest blogging engine in Oz!
introduction
------------

toto is a git-powered, minimalist blog engine for the hackers of Oz. The engine weights around ~300 sloc at its worse.
toto is a git-powered, minimalist blog engine for the hackers of Oz. The engine weighs around ~300 sloc at its worse.
There is no toto client, at least for now; everything goes through git.

blog in 10 seconds
Expand Down Expand Up @@ -142,6 +142,9 @@ you could add `set :author, 'John Galt'` inside the `Toto::Server.new` block. He
set :summary, :max => 150, :delim => /~\n/ # length of article summary and delimiter
set :ext, 'txt' # file extension for articles
set :cache, 28800 # cache site for 8 hours
set :to_html, lambda {|path, page, ctx| # returns an html, from a path & context
ERB.new(File.read("#{path}/#{page}.rhtml")).result(ctx)
}

thanks
------
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.2
0.4.0
49 changes: 26 additions & 23 deletions lib/toto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def self.env= env
end

module Template
def to_html page, &blk
def to_html page, config, &blk
path = ([:layout, :repo].include?(page) ? Paths[:templates] : Paths[:pages])
ERB.new(File.read("#{path}/#{page}.rhtml")).result(binding)
config[:to_html].call(path, page, binding)
end

def markdown text
Expand Down Expand Up @@ -87,7 +87,7 @@ def archives filter = ""
Article.new article, @config
end : []

return :archives => Archives.new(entries)
return :archives => Archives.new(entries, @config)
end

def article route
Expand Down Expand Up @@ -165,7 +165,7 @@ def title
end

def render page, type
type == :html ? to_html(:layout, &Proc.new { to_html page }) : send(:"to_#{type}", :feed)
type == :html ? to_html(:layout, @config, &Proc.new { to_html page, @config }) : send(:"to_#{type}", :feed)
end

def to_xml page
Expand Down Expand Up @@ -201,12 +201,17 @@ def readme
class Archives < Array
include Template

def initialize articles
def initialize articles, config
self.replace articles
@config = config
end

def [] a
a.is_a?(Range) ? self.class.new(self.slice(a) || [], @config) : super
end

def to_html
super(:archives)
super(:archives, @config)
end
alias :to_s to_html
alias :archive archives
Expand Down Expand Up @@ -263,28 +268,31 @@ def body
end

def title() self[:title] || "an article" end
def date() @config[:date, self[:date]] end
def date() @config[:date].call(self[:date]) end
def path() self[:date].strftime("/%Y/%m/%d/#{slug}/") end
def author() self[:author] || @config[:author] end
def to_html() self.load; super(:article) end
def to_html() self.load; super(:article, @config) end

alias :to_s to_html

end

class Config < Hash
Defaults = {
:author => ENV['USER'], # blog author
:title => Dir.pwd.split('/').last, # site title
:root => "index", # site index
:author => ENV['USER'], # blog author
:title => Dir.pwd.split('/').last, # site title
:root => "index", # site index
:url => "http://127.0.0.1",
:date => lambda {|now| now.strftime("%d/%m/%Y") }, # date function
:markdown => :smart, # use markdown
:disqus => false, # disqus name
:summary => {:max => 150, :delim => /~\n/}, # length of summary and delimiter
:ext => 'txt', # extension for articles
:cache => 28800, # cache duration (seconds)
:github => {:user => "", :repos => [], :ext => 'md'}# Github username and list of repos
:date => lambda {|now| now.strftime("%d/%m/%Y") }, # date function
:markdown => :smart, # use markdown
:disqus => false, # disqus name
:summary => {:max => 150, :delim => /~\n/}, # length of summary and delimiter
:ext => 'txt', # extension for articles
:cache => 28800, # cache duration (seconds)
:github => {:user => "", :repos => [], :ext => 'md'}, # Github username and list of repos
:to_html => lambda {|path, page, ctx| # returns an html, from a path & context
ERB.new(File.read("#{path}/#{page}.rhtml")).result(ctx)
}
}
def initialize obj
self.update Defaults
Expand All @@ -298,11 +306,6 @@ def set key, val
self[key] = val
end
end

def [] key, *args
val = super(key)
val.respond_to?(:call) ? val.call(*args) : val
end
end

class Server
Expand Down
15 changes: 15 additions & 0 deletions test/toto_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@
asserts("body is not empty") { not topic.body.empty? }
asserts("returns a 200") { topic.status }.equals 200
end

context "with a user-defined to_html" do
setup do
@config[:to_html] = lambda do |path, page, binding|
ERB.new(File.read("#{path}/#{page}.rhtml")).result(binding)
end
@toto.get('/')
end

asserts("returns a 200") { topic.status }.equals 200
asserts("body is not empty") { not topic.body.empty? }
asserts("content type is set properly") { topic.content_type }.equals "text/html"
should("include a couple of article") { topic.body }.includes_elements("#articles li", 3)
should("include an archive") { topic.body }.includes_elements("#archives li", 2)
end
end

context "GET /about" do
Expand Down
4 changes: 2 additions & 2 deletions toto.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

Gem::Specification.new do |s|
s.name = %q{toto}
s.version = "0.3.2"
s.version = "0.4.0"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["cloudhead"]
s.date = %q{2010-02-09}
s.date = %q{2010-02-17}
s.description = %q{the tiniest blog-engine in Oz.}
s.email = %q{[email protected]}
s.extra_rdoc_files = [
Expand Down

0 comments on commit 7f262d8

Please sign in to comment.