|
|
@ -5,6 +5,14 @@ require_relative "views"
|
|
|
|
require "roda"
|
|
|
|
require "roda"
|
|
|
|
|
|
|
|
|
|
|
|
module RankKing
|
|
|
|
module RankKing
|
|
|
|
|
|
|
|
module Models
|
|
|
|
|
|
|
|
require "sequel/model"
|
|
|
|
|
|
|
|
require_relative "db"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Pool < Sequel::Model
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
class App < Roda
|
|
|
|
class App < Roda
|
|
|
|
opts[:check_dynamic_arity] = false
|
|
|
|
opts[:check_dynamic_arity] = false
|
|
|
|
opts[:check_arity] = :warn
|
|
|
|
opts[:check_arity] = :warn
|
|
|
@ -26,19 +34,19 @@ module RankKing
|
|
|
|
csp.frame_ancestors :none
|
|
|
|
csp.frame_ancestors :none
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# css_opts = {cache: false, style: :compressed}
|
|
|
|
css_opts = {cache: false, style: :compressed}
|
|
|
|
# :nocov:
|
|
|
|
# :nocov:
|
|
|
|
# if ENV["RACK_ENV"] == 'development'
|
|
|
|
if ENV["RACK_ENV"] == 'development'
|
|
|
|
# css_opts.merge!(source_map_embed: true, source_map_contents: true, source_map_file: ".")
|
|
|
|
css_opts.merge!(source_map_embed: true, source_map_contents: true, source_map_file: ".")
|
|
|
|
# end
|
|
|
|
end
|
|
|
|
# plugin :render_coverage if defined?(SimpleCov)
|
|
|
|
plugin :render_coverage if defined?(SimpleCov)
|
|
|
|
# :nocov:
|
|
|
|
# :nocov:
|
|
|
|
|
|
|
|
|
|
|
|
plugin :route_csrf
|
|
|
|
plugin :route_csrf
|
|
|
|
plugin :flash
|
|
|
|
plugin :flash
|
|
|
|
# plugin :assets, css: "app.scss", css_opts: css_opts, timestamp_paths: true
|
|
|
|
# plugin :assets, css: "app.scss", css_opts: css_opts, timestamp_paths: true
|
|
|
|
# plugin :render, escape: true, layout: "./layout", :template_opts=>{chain_appends: !defined?(SimpleCov), freeze: true, skip_compiled_encoding_detection: true}
|
|
|
|
# plugin :render, escape: true, layout: "./layout", :template_opts=>{chain_appends: !defined?(SimpleCov), freeze: true, skip_compiled_encoding_detection: true}
|
|
|
|
# plugin :public
|
|
|
|
plugin :public
|
|
|
|
plugin :Integer_matcher_max
|
|
|
|
plugin :Integer_matcher_max
|
|
|
|
plugin :typecast_params_sized_integers, sizes: [64], default_size: 64
|
|
|
|
plugin :typecast_params_sized_integers, sizes: [64], default_size: 64
|
|
|
|
# plugin :hash_branch_view_subdir
|
|
|
|
# plugin :hash_branch_view_subdir
|
|
|
@ -52,8 +60,7 @@ module RankKing
|
|
|
|
plugin :common_logger, logger
|
|
|
|
plugin :common_logger, logger
|
|
|
|
|
|
|
|
|
|
|
|
plugin :not_found do
|
|
|
|
plugin :not_found do
|
|
|
|
@page_title = "File Not Found"
|
|
|
|
Views::Layout.call(title: "File Not Found")
|
|
|
|
view(content: "")
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if ENV["RACK_ENV"] == "development"
|
|
|
|
if ENV["RACK_ENV"] == "development"
|
|
|
@ -98,22 +105,90 @@ module RankKing
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# Unreloader.autoload("routes", delete_hook: proc{|f| hash_branch(File.basename(f).delete_suffix(".rb"))}){}
|
|
|
|
# Unreloader.autoload("routes", delete_hook: proc{|f| hash_branch(File.basename(f).delete_suffix(".rb"))}){}
|
|
|
|
|
|
|
|
|
|
|
|
# def render(view, layout=Views::Layout.new)
|
|
|
|
class Template < Phlex::HTML
|
|
|
|
# component.call
|
|
|
|
def initialize(block)
|
|
|
|
|
|
|
|
@block = block
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def template
|
|
|
|
|
|
|
|
instance_eval(&@block)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# def render(&block)
|
|
|
|
|
|
|
|
# template = Template.new(block)
|
|
|
|
|
|
|
|
# instance_variables
|
|
|
|
|
|
|
|
# .reject { _1.start_with?("@_") }
|
|
|
|
|
|
|
|
# .each { template.instance_variable_set(_1, instance_variable_get(_1)) }
|
|
|
|
|
|
|
|
# Views::Layout.call do
|
|
|
|
|
|
|
|
# plain ""
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# # Views::Layout.call(template)
|
|
|
|
|
|
|
|
# # Views::Layout.call do |layout|
|
|
|
|
|
|
|
|
# # layout.page_title "New Pool"
|
|
|
|
|
|
|
|
# # plain ""
|
|
|
|
|
|
|
|
# # end
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def view(&block)
|
|
|
|
|
|
|
|
Class.new(Phlex::HTML, &block).call
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
route do |r|
|
|
|
|
route do |r|
|
|
|
|
|
|
|
|
|
|
|
|
# r.public
|
|
|
|
# r.public
|
|
|
|
# r.assets
|
|
|
|
# r.assets
|
|
|
|
check_csrf!
|
|
|
|
check_csrf!
|
|
|
|
|
|
|
|
|
|
|
|
r.root do
|
|
|
|
r.root do
|
|
|
|
Views::Layout.new(Views::Hello.new(name: "Bob")).call
|
|
|
|
if DB[:pools].empty?
|
|
|
|
|
|
|
|
r.redirect "/pools/new"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
render do
|
|
|
|
|
|
|
|
h1 { "ohai" }
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
r.on "pools" do
|
|
|
|
r.on "pools" do
|
|
|
|
r.is "new" do
|
|
|
|
r.is "new" do
|
|
|
|
Views::Layout.new(Views::NewPool.new).call
|
|
|
|
r.get do
|
|
|
|
|
|
|
|
@csrf_token = csrf_token(r.path)
|
|
|
|
|
|
|
|
view do
|
|
|
|
|
|
|
|
Views::Layout.new(title: "New Pool") do
|
|
|
|
|
|
|
|
Views::NewPool.new(csrf_token: @csrf_token)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
# Views::Layout.call(title: "New Pool") do
|
|
|
|
|
|
|
|
# render Views::NewPool.new(csrf_token: csrf_token(r.path))
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# layout = Views::Layout.new do |layout|
|
|
|
|
|
|
|
|
# layout.page_title "New Pool"
|
|
|
|
|
|
|
|
# render Views::NewPool.new(csrf_token: csrf_token(r.path))
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# layout.call
|
|
|
|
|
|
|
|
# @csrf_token = csrf_token(r.path)
|
|
|
|
|
|
|
|
# render do
|
|
|
|
|
|
|
|
# form(method: "post") do
|
|
|
|
|
|
|
|
# input(type: "hidden", name: "_csrf", value: @csrf_token)
|
|
|
|
|
|
|
|
# label(for: "name")
|
|
|
|
|
|
|
|
# input(type: "text", name: "name", id: "name", required: true)
|
|
|
|
|
|
|
|
# input(type: "submit", value: "Create")
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
r.post do
|
|
|
|
|
|
|
|
pool = Models::Pool.create(name: r.params.fetch("name"))
|
|
|
|
|
|
|
|
r.redirect "/pools/#{pool.id}"
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
r.is Integer do |id|
|
|
|
|
|
|
|
|
pool = Models::Pool[id]
|
|
|
|
|
|
|
|
render do
|
|
|
|
|
|
|
|
h2 { pool.name }
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|