1
0
Fork 0

Renamed type field to syntax

This commit is contained in:
Gregory Eremin 2013-07-11 02:16:26 +07:00
parent 999509d17f
commit 2107e76df7
4 changed files with 14 additions and 14 deletions

View File

@ -1,7 +1,7 @@
class Selector
constructor: (selector) ->
@input = $("#{selector}-input")
@dropdown = $(selector)
@dropdown = $("#{selector}-selector")
@placeholder = @dropdown.children 'span'
@prefix = @placeholder.text()
@options = @dropdown.find 'ul.dropdown > li'
@ -29,6 +29,6 @@ class Selector
@input.val value
$ ->
new Selector '#type'
new Selector '#syntax'
$(document).on 'click', (e) ->
$('.wrapper-dropdown').removeClass 'active'

View File

@ -1,21 +1,21 @@
class Paste
attr_reader :contents, :type
attr_reader :contents, :syntax
class << self
def find(id)
record = DB[:pastes].where(id: id).first
record ? new(record[:contents], record[:type]) : nil
record ? new(record[:contents], record[:syntax]) : nil
end
end
def initialize(contents, type = nil)
def initialize(contents, syntax = nil)
@contents = contents
@type = type if CONFIG.available_syntaxes.include?(type)
@syntax = syntax if CONFIG.available_syntaxes.include?(syntax)
end
def save
encrypt!
DB[:pastes].insert(contents: contents, type: type)
DB[:pastes].insert(contents: contents, syntax: syntax)
end
def decrypt(key)
@ -37,7 +37,7 @@ class Paste
end
def highlighted
Pygments.highlight(contents, lexer: type, options: { linenos: 'table' })
Pygments.highlight(contents, lexer: syntax, options: { linenos: 'table' })
end
def paragraph
@ -45,6 +45,6 @@ class Paste
end
def html
type ? highlighted : paragraph
syntax ? highlighted : paragraph
end
end

View File

@ -1,11 +1,11 @@
form action="/" method="post" accept-charset="UTF-8"
textarea name="contents"
input id="type-input" type="hidden" name="type" value=""
div id="type" class="wrapper-dropdown" tabindex="1"
input id="syntax-input" type="hidden" name="syntax" value=""
div id="syntax-selector" class="wrapper-dropdown" tabindex="1"
span Syntax
ul.dropdown
li.selected data-value="" Plain Text
- for code, name in @lexers
- for code, name in @syntaxes
li data-value=code =name
input type="submit" value="Save"
a href="#" role="submit" Save

View File

@ -34,13 +34,13 @@ class Pastemaster < Sinatra::Application
use StylusAssets
get '/' do
@lexers = CONFIG.syntaxes_map
@syntaxes = CONFIG.syntaxes_map
slim :form, layout: :default
end
post '/' do
paste = Paste.new(params[:contents], params[:type])
paste = Paste.new(params[:contents], params[:syntax])
id = paste.save
redirect "/#{id}/#{paste.key}"