]> git.openstreetmap.org Git - rails.git/commitdiff
Add solid svg image helper
authorAnton Khorev <tony29@yandex.ru>
Sat, 16 Dec 2023 12:50:13 +0000 (15:50 +0300)
committerAnton Khorev <tony29@yandex.ru>
Tue, 19 Dec 2023 14:00:24 +0000 (17:00 +0300)
app/helpers/svg_helper.rb [new file with mode: 0644]
app/views/site/key.html.erb

diff --git a/app/helpers/svg_helper.rb b/app/helpers/svg_helper.rb
new file mode 100644 (file)
index 0000000..f2e02f7
--- /dev/null
@@ -0,0 +1,8 @@
+module SvgHelper
+  def solid_svg_image_tag(width, height, fill, **options)
+    svg = "<svg xmlns='http://www.w3.org/2000/svg' width='#{width}' height='#{height}'>" \
+          "<rect width='100%' height='100%' fill='#{fill}' />" \
+          "</svg>"
+    image_tag "data:image/svg+xml,#{u(svg)}", **options
+  end
+end
index 608932b3e4b20bd282692e66baf8500afc48a184..ddb3cbbefe8cfa8ef69ebaddc291c93a2610b4d3 100644 (file)
@@ -5,7 +5,7 @@
         <%= tag.tr :class => "mapkey-table-entry", :data => { :layer => layer_name, :zoom_min => entry["min_zoom"], :zoom_max => entry["max_zoom"] } do %>
           <td>
             <% 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>")}", :class => "d-block mx-auto" %>
+              <%= solid_svg_image_tag entry["width"], entry["height"], entry["fill"], :class => "d-block mx-auto" %>
             <% else %>
               <%= image_tag "key/#{layer_name}/#{entry['image']}", :class => "d-block mx-auto" %>
             <% end %>