diff --git a/Gemfile b/Gemfile index db202f1..48628ce 100644 --- a/Gemfile +++ b/Gemfile @@ -15,8 +15,11 @@ gem 'encryptor' # Syntax Highlighting gem 'pygments.rb' +# JS +gem 'execjs' +gem 'therubyracer' + # Sugar -gem 'haml' -gem 'sass' - - +gem 'coffee-script' +gem 'slim' +gem 'stylus' diff --git a/Gemfile.lock b/Gemfile.lock index 9f846e0..c6b05c5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,10 +1,16 @@ GEM remote: https://rubygems.org/ specs: + coffee-script (2.2.0) + coffee-script-source + execjs + coffee-script-source (1.6.3) encryptor (1.1.3) - haml (4.0.3) - tilt + execjs (1.4.0) + multi_json (~> 1.0) kgio (2.8.0) + libv8 (3.11.8.17) + multi_json (1.7.7) pg (0.15.1) posix-spawn (0.3.6) pygments.rb (0.5.1) @@ -14,7 +20,7 @@ GEM rack-protection (1.5.0) rack raindrops (0.11.0) - sass (3.2.9) + ref (1.0.5) sequel (4.0.0) shotgun (0.9) rack (>= 1.0) @@ -22,6 +28,17 @@ GEM rack (~> 1.4) rack-protection (~> 1.4) tilt (~> 1.3, >= 1.3.4) + slim (2.0.0) + temple (~> 0.6.5) + tilt (~> 1.3, >= 1.3.3) + stylus (0.7.2) + execjs + stylus-source + stylus-source (0.31.0) + temple (0.6.5) + therubyracer (0.11.4) + libv8 (~> 3.11.8.12) + ref tilt (1.4.1) unicorn (4.6.3) kgio (~> 2.6) @@ -33,12 +50,15 @@ PLATFORMS ruby DEPENDENCIES + coffee-script encryptor - haml + execjs pg pygments.rb - sass sequel shotgun sinatra + slim + stylus + therubyracer unicorn diff --git a/app/assets/javascripts/pastemaster.coffee b/app/assets/javascripts/pastemaster.coffee new file mode 100644 index 0000000..a024730 --- /dev/null +++ b/app/assets/javascripts/pastemaster.coffee @@ -0,0 +1,15 @@ +$ -> + $form = $('#pasteform') + $contents = $('#contents') + $_button = $('#submitbtn') + $button = $('#submitlnk') + + # Hide generic button, show styled button + $_button.hide() + $button.show() + $contents.focus() + + # Binding submit event to new button + $button.on 'click', -> + $form.submit() + false diff --git a/app/assets/stylesheets/pastemaster.styl b/app/assets/stylesheets/pastemaster.styl new file mode 100644 index 0000000..f0bc18f --- /dev/null +++ b/app/assets/stylesheets/pastemaster.styl @@ -0,0 +1,82 @@ +* { -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: 1.2em; +} +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; +} +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; +} + +.container { + width: 100%; + height: 100%; +} + +textarea, input { + outline: none; +} + +textarea { + background-color: #ffffff; + width: 100%; + height: 100%; + line-height: 120%; + resize: none; + border-style: solid; + border-color: #ddd; + border-radius: 5px; + padding: .5em; +} + +#submitbtn, #submitlnk { + float: right; +} +#submitlnk { + 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-style: solid; + border-color: #ddd; + border-radius: 4px; + border-width: 1px; + border-bottom-width: 4px; + font-size: 1em; + width: 5em; + text-align: center; + padding: .4em 0; + margin: .5em 0; + text-decoration: none; + display: none; +} +#submitlnk:active { + box-shadow: 0 0 2px 2px #eee inset; + border-bottom-width: 1px; +} + +p { + width: 100%; +} diff --git a/config.ru b/config.ru index 696dd7b..6fc39a5 100644 --- a/config.ru +++ b/config.ru @@ -1,6 +1,3 @@ -$:.unshift File.dirname(__FILE__) -require 'pastemaster' - -use Rack::ShowExceptions +require File.expand_path('../pastemaster', __FILE__) run Pastemaster.new diff --git a/lib/assets.rb b/lib/assets.rb new file mode 100644 index 0000000..3c95564 --- /dev/null +++ b/lib/assets.rb @@ -0,0 +1,21 @@ +class CoffeeAssets < Sinatra::Base + set :views, File.expand_path('../../app/assets/javascripts', __FILE__) + + get '/assets/:name.js' do + path = "#{settings.views}/#{params[:name]}.coffee" + return not_found unless File.exists?(path) + + coffee params[:name].to_sym + end +end + +class StylusAssets < Sinatra::Base + set :views, File.expand_path('../../app/assets/stylesheets', __FILE__) + + get '/assets/:name.css' do + path = "#{settings.views}/#{params[:name]}.styl" + return not_found unless File.exists?(path) + + stylus params[:name].to_sym + end +end diff --git a/lib/error_pages.rb b/lib/error_pages.rb new file mode 100644 index 0000000..3decfb0 --- /dev/null +++ b/lib/error_pages.rb @@ -0,0 +1,15 @@ +class ErrorPages < Sinatra::Base + set :views, File.expand_path('../../views', __FILE__) + + not_found do + status 404 + slim :error_404 + end + + module Forbidden + def forbidden + status 403 + slim :error_403 + end + end +end diff --git a/pastemaster.rb b/pastemaster.rb index 5987f43..c3642a6 100644 --- a/pastemaster.rb +++ b/pastemaster.rb @@ -1,3 +1,5 @@ +$:.unshift File.dirname(__FILE__) + require 'securerandom' require 'base64' @@ -5,17 +7,30 @@ require 'bundler/setup' require 'sinatra' require 'sequel' require 'encryptor' -require 'haml' +require 'slim' +require 'coffee_script' +require 'stylus' +require 'stylus/tilt' +require 'lib/error_pages' +require 'lib/assets' require 'app/config' require 'app/database' require 'app/paste' class Pastemaster < Sinatra::Application + set :server, 'unicorn' set :public_folder, 'public' + set :slim, pretty: true + + use ErrorPages + helpers ErrorPages::Forbidden + use CoffeeAssets + use StylusAssets + get '/' do - haml :form, layout: :default + slim :form, layout: :default end post '/' do @@ -27,9 +42,13 @@ class Pastemaster < Sinatra::Application get '/:id/:key' do @paste = Paste.find(params[:id]) - redirect '/' unless @paste + return not_found unless @paste - @paste.decrypt(params[:key]) - haml :show, layout: :default + begin + @paste.decrypt(params[:key]) + slim :show, layout: :default + rescue => Error + forbidden + end end end diff --git a/public/pastemaster.css b/public/pastemaster.css deleted file mode 100644 index 4c24c1e..0000000 --- a/public/pastemaster.css +++ /dev/null @@ -1,47 +0,0 @@ -* { -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: 150%; -} - -.container { - position: absolute; - top: 10%; - left: 10%; - width: 80%; - height: 80%; -} - -textarea, input { - outline: none; -} - -textarea { - width: 100%; - height: 20em; - line-height: 120%; - resize: none; - border-style: solid; - border-color: #ddd; - border-radius: 5px; - padding: .5em; -} - -input[type="submit"] { - display: inline-block; - margin: .3em 0; - background-color: #fafafa; - border-color: #ddd; - border-radius: 4px; - border-width: 1px; - font-size: 1em; - padding: .2em .5em; -} -.row.centered { - text-align: center; -} - -p { - width: 100%; -} diff --git a/views/default.haml b/views/default.haml deleted file mode 100644 index 79aab1b..0000000 --- a/views/default.haml +++ /dev/null @@ -1,8 +0,0 @@ -!!! -%html - %head - %title Pastemaster - %link{ rel: 'stylesheet', href: '/normalize.css?v2.1.2' } - %link{ rel: 'stylesheet', href: '/pastemaster.css?r1' } - %body - .container= yield diff --git a/views/default.slim b/views/default.slim new file mode 100644 index 0000000..122a5a7 --- /dev/null +++ b/views/default.slim @@ -0,0 +1,13 @@ +doctype html +html + head + title Pastemaster + link rel="stylesheet" href="/normalize.css?v2.1.2" + link rel="stylesheet" href="/assets/pastemaster.css?r1" + body + 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" diff --git a/views/error_403.slim b/views/error_403.slim new file mode 100644 index 0000000..ac40b01 --- /dev/null +++ b/views/error_403.slim @@ -0,0 +1,20 @@ +doctype html +html + head + title 403 Forbidden + meta charset="utf-8" + style type="text/css" + | html { display: table; } + | body { display: table-cell; } + | html, body { + | width: 100%; height: 100%; + | margin: 0; padding: 0; + | text-align: center; vertical-align: middle; + | font-face: Helvetica, Arial, sans-serif; + | font-size: 2em; + | font-weight: 100; + | background-color: #fafafa; + | color: #444444; + | } + body + | 403 Forbidden diff --git a/views/error_404.slim b/views/error_404.slim new file mode 100644 index 0000000..d2f7177 --- /dev/null +++ b/views/error_404.slim @@ -0,0 +1,20 @@ +doctype html +html + head + title 404 Not Found + meta charset="utf-8" + style type="text/css" + | html { display: table; } + | body { display: table-cell; } + | html, body { + | width: 100%; height: 100%; + | margin: 0; padding: 0; + | text-align: center; vertical-align: middle; + | font-face: Helvetica, Arial, sans-serif; + | font-size: 2em; + | font-weight: 100; + | background-color: #fafafa; + | color: #444444; + | } + body + | 404 Not Found diff --git a/views/form.haml b/views/form.haml deleted file mode 100644 index 2b33d87..0000000 --- a/views/form.haml +++ /dev/null @@ -1,8 +0,0 @@ -%form{ action: '/', method: 'post', 'accept-charset' => 'UTF-8' } - .row{ style: 'display: none' } - %select{ name: 'type' } - %option{ value: 'text_plain' } Plain Text - .row - %textarea{ name: 'contents' } - .row.centered - %input{ type: 'submit' } diff --git a/views/form.slim b/views/form.slim new file mode 100644 index 0000000..ac4533f --- /dev/null +++ b/views/form.slim @@ -0,0 +1,4 @@ +form#pasteform action="/" method="post" accept-charset="UTF-8" + textarea#contents name="contents" + input#submitbtn type="submit" value="Save" + a#submitlnk href="" role="submit" Save diff --git a/views/show.haml b/views/show.haml deleted file mode 100644 index 7c06e4d..0000000 --- a/views/show.haml +++ /dev/null @@ -1,5 +0,0 @@ -%p - - if @paste - = @paste.contents - - else - .nohave Sorry no have mister diff --git a/views/show.slim b/views/show.slim new file mode 100644 index 0000000..5705505 --- /dev/null +++ b/views/show.slim @@ -0,0 +1 @@ +pre= @paste.contents