Syntax highlighting support

This commit is contained in:
Gregory Eremin
2013-07-10 19:02:19 +07:00
parent 0a455e2b3e
commit df03286266
8 changed files with 103 additions and 10 deletions
+1 -1
View File
@@ -10,6 +10,6 @@ $ ->
$contents.focus()
# Binding submit event to new button
$button.on 'click', ->
$button.on 'mouseup', ->
$form.submit()
false
+10 -2
View File
@@ -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
View File
@@ -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