Initial sinatra project structure
This commit is contained in:
parent
55400fa30d
commit
fb7f99d67b
9
.gitignore
vendored
9
.gitignore
vendored
@ -56,3 +56,12 @@ build-iPhoneSimulator/
|
||||
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
||||
# .rubocop-https?--*
|
||||
|
||||
# Ignore local data
|
||||
data/
|
||||
|
||||
# Node modules
|
||||
node_modules/
|
||||
|
||||
# Compiled assets
|
||||
public/css/
|
||||
public/js/
|
||||
|
23
.rubocop.yml
Normal file
23
.rubocop.yml
Normal file
@ -0,0 +1,23 @@
|
||||
require: rubocop-sequel
|
||||
|
||||
AllCops:
|
||||
NewCops: enable
|
||||
|
||||
Layout/EmptyLinesAroundClassBody:
|
||||
EnforcedStyle: 'empty_lines_except_namespace'
|
||||
Layout/EmptyLinesAroundModuleBody:
|
||||
EnforcedStyle: 'empty_lines_except_namespace'
|
||||
Layout/FirstHashElementIndentation:
|
||||
EnforcedStyle: 'consistent'
|
||||
Metrics/ClassLength:
|
||||
Max: 150
|
||||
Style/ClassVars:
|
||||
Enabled: false
|
||||
Style/GlobalVars:
|
||||
Enabled: false
|
||||
Style/MethodCallWithoutArgsParentheses:
|
||||
Enabled: false
|
||||
Style/MethodCallWithArgsParentheses:
|
||||
Enabled: true
|
||||
Style/RedundantReturn:
|
||||
Enabled: false
|
15
Dockerfile.dev
Normal file
15
Dockerfile.dev
Normal file
@ -0,0 +1,15 @@
|
||||
FROM ruby:3.3
|
||||
|
||||
RUN gem install bundler -v 2.5
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
COPY Gemfile Gemfile.lock ./
|
||||
|
||||
RUN bundle check || bundle install
|
||||
|
||||
RUN gem install rake
|
||||
|
||||
COPY . ./
|
||||
|
||||
ENTRYPOINT ["bash", "entrypoints/dev.sh"]
|
17
Gemfile
Normal file
17
Gemfile
Normal file
@ -0,0 +1,17 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
gem 'sinatra', '~> 3.0'
|
||||
gem 'sinatra-contrib', '~> 3.0'
|
||||
gem 'puma', '~> 6.3'
|
||||
|
||||
gem 'sequel', '~> 5.70'
|
||||
gem 'sqlite3', '~> 1.7'
|
||||
|
||||
group :development, :test do
|
||||
gem 'rerun'
|
||||
gem 'wdm', '>= 0.1.0' if Gem.win_platform?
|
||||
|
||||
# rubocop and extensions for code style
|
||||
gem 'rubocop'
|
||||
gem 'rubocop-sequel'
|
||||
end
|
65
Gruntfile.js
Normal file
65
Gruntfile.js
Normal file
@ -0,0 +1,65 @@
|
||||
module.exports = function(grunt) {
|
||||
|
||||
// Project configuration.
|
||||
grunt.initConfig({
|
||||
pkg: grunt.file.readJSON('package.json'),
|
||||
|
||||
sass: {
|
||||
dist: {
|
||||
options: {
|
||||
style: 'compressed'
|
||||
},
|
||||
files: [{
|
||||
expand: true,
|
||||
cwd: 'assets/styles',
|
||||
src: ['**/*.sass'],
|
||||
dest: 'public/css',
|
||||
ext: '.css'
|
||||
}]
|
||||
}
|
||||
},
|
||||
|
||||
coffee: {
|
||||
options: {
|
||||
sourceMap: true,
|
||||
style: 'compressed'
|
||||
},
|
||||
files: {
|
||||
expand: true,
|
||||
flatten: true,
|
||||
cwd: 'assets/scripts',
|
||||
src: ['*.coffee'],
|
||||
dest: 'public/js',
|
||||
ext: '.js'
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
css: {
|
||||
files: ['assets/styles/**/*.sass'],
|
||||
tasks: ['sass'],
|
||||
options: {
|
||||
atBegin: true,
|
||||
spawn: false
|
||||
}
|
||||
},
|
||||
js: {
|
||||
files: ['assets/scripts/**/*.js'],
|
||||
tasks: ['coffee'],
|
||||
options: {
|
||||
atBegin: true,
|
||||
spawn: false
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Load plugins.
|
||||
grunt.loadNpmTasks('grunt-contrib-watch');
|
||||
grunt.loadNpmTasks('grunt-contrib-sass');
|
||||
grunt.loadNpmTasks('grunt-contrib-coffee');
|
||||
|
||||
// CLI tasks.
|
||||
grunt.registerTask('default', ['sass', 'coffee']);
|
||||
|
||||
};
|
18
Rakefile
Normal file
18
Rakefile
Normal file
@ -0,0 +1,18 @@
|
||||
require 'bundler/setup'
|
||||
|
||||
namespace :server do
|
||||
task :start do
|
||||
ENV['APP_ENV'] = 'production'
|
||||
system("puma")
|
||||
end
|
||||
|
||||
task :dev do
|
||||
system('rerun --no-notify --exit --dir="src/" puma')
|
||||
end
|
||||
end
|
||||
|
||||
namespace :test do
|
||||
task :rubocop do
|
||||
system("rubocop src/")
|
||||
end
|
||||
end
|
2
assets/scripts/darkmeyer.coffee
Normal file
2
assets/scripts/darkmeyer.coffee
Normal file
@ -0,0 +1,2 @@
|
||||
$ ->
|
||||
console.log('Ready.')
|
2
assets/styles/hallowvale.sass
Normal file
2
assets/styles/hallowvale.sass
Normal file
@ -0,0 +1,2 @@
|
||||
#main-nav
|
||||
margin-bottom: 15px
|
7
config.ru
Normal file
7
config.ru
Normal file
@ -0,0 +1,7 @@
|
||||
# Load application config
|
||||
require_relative 'src/config.rb'
|
||||
$conf = Config.new(File.join(__dir__, 'config/defaults.yaml'))
|
||||
|
||||
root = ::File.dirname(__FILE__)
|
||||
require ::File.join( root, 'src', 'server' )
|
||||
run GameData.new
|
6
config/defaults.yaml
Normal file
6
config/defaults.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
database:
|
||||
adapter: 'sqlite'
|
||||
database: 'data/destructo.db'
|
||||
|
||||
testing:
|
||||
minimum_results_required: 3
|
7
entrypoints/dev.sh
Normal file
7
entrypoints/dev.sh
Normal file
@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ ! -f ./data/gamedata.db ]; then
|
||||
rake db:migrate
|
||||
fi
|
||||
|
||||
rake server:dev
|
27
package.json
Normal file
27
package.json
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "destructo",
|
||||
"description": "Self-destructing messaging app",
|
||||
"version": "0.1.0",
|
||||
"main": "src/server.rb",
|
||||
"scripts": {
|
||||
"grunt": "grunt"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.metaunix.net/Metaunix/Destructo"
|
||||
},
|
||||
"keywords": [
|
||||
"messaging",
|
||||
"self-destructing"
|
||||
],
|
||||
"author": "Gregory Ballantine <gballantine@metaunix.net>",
|
||||
"license": "BSD-4-Clause",
|
||||
"devDependencies": {
|
||||
"grunt": "^1.6.1",
|
||||
"grunt-cli": "^1.4.3",
|
||||
"grunt-contrib-coffee": "^2.1.0",
|
||||
"grunt-contrib-sass": "^2.0.0",
|
||||
"grunt-contrib-watch": "^1.1.0",
|
||||
"sass": "^1.77.4"
|
||||
}
|
||||
}
|
28
src/config.rb
Normal file
28
src/config.rb
Normal file
@ -0,0 +1,28 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'yaml'
|
||||
|
||||
# Config - loads and manages the app's configuration
|
||||
class Config
|
||||
|
||||
DEFAULT_CONFIG = 'config/defaults.yaml'
|
||||
|
||||
def initialize(config_path)
|
||||
@data = YAML.load_file(DEFAULT_CONFIG)
|
||||
|
||||
# merge in user-defined configuration if it exists
|
||||
@data.merge!(YAML.load_file(config_path)) if File.exist?(config_path)
|
||||
end
|
||||
|
||||
def get(key)
|
||||
bits = key.split('.')
|
||||
value = @data
|
||||
|
||||
bits.each do |bit|
|
||||
value = value[bit]
|
||||
end
|
||||
|
||||
return value
|
||||
end
|
||||
|
||||
end
|
11
src/helpers.rb
Normal file
11
src/helpers.rb
Normal file
@ -0,0 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Helpers - view helper functions
|
||||
module Helpers
|
||||
|
||||
def date_format(date)
|
||||
dt = date.to_datetime
|
||||
return dt.strftime('%B %d, %Y @ %I:%M:%S %p %Z')
|
||||
end
|
||||
|
||||
end
|
3
src/models/init.rb
Normal file
3
src/models/init.rb
Normal file
@ -0,0 +1,3 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Will add models to load here
|
12
src/routes/index.rb
Normal file
12
src/routes/index.rb
Normal file
@ -0,0 +1,12 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# / (top-level) routes
|
||||
class Destructo < Sinatra::Base
|
||||
|
||||
get '/' do
|
||||
erb :'index/home', locals: {
|
||||
title: 'Home'
|
||||
}
|
||||
end
|
||||
|
||||
end
|
3
src/routes/init.rb
Normal file
3
src/routes/init.rb
Normal file
@ -0,0 +1,3 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'index'
|
34
src/server.rb
Normal file
34
src/server.rb
Normal file
@ -0,0 +1,34 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'sinatra/base'
|
||||
require 'sinatra/json'
|
||||
require 'sequel'
|
||||
require 'sqlite3'
|
||||
|
||||
# Load the Sequel timestamps plugin
|
||||
Sequel::Model.plugin(:timestamps)
|
||||
# Initialize Sequel gem for database actions
|
||||
DB = Sequel.connect(adapter: $conf.get('database.adapter'), database: $conf.get('database.database'))
|
||||
|
||||
# Base app
|
||||
class Destructo < Sinatra::Base
|
||||
|
||||
enable :sessions
|
||||
|
||||
# Set up static file serving
|
||||
enable :static
|
||||
set :public_folder, File.join(__dir__, '/../public')
|
||||
|
||||
# Register view helpers
|
||||
require_relative 'helpers'
|
||||
helpers Helpers
|
||||
|
||||
# Set up our view engine
|
||||
set :views, File.join(settings.root, '/../views')
|
||||
|
||||
end
|
||||
|
||||
# Load routes
|
||||
require_relative 'routes/init'
|
||||
# Load models
|
||||
require_relative 'models/init'
|
5
views/index/home.erb
Normal file
5
views/index/home.erb
Normal file
@ -0,0 +1,5 @@
|
||||
<div class="row">
|
||||
<div class="columns twelve">
|
||||
<p>This is the home page.</p>
|
||||
</div>
|
||||
</div>
|
22
views/layout.erb
Normal file
22
views/layout.erb
Normal file
@ -0,0 +1,22 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<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>
|
||||
<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>
|
||||
<script src="/js/darkmeyer.js" charset="utf-8"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!-- main navigation -->
|
||||
<%= erb :'partials/navbar', :locals => locals %>
|
||||
|
||||
<!-- main content -->
|
||||
<div class="container">
|
||||
<%= yield %>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
8
views/partials/navbar.erb
Normal file
8
views/partials/navbar.erb
Normal file
@ -0,0 +1,8 @@
|
||||
<div id="main-nav">
|
||||
<div class="nav-left">
|
||||
<ul>
|
||||
<li><a href="/">Home</a></li>
|
||||
<li><a href="/message">New Message</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user