Compare commits
14 Commits
8b742cfed7
...
main
Author | SHA1 | Date | |
---|---|---|---|
df53c44201 | |||
e5022c5624 | |||
0da1fea1ec | |||
498ecf76f5 | |||
c5d6293737 | |||
8a7d5b93e3 | |||
37d5239f94 | |||
f08c5c71ab | |||
c9a8ff07f2 | |||
d7610bde55 | |||
85a67aea7a | |||
3738c9e4f7 | |||
9942843e3e | |||
3b952dd11e |
1
Gemfile
1
Gemfile
@ -2,6 +2,7 @@ source 'https://rubygems.org'
|
||||
|
||||
gem 'sinatra', '~> 3.0'
|
||||
gem 'sinatra-contrib', '~> 3.0'
|
||||
gem 'sinatra-flash', '~> 0.3.0'
|
||||
gem 'puma', '~> 6.3'
|
||||
|
||||
gem 'sequel', '~> 5.70'
|
||||
|
89
Gemfile.lock
Normal file
89
Gemfile.lock
Normal file
@ -0,0 +1,89 @@
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
ast (2.4.2)
|
||||
base64 (0.2.0)
|
||||
bigdecimal (3.1.8)
|
||||
ffi (1.17.0-x86_64-linux-gnu)
|
||||
json (2.7.2)
|
||||
language_server-protocol (3.17.0.3)
|
||||
listen (3.9.0)
|
||||
rb-fsevent (~> 0.10, >= 0.10.3)
|
||||
rb-inotify (~> 0.9, >= 0.9.10)
|
||||
multi_json (1.15.0)
|
||||
mustermann (3.0.0)
|
||||
ruby2_keywords (~> 0.0.1)
|
||||
nio4r (2.7.3)
|
||||
parallel (1.25.1)
|
||||
parser (3.3.3.0)
|
||||
ast (~> 2.4.1)
|
||||
racc
|
||||
puma (6.4.2)
|
||||
nio4r (~> 2.0)
|
||||
racc (1.8.0)
|
||||
rack (2.2.9)
|
||||
rack-protection (3.2.0)
|
||||
base64 (>= 0.1.0)
|
||||
rack (~> 2.2, >= 2.2.4)
|
||||
rainbow (3.1.1)
|
||||
rb-fsevent (0.11.2)
|
||||
rb-inotify (0.11.1)
|
||||
ffi (~> 1.0)
|
||||
regexp_parser (2.9.2)
|
||||
rerun (0.14.0)
|
||||
listen (~> 3.0)
|
||||
rexml (3.3.1)
|
||||
strscan
|
||||
rubocop (1.64.1)
|
||||
json (~> 2.3)
|
||||
language_server-protocol (>= 3.17.0)
|
||||
parallel (~> 1.10)
|
||||
parser (>= 3.3.0.2)
|
||||
rainbow (>= 2.2.2, < 4.0)
|
||||
regexp_parser (>= 1.8, < 3.0)
|
||||
rexml (>= 3.2.5, < 4.0)
|
||||
rubocop-ast (>= 1.31.1, < 2.0)
|
||||
ruby-progressbar (~> 1.7)
|
||||
unicode-display_width (>= 2.4.0, < 3.0)
|
||||
rubocop-ast (1.31.3)
|
||||
parser (>= 3.3.1.0)
|
||||
rubocop-sequel (0.3.4)
|
||||
rubocop (~> 1.0)
|
||||
ruby-progressbar (1.13.0)
|
||||
ruby2_keywords (0.0.5)
|
||||
sequel (5.82.0)
|
||||
bigdecimal
|
||||
sinatra (3.2.0)
|
||||
mustermann (~> 3.0)
|
||||
rack (~> 2.2, >= 2.2.4)
|
||||
rack-protection (= 3.2.0)
|
||||
tilt (~> 2.0)
|
||||
sinatra-contrib (3.2.0)
|
||||
multi_json (>= 0.0.2)
|
||||
mustermann (~> 3.0)
|
||||
rack-protection (= 3.2.0)
|
||||
sinatra (= 3.2.0)
|
||||
tilt (~> 2.0)
|
||||
sinatra-flash (0.3.0)
|
||||
sinatra (>= 1.0.0)
|
||||
sqlite3 (1.7.3-x86_64-linux)
|
||||
strscan (3.1.0)
|
||||
tilt (2.4.0)
|
||||
unicode-display_width (2.5.0)
|
||||
|
||||
PLATFORMS
|
||||
x86_64-linux-gnu
|
||||
|
||||
DEPENDENCIES
|
||||
puma (~> 6.3)
|
||||
rerun
|
||||
rubocop
|
||||
rubocop-sequel
|
||||
sequel (~> 5.70)
|
||||
sinatra (~> 3.0)
|
||||
sinatra-contrib (~> 3.0)
|
||||
sinatra-flash (~> 0.3.0)
|
||||
sqlite3 (~> 1.7)
|
||||
|
||||
BUNDLED WITH
|
||||
2.4.20
|
12
Rakefile
12
Rakefile
@ -1,5 +1,17 @@
|
||||
require 'bundler/setup'
|
||||
|
||||
namespace :db do
|
||||
desc 'Run migrations'
|
||||
task :migrate, [:version] do |t, args|
|
||||
require "sequel/core"
|
||||
Sequel.extension :migration
|
||||
version = args[:version].to_i if args[:version]
|
||||
Sequel.connect('sqlite://data/destructo.db') do |db|
|
||||
Sequel::Migrator.run(db, "db/migrations", target: version)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
namespace :server do
|
||||
task :start do
|
||||
ENV['APP_ENV'] = 'production'
|
||||
|
@ -1,2 +1,39 @@
|
||||
html,
|
||||
body
|
||||
margin: 0
|
||||
padding: 0
|
||||
|
||||
body
|
||||
background: #eee
|
||||
|
||||
.container
|
||||
max-width: 1024px
|
||||
|
||||
#main-nav
|
||||
margin-bottom: 15px
|
||||
padding-left: 20px
|
||||
background: teal
|
||||
|
||||
ul
|
||||
li
|
||||
display: inline-block
|
||||
margin: 0 10px 0 0
|
||||
|
||||
a
|
||||
display: block
|
||||
height: 100%
|
||||
padding: 10px 12px
|
||||
background: none
|
||||
color: white
|
||||
font-size: 2rem
|
||||
text-decoration: none
|
||||
transition: all 220ms ease-in-out
|
||||
|
||||
&:hover
|
||||
background: rgba(0, 0, 0, .1)
|
||||
color: lightgrey
|
||||
|
||||
#main-content
|
||||
padding: 12px 20px
|
||||
background: white
|
||||
border-radius: 8px
|
||||
|
0
data/.gitkeep
Normal file
0
data/.gitkeep
Normal file
@ -3,6 +3,7 @@ Sequel.migration do
|
||||
up do
|
||||
create_table(:messages) do
|
||||
primary_key :id
|
||||
String :slug, null: false, unique: true
|
||||
String :body, null: false
|
||||
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP
|
||||
DateTime :updated_at, default: Sequel::CURRENT_TIMESTAMP
|
||||
|
1859
package-lock.json
generated
Normal file
1859
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -8,4 +8,8 @@ module Helpers
|
||||
return dt.strftime('%B %d, %Y @ %I:%M:%S %p %Z')
|
||||
end
|
||||
|
||||
def message_url(slug)
|
||||
return "#{request.scheme}://#{request.host}:#{request.port}/message/#{slug}"
|
||||
end
|
||||
|
||||
end
|
||||
|
12
src/routes/error.rb
Normal file
12
src/routes/error.rb
Normal file
@ -0,0 +1,12 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# error handling routes
|
||||
class Destructo < Sinatra::Base
|
||||
|
||||
error 404 do
|
||||
erb :'error/404', locals: {
|
||||
title: 'Page not found'
|
||||
}
|
||||
end
|
||||
|
||||
end
|
@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'error'
|
||||
require_relative 'index'
|
||||
require_relative 'message'
|
||||
|
50
src/routes/message.rb
Normal file
50
src/routes/message.rb
Normal file
@ -0,0 +1,50 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'securerandom'
|
||||
|
||||
# /message routes
|
||||
class Destructo < Sinatra::Base
|
||||
|
||||
get '/message' do
|
||||
redirect '/message/new'
|
||||
end
|
||||
|
||||
get '/message/new' do
|
||||
erb :'message/new', locals: {
|
||||
title: 'Create new message'
|
||||
}
|
||||
end
|
||||
|
||||
post '/message/new' do
|
||||
# generate a random string for the slug
|
||||
slug = SecureRandom.urlsafe_base64(12)
|
||||
|
||||
# create object in DB
|
||||
msg = Message.create(
|
||||
slug: slug,
|
||||
body: params[:message_body]
|
||||
)
|
||||
|
||||
msg_url = message_url(slug)
|
||||
flash[:success] = "Your message was created successfully! Share this link: <a href='#{msg_url}'>#{msg_url}</a>"
|
||||
|
||||
redirect '/'
|
||||
end
|
||||
|
||||
get '/message/:message_slug' do
|
||||
message = Message.where(slug: params[:message_slug]).first()
|
||||
|
||||
if message
|
||||
# delete the message
|
||||
message.delete()
|
||||
|
||||
erb :'message/view', locals: {
|
||||
title: 'View message',
|
||||
message: message
|
||||
}
|
||||
else
|
||||
404
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@ -23,6 +23,10 @@ class Destructo < Sinatra::Base
|
||||
require_relative 'helpers'
|
||||
helpers Helpers
|
||||
|
||||
# Register flash messages
|
||||
require 'sinatra/flash'
|
||||
register Sinatra::Flash
|
||||
|
||||
# Set up our view engine
|
||||
set :views, File.join(settings.root, '/../views')
|
||||
|
||||
|
5
views/error/404.erb
Normal file
5
views/error/404.erb
Normal file
@ -0,0 +1,5 @@
|
||||
<p>This page does not exist.</p>
|
||||
|
||||
<p>If you're looking for a message, it's possible that it has already been viewed and subsequently deleted.</p>
|
||||
|
||||
<p>If you would like to send a new message, head <a href="/">back home</a> to get started.</p>
|
@ -1,5 +1,7 @@
|
||||
<div class="row">
|
||||
<div class="columns twelve">
|
||||
<p>This is the home page.</p>
|
||||
|
||||
<p><a href="/message/new">Click here</a> to send a new message.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -4,7 +4,7 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title><%= title %> | Game Data</title>
|
||||
<title><%= title %> | Destructo</title>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
|
||||
<link rel="stylesheet" href="/css/hallowvale.css">
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.0/jquery.min.js" charset="utf-8"></script>
|
||||
@ -14,8 +14,11 @@
|
||||
<!-- main navigation -->
|
||||
<%= erb :'partials/navbar', :locals => locals %>
|
||||
|
||||
<!-- flash messages -->
|
||||
<%= erb :'partials/flash' %>
|
||||
|
||||
<!-- main content -->
|
||||
<div class="container">
|
||||
<div id="main-content" class="container">
|
||||
<%= yield %>
|
||||
</div>
|
||||
</body>
|
||||
|
18
views/message/new.erb
Normal file
18
views/message/new.erb
Normal file
@ -0,0 +1,18 @@
|
||||
<div class="row">
|
||||
<form class="u-full-width" action="/message/new" method="post">
|
||||
<div class="row">
|
||||
<div class="twelve columns">
|
||||
<label>
|
||||
Message body:
|
||||
<textarea class="u-full-width" name="message_body"></textarea>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="twelve columns">
|
||||
<input class="button-primary" type="submit" value="Create message">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
5
views/message/view.erb
Normal file
5
views/message/view.erb
Normal file
@ -0,0 +1,5 @@
|
||||
<div class="row">
|
||||
<div class="twelve columns">
|
||||
<p><%= message.body %></p>
|
||||
</div>
|
||||
</div>
|
9
views/partials/flash.erb
Normal file
9
views/partials/flash.erb
Normal file
@ -0,0 +1,9 @@
|
||||
<% if flash[:success] %>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="columns twelve">
|
||||
<p><%= flash[:success] %></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
Reference in New Issue
Block a user