aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-03-02 00:10:45 +0100
committerJohn Ankarström <john@ankarstrom.se>2021-03-02 00:10:45 +0100
commit469a4c2424a684524a8323a8a1a3727e1b6a4ed7 (patch)
treeacb61ff26c932e9cf5eac09aff89d5d452a92ac4
parent7640f27b9e183c6e9a00249c352e3515d3f90c75 (diff)
downloadcomb-469a4c2424a684524a8323a8a1a3727e1b6a4ed7.tar.gz
Add simple web interface
The structure is preliminary. It might be a better idea to start Sinatra in a main script, which decides what interface to use. The question is whether non-Sinatra interfaces should be supported. Most will likely use Sinatra, but perhaps not all. With that in mind, how should it be decided which interface to use? The best idea is probably to have a protocols directory, with one script per protocol. http.rb would be the HTTP server, using Sinatra, while ftp.rb or whatever could be run alongside it. Alternatively, there could be the following structure: interfaces/ - http/ - http.rb - web/ - web.rb - views/ - admin/ - rss/ - ftp/ - ftp.rb That would probably be the cleanest implementation.
-rw-r--r--web/interface.rb9
-rw-r--r--web/views/index.erb19
2 files changed, 28 insertions, 0 deletions
diff --git a/web/interface.rb b/web/interface.rb
new file mode 100644
index 0000000..5914866
--- /dev/null
+++ b/web/interface.rb
@@ -0,0 +1,9 @@
+require 'sinatra'
+require_relative '../db'
+
+$config = Config.first
+
+get '/' do
+ @posts = Post.all
+ erb :index
+end
diff --git a/web/views/index.erb b/web/views/index.erb
new file mode 100644
index 0000000..80e64a5
--- /dev/null
+++ b/web/views/index.erb
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8" />
+ <title><%= $config.title %></title>
+</head>
+<body>
+ <h1 id="title"><%= $config.title %></h1>
+ <% for post in @posts %>
+ <h2><%= post.title %></h2>
+ <div class="meta">
+ <p><%= post.created_at %></p>
+ </div>
+ <div class="content">
+ <%= post.body %>
+ </div>
+ <% end %>
+</body>
+</html>