diff --git a/README b/README new file mode 100644 index 0000000..f50c0ff --- /dev/null +++ b/README @@ -0,0 +1,4 @@ +Toopaste +======== + +A simple (and tiny) Pastie clone written using Sinatra and DataMapper. diff --git a/toopaste.rb b/toopaste.rb new file mode 100644 index 0000000..3c0b047 --- /dev/null +++ b/toopaste.rb @@ -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 + "