Permalink
Browse files

changed to a pastie type app

  • Loading branch information...
1 parent 592d0f4 commit 7bd33a0c01bc5cf93c8a68a5317565a3695e6ff5 @jgwmaxwell committed Dec 30, 2011
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
@@ -0,0 +1 @@
+1325277109
View
@@ -0,0 +1 @@
+25046: Locked by 25046 at Fri Dec 30 20:22:03 +0000 2011
View
@@ -0,0 +1,25 @@
+1325277109
+App /home/john/TestRuby/testapp/app.rb class App
+BACKENDS /home/john/TestRuby/testapp/proxy.rb BACKENDS =
+Backend /home/john/TestRuby/testapp/proxy.rb class Backend
+BalancingProxy /home/john/TestRuby/testapp/proxy.rb module BalancingProxy
+Callbacks /home/john/TestRuby/testapp/proxy.rb module Callbacks
+Proxy /home/john/TestRuby/testapp/proxy.rb class Proxy
+Server /home/john/TestRuby/testapp/proxy.rb module Server
+Snippet /home/john/TestRuby/testapp/app.rb class Snippet
+decrement_counter /home/john/TestRuby/testapp/proxy.rb def decrement_counter
+formatted_body /home/john/TestRuby/testapp/app.rb def formatted_body
+increment_counter /home/john/TestRuby/testapp/proxy.rb def increment_counter
+initialize /home/john/TestRuby/testapp/proxy.rb def initialize(options={})
+list /home/john/TestRuby/testapp/proxy.rb def self.list
+load /home/john/TestRuby/testapp/proxy.rb attr_accessor :load
+on_connect /home/john/TestRuby/testapp/proxy.rb def on_connect
+on_data /home/john/TestRuby/testapp/proxy.rb def on_data
+on_finish /home/john/TestRuby/testapp/proxy.rb def on_finish
+on_response /home/john/TestRuby/testapp/proxy.rb def on_response
+on_select /home/john/TestRuby/testapp/proxy.rb def on_select
+run /home/john/TestRuby/testapp/proxy.rb def run(host='0.0.0.0')
+select /home/john/TestRuby/testapp/proxy.rb def self.select(strategy = :balanced)
+socket /home/john/TestRuby/testapp/proxy.rb attr_reader :socket
+stop /home/john/TestRuby/testapp/proxy.rb def self.stop
+strategy /home/john/TestRuby/testapp/proxy.rb def self.strategy
View
@@ -2,4 +2,7 @@ source :rubygems
gem 'em-proxy', :git => "git://github.com/jgwmaxwell/em-proxy.git"
gem 'sinatra'
-gem 'thin'
+gem 'thin'
+
+gem 'mongo'
+gem 'syntaxi'
View
56 app.rb
@@ -1,10 +1,62 @@
require 'sinatra'
+require 'syntaxi'
+
+Mongoid.configure do |config|
+ config.master = Mongo::Connection.new.db(ENV['MONGOLAB_URI'])
+end
+
+class Snippet
+ include Mongoid::Document
+ include Mongoid::Timestamps
+
+
+ field :id, type: String
+ field :title, type: String
+ field :body, type: String
+
+ validates_presence_of :body
+ validates_length_of :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
class App < Sinatra::Base
+
get '/' do
- @title = "This is the title!\n Hello there World!"
- erb :index
+ erb :new
+ end
+
+ # create
+ post '/' do
+ snippet = Snippet.new(:title => params[:snippet_title],
+ :body => params[:snippet_body])
+ if snippet.save
+ redirect "/#{snippet.id}"
+ else
+ redirect '/'
+ end
end
+
+ # show
+ get '/:id' do
+ @snippet = Snippet.find(params[:id])
+ if @snippet
+ erb :show
+ else
+ redirect '/'
+ end
+ end
+
end
View
@@ -5,7 +5,7 @@ Bundler.require(:default)
$port = ARGV.first
ROOT = File.expand_path(File.dirname(File.dirname(__FILE__)))
-SERVERS = 4
+SERVERS = 3
require './app'
View
@@ -0,0 +1,64 @@
+<!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>
+ body {
+ background-color: #eee;
+ font-family: "Trebuchet MS", verdana, tahoma, arial, sans-serif;
+ }
+ .snippet {
+ margin: 5px;
+ }
+ .snippet textarea, .snippet .sbody {
+ border: 2px 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>
View
@@ -0,0 +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"/>
+ </form>
+</div>
View
@@ -0,0 +1,11 @@
+<div class="snippet">
+ <h1><%= @snippet.title %></h1>
+ <div class="sbody" id="content">
+ <%= @snippet.formatted_body %>
+ </div>
+ <div class="sdate">
+ Created on <%= @snippet.created_at.strftime("%D at %T %Z") %>
+ </div>
+ <br/>
+ <a href="/">Create new paste!</a>
+</div>

0 comments on commit 7bd33a0

Please sign in to comment.