Created
August 27, 2012 11:11
-
-
Save andyhawthorne/3487531 to your computer and use it in GitHub Desktop.
Completed blog file
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
require 'sinatra' | |
require 'find' | |
require 'rdiscount' | |
def get_files(path) | |
dir_list_array = Array.new | |
Find.find(path) do |f| | |
dir_list_array << File.basename(f, ".*") if !File.directory?(f) | |
end | |
return dir_list_array | |
end | |
helpers do | |
def formatter(page) | |
formatted = "" | |
formatted = page.gsub(/[-]/, ' ').capitalize | |
return formatted | |
end | |
end | |
get '/' do | |
@arr = get_files('./views/posts/') | |
erb :index | |
end | |
get '/view/:link' do | |
halt 404 unless File.exist?("views/posts/#{params[:link]}.md") | |
markdown :"posts/#{params[:link]}", :layout_engine => :erb | |
end | |
get '/about' do | |
#if you don't want to use Markdown for pages, do this: | |
#erb :"pages/about" | |
#Then create about.erb in views/pages | |
markdown :"pages/about", :layout_engine => :erb | |
end | |
not_found do | |
erb :missing | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment