Skip to content

Commit

Permalink
Add updated ruby file, views and new README.
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveEveritt committed Jan 17, 2010
1 parent 107df41 commit e7ca870
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 17 deletions.
8 changes: 7 additions & 1 deletion README
@@ -1,4 +1,10 @@
Toopaste
========

A simple (and tiny) Pastie clone written using Sinatra and DataMapper.
A simple (and tiny) Pastie clone written by Nick Plante using Sinatra and DataMapper.

This version has been modified by Dave Everitt as follows:

- updated Snippet DataMapper model replaces deprecated :serial and :nullable
- Snippet 'title' field added, with modified view
- subtle changes to CSS
26 changes: 16 additions & 10 deletions toopaste.rb 100644 → 100755
@@ -1,3 +1,5 @@
#!/usr/local/bin/ruby -rubygems

require 'sinatra'
require 'dm-core'
require 'dm-validations'
Expand All @@ -9,22 +11,25 @@
class Snippet
include DataMapper::Resource

property :id, Integer, :serial => true # primary serial key
property :body, Text, :nullable => false # cannot be null
property :id, Serial # primary serial key
property :title, String, :required => true, :length => 32
property :body, Text, :required => true
property :created_at, DateTime
property :updated_at, DateTime
#validates_present :body
#validates_length :body, :minimum => 1

# 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>"
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

Expand All @@ -38,7 +43,8 @@ def formatted_body

# create
post '/' do
@snippet = Snippet.new(:body => params[:snippet_body])
@snippet = Snippet.new(:title => params[:snippet_title],
:body => params[:snippet_body])
if @snippet.save
redirect "/#{@snippet.id}"
else
Expand Down
5 changes: 3 additions & 2 deletions views/layout.erb 100644 → 100755
Expand Up @@ -3,14 +3,15 @@
<head>
<title><%= @title || 'Toopaste!' %></title>
<style>
html {
body {
background-color: #eee;
font-family: "Trebuchet MS", verdana, tahoma, arial, sans-serif;
}
.snippet {
margin: 5px;
}
.snippet textarea, .snippet .sbody {
border: 5px dotted #eee;
border: 2px dotted #eee;
padding: 5px;
width: 700px;
color: #fff;
Expand Down
5 changes: 4 additions & 1 deletion views/new.erb 100644 → 100755
@@ -1,6 +1,9 @@
<div class="snippet">
<h1>Paste a new code snippet below:</h1>
<form action="/" method="POST">
<p><label for="name">Title: </label><input type="text" name="snippet_title" /></p>
<textarea name="snippet_body" id="snippet_body" rows="20"></textarea>
<br/><input type="submit" value="Save"/>
<br/>
<input type="submit" value="Save"/>
</form>
</div>
12 changes: 9 additions & 3 deletions views/show.erb 100644 → 100755
@@ -1,5 +1,11 @@
<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>
<h1><%= @snippet.title %></h1>
<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="/">Create new paste!</a>
</div>

0 comments on commit e7ca870

Please sign in to comment.