Syntax highlighting support
This commit is contained in:
@@ -10,6 +10,6 @@ $ ->
|
||||
$contents.focus()
|
||||
|
||||
# Binding submit event to new button
|
||||
$button.on 'click', ->
|
||||
$button.on 'mouseup', ->
|
||||
$form.submit()
|
||||
false
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
body, input, select {
|
||||
font-family: Helvetica, Arial, sans-serif;
|
||||
font-size: 1.2em;
|
||||
font-size: 1em;
|
||||
}
|
||||
textarea, pre {
|
||||
font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;
|
||||
font-size: 1.2em;
|
||||
font-size: 1em;
|
||||
}
|
||||
html, body, form {
|
||||
height: 100%;
|
||||
@@ -27,6 +27,14 @@ h1 {
|
||||
text-transform: uppercase;
|
||||
color: #ccc;
|
||||
}
|
||||
.linenos {
|
||||
padding-right: .5em;
|
||||
color: #ccc;
|
||||
border-right: #eee 1px solid;
|
||||
}
|
||||
.code {
|
||||
padding-left: .5em;
|
||||
}
|
||||
|
||||
.container {
|
||||
width: 100%;
|
||||
|
||||
+17
-4
@@ -1,20 +1,21 @@
|
||||
class Paste
|
||||
attr_reader :contents
|
||||
attr_reader :contents, :type
|
||||
|
||||
class << self
|
||||
def find(id)
|
||||
record = DB[:pastes].where(id: id).first
|
||||
record ? new(record[:contents]) : nil
|
||||
record ? new(record[:contents], record[:type]) : nil
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(contents)
|
||||
def initialize(contents, type = nil)
|
||||
@contents = contents
|
||||
@type = type
|
||||
end
|
||||
|
||||
def save
|
||||
encrypt!
|
||||
DB[:pastes].insert(contents: contents)
|
||||
DB[:pastes].insert(contents: contents, type: type)
|
||||
end
|
||||
|
||||
def decrypt(key)
|
||||
@@ -34,4 +35,16 @@ class Paste
|
||||
def decrypt!
|
||||
@contents = Encryptor.decrypt(value: Base64.decode64(contents), key: key)
|
||||
end
|
||||
|
||||
def highlighted
|
||||
Pygments.highlight(@contents, lexer: 'ruby', options: { linenos: 'table' })
|
||||
end
|
||||
|
||||
def paragraph
|
||||
"<pre>#{@contents}</pre>"
|
||||
end
|
||||
|
||||
def html
|
||||
type ? highlighted : paragraph
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user