Skip to content

Instantly share code, notes, and snippets.

@agarzola
Created January 6, 2014 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agarzola/8290931 to your computer and use it in GitHub Desktop.
Save agarzola/8290931 to your computer and use it in GitHub Desktop.
# Use the app.rb file to load Ruby code, modify or extend the models, or
# do whatever else you fancy when the theme is loaded.
module Nesta
class App
# Uncomment the Rack::Static line below if your theme has assets
# (i.e images or JavaScript).
#
# Put your assets in themes/v2/public/v2.
#
use Rack::Static, :urls => ["/v2"], :root => "themes/v2/public"
helpers do
# Add new helpers here.
end
require 'slim'
set :slim, { :format => :html5, :pretty => true }
not_found do
set_common_variables
slim(:not_found)
end
error do
set_common_variables
slim(:error)
end unless Nesta::App.development?
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 slim(: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 slim(:sitemap, :format => :xhtml, :layout => false)
end
get '*' do
set_common_variables
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
set_from_page(:description, :keywords)
cache slim(@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