Rename key_svg_tag to legend_svg_tag in svg_helper

This commit is contained in:
Marwin Hochfelsner
2025-06-17 06:42:34 +02:00
parent e9978bba8f
commit 6b450a6c13
3 changed files with 24 additions and 24 deletions

View File

@ -13,7 +13,7 @@ module SvgHelper
adjacent_page_svg_tag(dir == "rtl" ? -1 : 1, **)
end
def key_svg_tag(**options)
def legend_svg_tag(**options)
border_width = options["border"] ? (options["border-width"] || 1) : 0
rect_attrs = {
:width => "100%",

View File

@ -7,7 +7,7 @@
<% if entry["image"] %>
<%= image_tag "key/#{layer_name}/#{entry['image']}", :class => "filtered-image d-block mx-auto" %>
<% else %>
<%= key_svg_tag :class => "filtered-image d-block mx-auto", **entry %>
<%= legend_svg_tag :class => "filtered-image d-block mx-auto", **entry %>
<% end %>
</td>
<td>

View File

@ -1,8 +1,8 @@
require "test_helper"
class SvgHelperTest < ActionView::TestCase
def test_key_fill
svg = key_svg_tag("width" => 60, "height" => 40, "fill" => "green")
def test_legend_fill
svg = legend_svg_tag("width" => 60, "height" => 40, "fill" => "green")
expected = <<~HTML.gsub(/\n\s*/, "")
<svg width="60" height="40">
<rect width="100%" height="100%" fill="green" />
@ -11,8 +11,8 @@ class SvgHelperTest < ActionView::TestCase
assert_dom_equal expected, svg
end
def test_key_border
svg = key_svg_tag("width" => 60, "height" => 40, "border" => "red")
def test_legend_border
svg = legend_svg_tag("width" => 60, "height" => 40, "border" => "red")
expected = <<~HTML.gsub(/\n\s*/, "")
<svg width="60" height="40">
<rect x="0.5" y="0.5" width="59" height="39" fill="none" stroke="red" />
@ -21,8 +21,8 @@ class SvgHelperTest < ActionView::TestCase
assert_dom_equal expected, svg
end
def test_key_border_width
svg = key_svg_tag("width" => 60, "height" => 40, "border" => "red", "border-width" => 3)
def test_legend_border_width
svg = legend_svg_tag("width" => 60, "height" => 40, "border" => "red", "border-width" => 3)
expected = <<~HTML.gsub(/\n\s*/, "")
<svg width="60" height="40">
<rect x="1.5" y="1.5" width="57" height="37" fill="none" stroke="red" stroke-width="3" />
@ -31,8 +31,8 @@ class SvgHelperTest < ActionView::TestCase
assert_dom_equal expected, svg
end
def test_key_border_with_integer_coords
svg = key_svg_tag("width" => 60, "height" => 40, "border" => "red", "border-width" => 2)
def test_legend_border_with_integer_coords
svg = legend_svg_tag("width" => 60, "height" => 40, "border" => "red", "border-width" => 2)
expected = <<~HTML.gsub(/\n\s*/, "")
<svg width="60" height="40">
<rect x="1" y="1" width="58" height="38" fill="none" stroke="red" stroke-width="2" />
@ -41,8 +41,8 @@ class SvgHelperTest < ActionView::TestCase
assert_dom_equal expected, svg
end
def test_key_border_fractional_width
svg = key_svg_tag("width" => 60, "height" => 40, "border" => "red", "border-width" => 1.5)
def test_legend_border_fractional_width
svg = legend_svg_tag("width" => 60, "height" => 40, "border" => "red", "border-width" => 1.5)
expected = <<~HTML.gsub(/\n\s*/, "")
<svg width="60" height="40">
<rect x="0.75" y="0.75" width="58.5" height="38.5" fill="none" stroke="red" stroke-width="1.5" />
@ -51,8 +51,8 @@ class SvgHelperTest < ActionView::TestCase
assert_dom_equal expected, svg
end
def test_key_line
svg = key_svg_tag("width" => 80, "height" => 15, "line" => "blue")
def test_legend_line
svg = legend_svg_tag("width" => 80, "height" => 15, "line" => "blue")
expected = <<~HTML.gsub(/\n\s*/, "")
<svg width="80" height="15">
<path d="M0,7.5 H80" stroke="blue" />
@ -61,8 +61,8 @@ class SvgHelperTest < ActionView::TestCase
assert_dom_equal expected, svg
end
def test_key_line_width
svg = key_svg_tag("width" => 80, "height" => 15, "line" => "blue", "line-width" => 3)
def test_legend_line_width
svg = legend_svg_tag("width" => 80, "height" => 15, "line" => "blue", "line-width" => 3)
expected = <<~HTML.gsub(/\n\s*/, "")
<svg width="80" height="15">
<path d="M0,7.5 H80" stroke="blue" stroke-width="3" />
@ -71,8 +71,8 @@ class SvgHelperTest < ActionView::TestCase
assert_dom_equal expected, svg
end
def test_key_line_with_integer_coords
svg = key_svg_tag("width" => 80, "height" => 20, "line" => "blue")
def test_legend_line_with_integer_coords
svg = legend_svg_tag("width" => 80, "height" => 20, "line" => "blue")
expected = <<~HTML.gsub(/\n\s*/, "")
<svg width="80" height="20">
<path d="M0,10 H80" stroke="blue" />
@ -81,8 +81,8 @@ class SvgHelperTest < ActionView::TestCase
assert_dom_equal expected, svg
end
def test_key_casing
svg = key_svg_tag("width" => 80, "height" => 20, "casing" => "yellow")
def test_legend_casing
svg = legend_svg_tag("width" => 80, "height" => 20, "casing" => "yellow")
expected = <<~HTML.gsub(/\n\s*/, "")
<svg width="80" height="20">
<path d="M0,0.5 H80 M0,19.5 H80" stroke="yellow" />
@ -91,8 +91,8 @@ class SvgHelperTest < ActionView::TestCase
assert_dom_equal expected, svg
end
def test_key_casing_width
svg = key_svg_tag("width" => 80, "height" => 20, "casing" => "yellow", "casing-width" => 5)
def test_legend_casing_width
svg = legend_svg_tag("width" => 80, "height" => 20, "casing" => "yellow", "casing-width" => 5)
expected = <<~HTML.gsub(/\n\s*/, "")
<svg width="80" height="20">
<path d="M0,2.5 H80 M0,17.5 H80" stroke="yellow" stroke-width="5" />
@ -101,8 +101,8 @@ class SvgHelperTest < ActionView::TestCase
assert_dom_equal expected, svg
end
def test_key_casing_with_integer_coords
svg = key_svg_tag("width" => 80, "height" => 20, "casing" => "yellow", "casing-width" => 2)
def test_legend_casing_with_integer_coords
svg = legend_svg_tag("width" => 80, "height" => 20, "casing" => "yellow", "casing-width" => 2)
expected = <<~HTML.gsub(/\n\s*/, "")
<svg width="80" height="20">
<path d="M0,1 H80 M0,19 H80" stroke="yellow" stroke-width="2" />