From d072b503f5ccc5d08f279aac463d37837cbbb576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Tue, 2 Mar 2021 21:35:44 +0100 Subject: Add 'post' and 'not_found' views --- interfaces/http/http.rb | 1 + interfaces/http/web/views/index.erb | 28 +++++++++------------------- interfaces/http/web/views/layout.erb | 11 +++++++++++ interfaces/http/web/views/not_found.erb | 3 +++ interfaces/http/web/views/post.erb | 7 +++++++ interfaces/http/web/web.rb | 15 +++++++++++++++ 6 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 interfaces/http/web/views/layout.erb create mode 100644 interfaces/http/web/views/not_found.erb create mode 100644 interfaces/http/web/views/post.erb diff --git a/interfaces/http/http.rb b/interfaces/http/http.rb index 8947890..0589c93 100644 --- a/interfaces/http/http.rb +++ b/interfaces/http/http.rb @@ -7,5 +7,6 @@ class HTTPInterface < Sinatra::Base require_relative 'web/web'; use WebInterface # require_relative 'admin/admin'; use AdminInterface # require_relative 'rss/rss'; use RSSInterface + run! if app_file == $0 end diff --git a/interfaces/http/web/views/index.erb b/interfaces/http/web/views/index.erb index 80e64a5..ee96a6c 100644 --- a/interfaces/http/web/views/index.erb +++ b/interfaces/http/web/views/index.erb @@ -1,19 +1,9 @@ - - - - - <%= $config.title %> - - -

<%= $config.title %>

- <% for post in @posts %> -

<%= post.title %>

-
-

<%= post.created_at %>

-
-
- <%= post.body %> -
- <% end %> - - +<% for post in @posts %> +

<%= post.title %>

+
+

<%= post.created_at.strftime('%e %b %Y') %>

+
+
+ <%= post.body %> +
+<% end %> diff --git a/interfaces/http/web/views/layout.erb b/interfaces/http/web/views/layout.erb new file mode 100644 index 0000000..2593992 --- /dev/null +++ b/interfaces/http/web/views/layout.erb @@ -0,0 +1,11 @@ + + + + + <%= @title %> + + +

<%= $config.title %>

+ <%= yield %> + + diff --git a/interfaces/http/web/views/not_found.erb b/interfaces/http/web/views/not_found.erb new file mode 100644 index 0000000..7a4228b --- /dev/null +++ b/interfaces/http/web/views/not_found.erb @@ -0,0 +1,3 @@ +

404 Not Found

+

The page you are looking for does not exist.

+

Go to front page.

diff --git a/interfaces/http/web/views/post.erb b/interfaces/http/web/views/post.erb new file mode 100644 index 0000000..1fe689a --- /dev/null +++ b/interfaces/http/web/views/post.erb @@ -0,0 +1,7 @@ +

<%= @post.title %>

+
+

<%= @post.created_at %>

+
+
+ <%= @post.body %> +
diff --git a/interfaces/http/web/web.rb b/interfaces/http/web/web.rb index ca04ecc..16492c2 100644 --- a/interfaces/http/web/web.rb +++ b/interfaces/http/web/web.rb @@ -1,6 +1,21 @@ class WebInterface < Sinatra::Base get '/' do + @title = $config.title @posts = Post.all erb :index end + + get '/:year/:month/:day/:slug' do + @posts = Post.where(slug: params['slug']) + + if @posts.empty? then + status 404 + @title = '404 Not Found' + erb :not_found + else + @post = @posts[0] + @title = @post.title + erb :post + end + end end -- cgit v1.2.3