Renamed type field to syntax
This commit is contained in:
parent
999509d17f
commit
2107e76df7
@ -1,7 +1,7 @@
|
|||||||
class Selector
|
class Selector
|
||||||
constructor: (selector) ->
|
constructor: (selector) ->
|
||||||
@input = $("#{selector}-input")
|
@input = $("#{selector}-input")
|
||||||
@dropdown = $(selector)
|
@dropdown = $("#{selector}-selector")
|
||||||
@placeholder = @dropdown.children 'span'
|
@placeholder = @dropdown.children 'span'
|
||||||
@prefix = @placeholder.text()
|
@prefix = @placeholder.text()
|
||||||
@options = @dropdown.find 'ul.dropdown > li'
|
@options = @dropdown.find 'ul.dropdown > li'
|
||||||
@ -29,6 +29,6 @@ class Selector
|
|||||||
@input.val value
|
@input.val value
|
||||||
|
|
||||||
$ ->
|
$ ->
|
||||||
new Selector '#type'
|
new Selector '#syntax'
|
||||||
$(document).on 'click', (e) ->
|
$(document).on 'click', (e) ->
|
||||||
$('.wrapper-dropdown').removeClass 'active'
|
$('.wrapper-dropdown').removeClass 'active'
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
class Paste
|
class Paste
|
||||||
attr_reader :contents, :type
|
attr_reader :contents, :syntax
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def find(id)
|
def find(id)
|
||||||
record = DB[:pastes].where(id: id).first
|
record = DB[:pastes].where(id: id).first
|
||||||
record ? new(record[:contents], record[:type]) : nil
|
record ? new(record[:contents], record[:syntax]) : nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(contents, type = nil)
|
def initialize(contents, syntax = nil)
|
||||||
@contents = contents
|
@contents = contents
|
||||||
@type = type if CONFIG.available_syntaxes.include?(type)
|
@syntax = syntax if CONFIG.available_syntaxes.include?(syntax)
|
||||||
end
|
end
|
||||||
|
|
||||||
def save
|
def save
|
||||||
encrypt!
|
encrypt!
|
||||||
DB[:pastes].insert(contents: contents, type: type)
|
DB[:pastes].insert(contents: contents, syntax: syntax)
|
||||||
end
|
end
|
||||||
|
|
||||||
def decrypt(key)
|
def decrypt(key)
|
||||||
@ -37,7 +37,7 @@ class Paste
|
|||||||
end
|
end
|
||||||
|
|
||||||
def highlighted
|
def highlighted
|
||||||
Pygments.highlight(contents, lexer: type, options: { linenos: 'table' })
|
Pygments.highlight(contents, lexer: syntax, options: { linenos: 'table' })
|
||||||
end
|
end
|
||||||
|
|
||||||
def paragraph
|
def paragraph
|
||||||
@ -45,6 +45,6 @@ class Paste
|
|||||||
end
|
end
|
||||||
|
|
||||||
def html
|
def html
|
||||||
type ? highlighted : paragraph
|
syntax ? highlighted : paragraph
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
form action="/" method="post" accept-charset="UTF-8"
|
form action="/" method="post" accept-charset="UTF-8"
|
||||||
textarea name="contents"
|
textarea name="contents"
|
||||||
input id="type-input" type="hidden" name="type" value=""
|
input id="syntax-input" type="hidden" name="syntax" value=""
|
||||||
div id="type" class="wrapper-dropdown" tabindex="1"
|
div id="syntax-selector" class="wrapper-dropdown" tabindex="1"
|
||||||
span Syntax
|
span Syntax
|
||||||
ul.dropdown
|
ul.dropdown
|
||||||
li.selected data-value="" Plain Text
|
li.selected data-value="" Plain Text
|
||||||
- for code, name in @lexers
|
- for code, name in @syntaxes
|
||||||
li data-value=code =name
|
li data-value=code =name
|
||||||
input type="submit" value="Save"
|
input type="submit" value="Save"
|
||||||
a href="#" role="submit" Save
|
a href="#" role="submit" Save
|
||||||
|
@ -34,13 +34,13 @@ class Pastemaster < Sinatra::Application
|
|||||||
use StylusAssets
|
use StylusAssets
|
||||||
|
|
||||||
get '/' do
|
get '/' do
|
||||||
@lexers = CONFIG.syntaxes_map
|
@syntaxes = CONFIG.syntaxes_map
|
||||||
|
|
||||||
slim :form, layout: :default
|
slim :form, layout: :default
|
||||||
end
|
end
|
||||||
|
|
||||||
post '/' do
|
post '/' do
|
||||||
paste = Paste.new(params[:contents], params[:type])
|
paste = Paste.new(params[:contents], params[:syntax])
|
||||||
id = paste.save
|
id = paste.save
|
||||||
|
|
||||||
redirect "/#{id}/#{paste.key}"
|
redirect "/#{id}/#{paste.key}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user