From 469a4c2424a684524a8323a8a1a3727e1b6a4ed7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Tue, 2 Mar 2021 00:10:45 +0100 Subject: 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. --- web/interface.rb | 9 +++++++++ web/views/index.erb | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 web/interface.rb create mode 100644 web/views/index.erb 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 @@ + + + + + <%= $config.title %> + + +

<%= $config.title %>

+ <% for post in @posts %> +

<%= post.title %>

+
+

<%= post.created_at %>

+
+
+ <%= post.body %> +
+ <% end %> + + -- cgit v1.2.3