]> git.openstreetmap.org Git - rails.git/commitdiff
Load map key data in controller
authorAnton Khorev <tony29@yandex.ru>
Fri, 8 Dec 2023 09:55:18 +0000 (12:55 +0300)
committerAnton Khorev <tony29@yandex.ru>
Fri, 8 Dec 2023 09:55:18 +0000 (12:55 +0300)
app/controllers/site_controller.rb
app/views/site/key.html.erb

index 5fb8aa111183455586693a2f601024e40e674d55..dce5faf54d3f43072bbdd2631015c2b3f12fa045 100644 (file)
@@ -48,6 +48,7 @@ class SiteController < ApplicationController
 
   def key
     expires_in 7.days, :public => true
+    @key = YAML.load_file(Rails.root.join("config/key.yml"))
     render :layout => false
   end
 
index d3da868569dbd97fff87ab6b927ed6f93525f654..60eff9a445d6ace0a15af81cec00414575fd48d6 100644 (file)
@@ -1,13 +1,13 @@
 <div id="mapkey">
   <table class="table table-sm table-borderless mapkey-table mb-0">
-    <% YAML.load_file(Rails.root.join("config/key.yml")).each do |name,data| %>
-      <% data.each do |entry| %>
-        <%= tag.tr :class => "mapkey-table-entry", :data => { :layer => name, :zoom_min => entry["min_zoom"], :zoom_max => entry["max_zoom"] } do %>
+    <% @key.each do |layer_name, layer_data| %>
+      <% layer_data.each do |entry| %>
+        <%= tag.tr :class => "mapkey-table-entry", :data => { :layer => layer_name, :zoom_min => entry["min_zoom"], :zoom_max => entry["max_zoom"] } do %>
           <td class="mapkey-table-key align-middle">
             <% if entry["width"] && entry["height"] && entry["fill"] %>
               <%= image_tag "data:image/svg+xml,#{u("<svg xmlns='http://www.w3.org/2000/svg' width='#{entry['width']}' height='#{entry['height']}'><rect width='100%' height='100%' fill='#{entry['fill']}' /></svg>")}" %>
             <% else %>
-              <%= image_tag "key/#{name}/#{entry['image']}" %>
+              <%= image_tag "key/#{layer_name}/#{entry['image']}" %>
             <% end %>
           </td>
           <td class="mapkey-table-value">