Created
July 20, 2011 15:57
-
-
Save gma/1095235 to your computer and use it in GitHub Desktop.
app.rb for legibilis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Nesta | |
class App | |
get '/robots.txt' do | |
content_type 'text/plain', :charset => 'utf-8' | |
<<-EOF | |
# robots.txt | |
# See http://en.wikipedia.org/wiki/Robots_exclusion_standard | |
EOF | |
end | |
get '/css/:sheet.css' do | |
content_type 'text/css', :charset => 'utf-8' | |
cache sass(params[:sheet].to_sym) | |
end | |
get %r{/attachments/([\w/.-]+)} do | |
file = File.join(Nesta::Config.attachment_path, params[:captures].first) | |
send_file(file, :disposition => nil) | |
end | |
get '/articles.xml' do | |
content_type :xml, :charset => 'utf-8' | |
set_from_config(:title, :subtitle, :author) | |
@articles = Page.find_articles.select { |a| a.date }[0..9] | |
cache haml(:atom, :format => :xhtml, :layout => false) | |
end | |
get '/sitemap.xml' do | |
content_type :xml, :charset => 'utf-8' | |
@pages = Page.find_all | |
@last = @pages.map { |page| page.last_modified }.inject do |latest, page| | |
(page > latest) ? page : latest | |
end | |
cache haml(:sitemap, :format => :xhtml, :layout => false) | |
end | |
get '*' do | |
set_common_variables | |
@heading = @title | |
parts = params[:splat].map { |p| p.sub(/\/$/, '') } | |
@page = Nesta::Page.find_by_path(File.join(parts)) | |
raise Sinatra::NotFound if @page.nil? | |
@title = @page.title | |
@body_class = @page.date.nil ? 'page' : 'article' | |
@body_class = "foo" | |
set_from_page(:description, :keywords) | |
cache haml(@page.template, :layout => @page.layout) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment