lib/serious.rb in serious-0.2.2 vs lib/serious.rb in serious-0.2.3
- old
+ new
@@ -8,10 +8,11 @@
require 'ruby_ext'
class Serious < Sinatra::Base
set :articles, Proc.new { File.join(Dir.getwd, 'articles') }
+ set :pages, Proc.new { File.join(Dir.getwd, 'pages') }
set :static, true # Required to serve static files, see http://www.sinatrarb.com/configuration.html
not_found do
erb :"404"
end
@@ -53,21 +54,35 @@
render_article @article
end
# Archives route
get %r{^/(\d{4})[/]{0,1}(\d{0,2})[/]{0,1}(\d{0,2})[/]{0,1}$} do
- @selection = params[:captures].reject {|s| s.strip.length == 0 }.map {|n| n.length == 1 ? "%02d" % n : n}
- @articles = Article.find(*@selection)
+ selection = params[:captures].reject {|s| s.strip.length == 0 }.map {|n| n.length == 1 ? "%02d" % n : n}
+ @articles = Article.find(*selection)
+ @title = "Archives for #{selection.join("-")}"
erb :archives
end
get "/archives" do
@articles = Article.all
+ @title = "Archives"
erb :archives
end
+
+ get "/pages" do
+ @articles = Page.all
+ @title = "Pages"
+ erb :archives
+ end
+
+ get "/pages/:page" do
+ halt 404 unless @article = Page.find(params[:page])
+ render_article @article
+ end
end
require 'serious/article'
+require 'serious/page'
# Set up default stupid_formatter chain
StupidFormatter.chain = [StupidFormatter::Erb, StupidFormatter::RDiscount]
# Set up defaults for app
Serious.set :root, File.join(File.dirname(__FILE__), 'site')