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'
self.placeholder.text "#{self.prefix}: #{$el.text()}"
self.setValue $el.data 'value'
$('textarea').focus()
@options.filter('.selected').click()
@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 {
font-family: Helvetica, Arial, sans-serif;
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;
}
body, input, select
font-family Helvetica, Arial, sans-serif
font-size 1em
.container {
width: 100%;
height: 100%;
}
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
textarea, input {
outline: none;
}
html, body, form
height 100%
textarea {
background-color: #ffffff;
width: 100%;
height: 100%;
line-height: 120%;
resize: none;
border: #ddd 1px solid;
border-radius: 5px;
padding: .5em;
}
body
background-color #fcfcfc
padding 3em
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;
}
form a[role="submit"]:active {
box-shadow: 0 0 2px 2px #eee inset;
border-bottom-width: 1px;
}
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
width 100%
height 100%
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)
@contents = contents
@type = type if available_types.include?(type)
@type = type if CONFIG.available_syntaxes.include?(type)
end
def save
@ -47,8 +47,4 @@ class Paste
def html
type ? highlighted : paragraph
end
def available_types
@available_types ||= Pygments::Lexer.all.map(&:aliases).flatten
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.create_table(:pastes) do
primary_key :id
String :type
String :syntax
Text :contents
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 'base64'
require 'yaml'
require 'bundler/setup'
require 'sinatra'
@ -13,11 +14,12 @@ require 'stylus'
require 'stylus/tilt'
require 'pygments'
require 'app/models/configuration'
require 'app/models/paste'
require 'config/initializers/configuration'
require 'config/initializers/database'
require 'lib/error_pages'
require 'lib/assets'
require 'app/config'
require 'app/database'
require 'app/paste'
class Pastemaster < Sinatra::Application
set :server, 'unicorn'
@ -30,14 +32,8 @@ class Pastemaster < Sinatra::Application
use CoffeeAssets
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
@lexers = fetch_lexers
@lexers = CONFIG.syntaxes_map
slim :form, layout: :default
end

View File

@ -7,9 +7,10 @@ html
link rel="stylesheet" href="/assets/dropdown.css?r1"
link rel="stylesheet" href="/pygments_solarized_modified.css?r1"
body
h1
strong Paste
| master
a href="/"
h1
strong Paste
| master
.container== yield
script type="text/javascript" src="http://code.jquery.com/jquery-2.0.3.min.js"
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
ul.dropdown
li.selected data-value="" Plain Text
- for lexer in @lexers
li data-value=lexer[:alias] =lexer[:name]
- for code, name in @lexers
li data-value=code =name
input type="submit" value="Save"
a href="#" role="submit" Save