lib/toto.rb in ceilingfish-toto-0.3.9 vs lib/toto.rb in ceilingfish-toto-0.4.0
- old
+ new
@@ -66,24 +66,24 @@
include ConfigHelpers
def archives filter = ""
entries = ! self.articles.empty??
self.articles.select do |a|
- filter !~ /^\d{4}/ || File.basename(a) =~ /^#{filter}/
- end.reverse.map do |article|
- Article.new File.new(article), @config
+ filter !~ /^\d{4}/ || a.path =~ /^\/#{filter}/
end : []
return Archives.new(entries)
end
def title
self[:title]
end
def articles ext = self[:ext]
- Dir["#{Paths[:articles]}/*.#{ext}"]
+ Dir["#{Paths[:articles]}/*.#{ext}"].reverse.map do |article|
+ Article.new File.new(article), @config
+ end
end
def root
self[:root]
end
@@ -102,28 +102,28 @@
end
def index type = :html
case type
when :html
- {:articles => articles.reverse.map do |article|
- Article.new File.new(article), @config
- end }.merge(:archives => archives)
+ {:articles => articles, :archives => archives }
when :xml, :json
- return :articles => articles.map do |article|
- Article.new File.new(article), @config
- end
+ return :articles => articles
else return {}
end
end
def article route
- Article.new(File.new("#{Paths[:articles]}/#{route.join('-')}.#{self[:ext]}"), @config).load
+ Article.new(File.new("#{Paths[:articles]}/#{route}.#{self[:ext]}"), @config).load
end
def /
self[:root]
end
+
+ def is_root?(path)
+ path == '/'
+ end
def go route, type = :html
route << self./ if route.empty?
type, path = type =~ /html|xml|json/ ? type.to_sym : :html, route.join('/')
context = lambda do |data, page|
@@ -132,17 +132,18 @@
body, status = if Context.new.respond_to?(:"to_#{type}")
if route.first =~ /\d{4}/
case route.size
when 1..3
- context[{:archives => archives(route * '-')}, :archives]
+ route.pop if route.last == 'archives'
+ context[{:archives => archives(route * '/')}, :archives]
when 4
- context[article(route), :article]
+ context[article(route.last), :article]
else http 400
end
- elsif respond_to?(path)
- context[send(path, type), path.to_sym]
+ elsif is_root?(path)
+ context[send(@config[:root], type), path.to_sym]
elsif (repo = @config[:github][:repos].grep(/#{path}/).first) &&
!@config[:github][:user].empty?
context[Repo.new(repo, @config), :repo]
else
context[{}, path.to_sym]
@@ -167,12 +168,10 @@
include Template
include PageHelpers
def initialize ctx = {}, config = {}, path = "/"
@config, @context, @path = config, ctx, path
- @articles = articles(@config[:ext]).reverse.map do |a|
- Article.new(File.new(a), @config)
- end
+ @articles = articles
ctx.each do |k, v|
meta_def(k) { ctx.instance_of?(Hash) ? v : ctx.send(k) }
end
end