Skip to content

Instantly share code, notes, and snippets.

require 'sinatra'
get '/' do
erb :"pages/index"
end
<!DOCTYPE html>
<html>
<head>
<title>HTML5</title>
</head>
<body>
Content here...
</body>
</html>
@andyhawthorne
andyhawthorne / sinatra_simple.rb
Created August 26, 2012 19:59
Basic Sinatra file
require 'sinatra'
get '/' do
"Hello, World!"
end
@andyhawthorne
andyhawthorne / index.erb
Created August 26, 2012 20:32
Basic erb file
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<meta name="description" content="" />
<meta name="keywords" content="" />
</head>
<body>
@andyhawthorne
andyhawthorne / sinatra_erb_example.rb
Created August 26, 2012 20:43
Sinatra method with instance variable
get '/' do
@time = Time.new
erb :index
end
@andyhawthorne
andyhawthorne / get_files.rb
Created August 26, 2012 22:35
method for listing files
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
@andyhawthorne
andyhawthorne / index.rb
Created August 26, 2012 22:47
blog index
get '/' do
@arr = get_files('./views/posts/')
erb :index
end
@andyhawthorne
andyhawthorne / posts_list.erb
Created August 26, 2012 22:49
list of posts
<ul>
<% @arr.each do |page| %>
<li><a href="/view/<%=page%>"><%=page %></a></li>
<% end %>
</ul>
@andyhawthorne
andyhawthorne / about.rb
Created August 27, 2012 10:08
Sinatra about page
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
@andyhawthorne
andyhawthorne / helper.rb
Created August 27, 2012 10:57
Sinatra helper
helpers do
def formatter(page)
formatted = ""
formatted = page.gsub(/[-]/, ' ').capitalize
return formatted
end
end