Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d2fa3b6
Showing
5 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Toopaste | ||
======== | ||
|
||
A simple (and tiny) Pastie clone written using Sinatra and DataMapper. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require 'sinatra' | ||
require 'dm-core' | ||
require 'dm-validations' | ||
require 'dm-timestamps' | ||
require 'syntaxi' | ||
|
||
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/toopaste.sqlite3") | ||
|
||
class Snippet | ||
include DataMapper::Resource | ||
|
||
property :id, Integer, :serial => true # primary serial key | ||
property :body, Text, :nullable => false # cannot be null | ||
property :created_at, DateTime | ||
property :updated_at, DateTime | ||
|
||
validates_present :body | ||
validates_length :body, :minimum => 1 | ||
|
||
Syntaxi.line_number_method = 'floating' | ||
Syntaxi.wrap_at_column = 80 | ||
#Syntaxi.wrap_enabled = false | ||
|
||
def formatted_body | ||
replacer = Time.now.strftime('[code-%d]') | ||
html = Syntaxi.new("[code lang='ruby']#{self.body.gsub('[/code]', replacer)}[/code]").process | ||
"<div class=\"syntax syntax_ruby\">#{html.gsub(replacer, '[/code]')}</div>" | ||
end | ||
end | ||
|
||
DataMapper.auto_upgrade! | ||
#File.open('toopaste.pid', 'w') { |f| f.write(Process.pid) } | ||
|
||
# new | ||
get '/' do | ||
erb :new | ||
end | ||
|
||
# create | ||
post '/' do | ||
@snippet = Snippet.new(:body => params[:snippet_body]) | ||
if @snippet.save | ||
redirect "/#{@snippet.id}" | ||
else | ||
redirect '/' | ||
end | ||
end | ||
|
||
# show | ||
get '/:id' do | ||
@snippet = Snippet.get(params[:id]) | ||
erb :show | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<title><%= @title || 'Toopaste!' %></title> | ||
<style> | ||
html { | ||
background-color: #eee; | ||
} | ||
.snippet { | ||
margin: 5px; | ||
} | ||
.snippet textarea, .snippet .sbody { | ||
border: 5px dotted #eee; | ||
padding: 5px; | ||
width: 700px; | ||
color: #fff; | ||
background-color: #333; | ||
} | ||
.snippet textarea { | ||
padding: 20px; | ||
} | ||
.snippet input, .snippet .sdate { | ||
margin-top: 5px; | ||
} | ||
|
||
/* Syntax highlighting */ | ||
#content .syntax_ruby .normal {} | ||
#content .syntax_ruby .comment { color: #CCC; font-style: italic; border: none; margin: none; } | ||
#content .syntax_ruby .keyword { color: #C60; font-weight: bold; } | ||
#content .syntax_ruby .method { color: #9FF; } | ||
#content .syntax_ruby .class { color: #074; } | ||
#content .syntax_ruby .module { color: #050; } | ||
#content .syntax_ruby .punct { color: #0D0; font-weight: bold; } | ||
#content .syntax_ruby .symbol { color: #099; } | ||
#content .syntax_ruby .string { color: #C03; } | ||
#content .syntax_ruby .char { color: #F07; } | ||
#content .syntax_ruby .ident { color: #0D0; } | ||
#content .syntax_ruby .constant { color: #07F; } | ||
#content .syntax_ruby .regex { color: #B66; } | ||
#content .syntax_ruby .number { color: #FF0; } | ||
#content .syntax_ruby .attribute { color: #7BB; } | ||
#content .syntax_ruby .global { color: #7FB; } | ||
#content .syntax_ruby .expr { color: #909; } | ||
#content .syntax_ruby .escape { color: #277; } | ||
#content .syntax { | ||
background-color: #333; | ||
padding: 2px; | ||
margin: 5px; | ||
margin-left: 1em; | ||
margin-bottom: 1em; | ||
} | ||
#content .syntax .line_number { | ||
text-align: right; | ||
font-family: monospace; | ||
padding-right: 1em; | ||
color: #999; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<%= yield %> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div class="snippet"> | ||
<form action="/" method="POST"> | ||
<textarea name="snippet_body" id="snippet_body" rows="20"></textarea> | ||
<br/><input type="submit" value="Save"/> | ||
</form> | ||
</div> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div class="snippet"> | ||
<div class="sbody" id="content"><%= @snippet.formatted_body %></div> | ||
<div class="sdate">Created on <%= @snippet.created_at.strftime("%B %d, %Y at %I:%M %p") %></div> | ||
<br/><a href="/">New Paste!</a> | ||
</div> |