Browse Source

[ruby/sinatra-sequel] Use erb for templates (#8990)

erb templates have better performance than slim templates. This also
makes it more inline with the Ruby/sinatra tests, which also use erb.
Petrik de Heus 1 year ago
parent
commit
b669efdbd0

+ 0 - 1
frameworks/Ruby/sinatra-sequel/Gemfile

@@ -5,7 +5,6 @@ gem 'passenger', '~> 6.0', :platforms=>[:ruby, :mswin], :require=>false
 gem 'puma', '~> 6.4', :require=>false
 gem 'sequel', '~> 5.0'
 gem 'sinatra', '~> 3.0', :require=>'sinatra/base'
-gem 'slim', '~> 3.0'
 gem 'unicorn', '~> 6.1', :platforms=>[:ruby, :mswin], :require=>false
 
 group :mysql do

+ 1 - 4
frameworks/Ruby/sinatra-sequel/hello_world.rb

@@ -1,8 +1,5 @@
 # frozen_string_literal: true
 
-# Configure Slim templating engine
-Slim::Engine.set_options :format=>:html, :sort_attrs=>false
-
 # Our Rack application to be executed by rackup
 class HelloWorld < Sinatra::Base
   configure do
@@ -73,7 +70,7 @@ class HelloWorld < Sinatra::Base
     )
     @fortunes.sort_by!(&:message)
 
-    slim :fortunes
+    erb :fortunes, :layout=>true
   end
 
   # Test type 5: Database updates

+ 12 - 0
frameworks/Ruby/sinatra-sequel/views/fortunes.erb

@@ -0,0 +1,12 @@
+<table>
+<tr>
+  <th>id</th>
+  <th>message</th>
+</tr>
+<% @fortunes.each do |fortune| %>
+<tr>
+  <td><%= fortune.id %></td>
+  <td><%= Rack::Utils.escape_html(fortune.message) %></td>
+</tr>
+<% end %>
+</table>

+ 0 - 8
frameworks/Ruby/sinatra-sequel/views/fortunes.slim

@@ -1,8 +0,0 @@
-table
-  tr
-    th id
-    th message
-  - for fortune in @fortunes
-    tr
-      td =fortune.id
-      td =fortune.message

+ 11 - 0
frameworks/Ruby/sinatra-sequel/views/layout.erb

@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>Fortunes</title>
+</head>
+
+<body>
+<%= yield %>
+</body>
+
+</html>

+ 0 - 6
frameworks/Ruby/sinatra-sequel/views/layout.slim

@@ -1,6 +0,0 @@
-doctype html
-html
-  head
-    title Fortunes
-  body
-    == yield