Przeglądaj źródła

Merge pull request #9673 from p8/roda/assume-fixed-locals

[ruby/roda-sequel] Enable assume_fixed_locals
Mike Smith 6 miesięcy temu
rodzic
commit
faf49d17c1

+ 3 - 3
frameworks/Ruby/roda-sequel/Gemfile.lock

@@ -5,16 +5,16 @@ GEM
     bigdecimal (3.1.9)
     erubi (1.13.1)
     iodine (0.7.58)
-    json (2.10.1)
+    json (2.10.2)
     kgio (2.11.4)
     mysql2 (0.5.6)
     nio4r (2.7.4)
     pg (1.5.9)
     puma (6.6.0)
       nio4r (~> 2.0)
-    rack (3.1.11)
+    rack (3.1.12)
     raindrops (0.20.1)
-    roda (3.89.0)
+    roda (3.90.0)
       rack
     sequel (5.90.0)
       bigdecimal

+ 5 - 5
frameworks/Ruby/roda-sequel/hello_world.rb

@@ -3,7 +3,7 @@
 # Our Rack application to be executed by rackup
 class HelloWorld < Roda
   plugin :hooks
-  plugin :render, escape: true, layout_opts: { cache_key: "default_layout" }
+  plugin :render, escape: true, assume_fixed_locals: true, template_opts: { extract_fixed_locals: true}, layout_opts: { cache_key: "default_layout" }
 
   def bounded_queries
     queries = request.params["queries"].to_i
@@ -57,13 +57,13 @@ class HelloWorld < Roda
     # Test type 4: Fortunes
     r.is "fortunes" do
       response[CONTENT_TYPE] = HTML_TYPE
-      @fortunes = Fortune.all
-      @fortunes << Fortune.new(
+      fortunes = Fortune.all
+      fortunes << Fortune.new(
         id: 0,
         message: "Additional fortune added at request time."
       )
-      @fortunes.sort_by!(&:message)
-      view :fortunes
+      fortunes.sort_by!(&:message)
+      view :fortunes, locals: { fortunes: fortunes }
     end
 
     # Test type 5: Database updates

+ 1 - 1
frameworks/Ruby/roda-sequel/views/fortunes.erb

@@ -3,7 +3,7 @@
   <th>id</th>
   <th>message</th>
 </tr>
-<% @fortunes.each do |fortune| %>
+<% fortunes.each do |fortune| %>
 <tr>
   <td><%= fortune.id %></td>
   <td><%= fortune.message %></td>