1
0
Fork 0

Organizing

This commit is contained in:
Gregory Eremin 2013-07-11 02:06:16 +07:00
parent e55a6af258
commit 23fee68790
14 changed files with 162 additions and 103 deletions

View File

@ -20,6 +20,7 @@ class Selector
$el.addClass 'selected' $el.addClass 'selected'
self.placeholder.text "#{self.prefix}: #{$el.text()}" self.placeholder.text "#{self.prefix}: #{$el.text()}"
self.setValue $el.data 'value' self.setValue $el.data 'value'
$('textarea').focus()
@options.filter('.selected').click() @options.filter('.selected').click()
@dropdown.removeClass 'active' @dropdown.removeClass 'active'

View File

@ -1,83 +1,81 @@
* { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; } *
-moz-box-sizing border-box
-webkit-box-sizing border-box
box-sizing border-box
body, input, select { body, input, select
font-family: Helvetica, Arial, sans-serif; font-family Helvetica, Arial, sans-serif
font-size: 1em; 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: 1em;
}
html, body, form {
height: 100%;
}
body {
background-color: #fcfcfc;
padding: 3em;
}
h1 {
position: absolute;
top: 1em;
left: 3em;
font-weight: 200;
font-size: 1em;
line-height: 1em;
padding: 0;
margin: 0;
text-transform: uppercase;
color: #ccc;
}
.linenos {
padding-right: .5em;
color: #ccc;
border-right: #eee 1px solid;
}
.code {
padding-left: .5em;
}
.container { textarea, pre
width: 100%; font-family Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif
height: 100%; font-size 1em
}
textarea, input { html, body, form
outline: none; height 100%
}
textarea { body
background-color: #ffffff; background-color #fcfcfc
width: 100%; padding 3em
height: 100%;
line-height: 120%;
resize: none;
border: #ddd 1px solid;
border-radius: 5px;
padding: .5em;
}
form input[type="submit"], form a[role="submit"] { h1
float: right; position absolute
} top 1em
form a[role="submit"] { left 3em
background-color: #fefefe; font-weight 200
background-image: -webkit-linear-gradient(top, #ffffff, #f5f5f5); font-size 1em
background-image: linear-gradient(to bottom, #ffffff, #f5f5f5); line-height 1em
box-shadow: 0 1px 2px 2px #ffffff; padding 0
color: #666; margin 0
text-shadow: 0 0 2px #ffffff; text-transform uppercase
border: #ddd 1px solid; color #ccc
border-radius: 4px;
border-bottom-width: 4px; .linenos
font-size: 1em; padding-right .5em
width: 5em; color #ccc
text-align: center; border-right #eee 1px solid
padding: .4em 0;
margin: .4em 0; .code
text-decoration: none; padding-left .5em
display: none;
} .container
form a[role="submit"]:active { width 100%
box-shadow: 0 0 2px 2px #eee inset; height 100%
border-bottom-width: 1px;
} textarea, input
outline none
textarea
background-color #ffffff
width 100%
height 100%
line-height 120%
resize none
border #ddd 1px solid
border-radius 5px
padding .5em
form input[type="submit"], form a[role="submit"]
float right
form a[role="submit"]
background-color #fefefe
background-image -webkit-linear-gradient(top, #ffffff, #f5f5f5)
background-image linear-gradient(to bottom, #ffffff, #f5f5f5)
box-shadow 0 1px 2px 2px #ffffff
color #666
text-shadow 0 0 2px #ffffff
border #ddd 1px solid
border-radius 4px
border-bottom-width 4px
font-size 1em
width 5em
text-align center
padding .4em 0
margin .4em 0
text-decoration none
display none
&:active
box-shadow 0 0 2px 2px #eee inset
border-bottom-width 1px

View File

@ -1,3 +0,0 @@
CONFIG = {
database_url: 'postgres://pastemaster:pastemaster@localhost:5432/pastemaster'
}

View File

@ -0,0 +1,28 @@
class Configuration
attr_reader :database_url,
:syntaxes_map,
:available_syntaxes
def initialize
load_database_config
load_syntax_config
end
def load_database_config
config = YAML.load_file(APP_ROOT.join('config', 'database.yml'))
@database_url = '%s://%s:%s@%s:%s/%s' % [
config['protocol'],
config['username'],
config['password'],
config['host'],
config['port'],
config['database']
]
end
def load_syntax_config
config = YAML.load_file(APP_ROOT.join('config', 'syntax.yml'))
@syntaxes_map = config
@available_syntaxes = config.keys
end
end

View File

@ -10,7 +10,7 @@ class Paste
def initialize(contents, type = nil) def initialize(contents, type = nil)
@contents = contents @contents = contents
@type = type if available_types.include?(type) @type = type if CONFIG.available_syntaxes.include?(type)
end end
def save def save
@ -47,8 +47,4 @@ class Paste
def html def html
type ? highlighted : paragraph type ? highlighted : paragraph
end end
def available_types
@available_types ||= Pygments::Lexer.all.map(&:aliases).flatten
end
end end

1
config/database.yml Symbolic link
View File

@ -0,0 +1 @@
examples/database.yml

View File

@ -0,0 +1,6 @@
protocol: postgres
username: pastemaster
password: pastemaster
host: localhost
port: 5432
database: pastemaster

View File

@ -0,0 +1,32 @@
actionscript: ActionScript
applescript: AppleScript
awk: Awk
c: C
charp: C#
cpp: C++
clojure: Clojure
coffeescript: CoffeeScript
cl: Common Lisp
d: D
dart: Dart
delphi: Delphi
erlang: Erlang
go: Go
groovy: Groovy
haskell: Haskell
java: Java
javascript: JavaScript
json: JSON
lua: Lua
objc: Objective-C
ocaml: OCaml
perl: Perl
php: PHP
python: Python
ruby: Ruby
rust: Rust
scala: Scala
smalltalk: Smalltalk
vim: VimL
xml: XML
xslt: XSLT

View File

@ -0,0 +1,2 @@
APP_ROOT = Pathname.new(File.expand_path('../../..', __FILE__))
CONFIG = Configuration.new

View File

@ -1,9 +1,9 @@
DB = Sequel.connect(CONFIG[:database_url]) DB = Sequel.connect(CONFIG.database_url)
# DB.drop_table(:pastes) if DB.table_exists?(:pastes) # DB.drop_table(:pastes) if DB.table_exists?(:pastes)
DB.create_table(:pastes) do DB.create_table(:pastes) do
primary_key :id primary_key :id
String :type String :syntax
Text :contents Text :contents
end unless DB.table_exists?(:pastes) end unless DB.table_exists?(:pastes)

1
config/syntax.yml Symbolic link
View File

@ -0,0 +1 @@
examples/syntax.yml

View File

@ -2,6 +2,7 @@ $:.unshift File.dirname(__FILE__)
require 'securerandom' require 'securerandom'
require 'base64' require 'base64'
require 'yaml'
require 'bundler/setup' require 'bundler/setup'
require 'sinatra' require 'sinatra'
@ -13,11 +14,12 @@ require 'stylus'
require 'stylus/tilt' require 'stylus/tilt'
require 'pygments' require 'pygments'
require 'app/models/configuration'
require 'app/models/paste'
require 'config/initializers/configuration'
require 'config/initializers/database'
require 'lib/error_pages' require 'lib/error_pages'
require 'lib/assets' require 'lib/assets'
require 'app/config'
require 'app/database'
require 'app/paste'
class Pastemaster < Sinatra::Application class Pastemaster < Sinatra::Application
set :server, 'unicorn' set :server, 'unicorn'
@ -30,14 +32,8 @@ class Pastemaster < Sinatra::Application
use CoffeeAssets use CoffeeAssets
use StylusAssets use StylusAssets
def fetch_lexers
@lexers_list ||= Pygments::Lexer.all.map do |lexer|
{ alias: lexer.aliases.first, name: lexer.name }
end.sort_by{ |a| a[:name] }
end
get '/' do get '/' do
@lexers = fetch_lexers @lexers = CONFIG.syntaxes_map
slim :form, layout: :default slim :form, layout: :default
end end

View File

@ -7,9 +7,10 @@ html
link rel="stylesheet" href="/assets/dropdown.css?r1" link rel="stylesheet" href="/assets/dropdown.css?r1"
link rel="stylesheet" href="/pygments_solarized_modified.css?r1" link rel="stylesheet" href="/pygments_solarized_modified.css?r1"
body body
h1 a href="/"
strong Paste h1
| master strong Paste
| master
.container== yield .container== yield
script type="text/javascript" src="http://code.jquery.com/jquery-2.0.3.min.js" script type="text/javascript" src="http://code.jquery.com/jquery-2.0.3.min.js"
script type="text/javascript" src="/assets/pastemaster.js?r1" script type="text/javascript" src="/assets/pastemaster.js?r1"

View File

@ -5,7 +5,7 @@ form action="/" method="post" accept-charset="UTF-8"
span Syntax span Syntax
ul.dropdown ul.dropdown
li.selected data-value="" Plain Text li.selected data-value="" Plain Text
- for lexer in @lexers - for code, name in @lexers
li data-value=lexer[:alias] =lexer[: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