fixtures/attribute_shapes.rb

Lines

100%

24 of 24 covered

Branches

88%

22 of 25 covered

Methods

75%

3 of 4 covered

Never called
1# frozen_string_literal: true
2
3# Each shape passes a value to an element in a way the compiler compiles
4# differently. Errors are rescued so partial output is compared too.
51class AttributeShapes < Phlex::HTML
61 SHAPES = %i[title href src id class style data interpolated interpolated_only interpolated_href splat mixed conditional tokens nested prefixed_href].freeze
7
81 def initialize(shape, value)
9200 @shape = shape
10200 @value = value
11 end
12
131 def view_template
14100 case @shapeelse never taken
159 in :title then div(title: @value)
164 in :href then a(href: @value)
176 in :src then img(src: @value)
187 in :id then div(id: @value)
199 in :class then div(class: @value)
205 in :style then div(style: @value)
218 in :data then div(data: @value)
2210 in :interpolated then div(title: "a #{@value}") { "x" }
233 in :interpolated_only then div(title: "#{@value}") { "x" } # rubocop:disable Style/RedundantInterpolation
243 in :interpolated_href then a(href: "#{@value}/")
254 in :splat then div(**@value)
266 in :mixed then a(id: "x", href: @value, class: ["a", @value], data: { value: @value })
276 in :conditional then a(href: (@value ? "/yes" : "javascript:no()"), title: (@value ? "yes" : nil))
2821 in :tokens then div(class: ["a", ("b" if @value), (@value ? :c_d : nil)], title: @value) { "x" }else never takenelse never taken
2913 in :nested then div(data: { a: "x", b: @value, c_d: @value }, aria: { label: @value }) { "x" }
3013 in :prefixed_href then a(href: "/posts/#{@value}", title: "mailto:#{@value}") { a(href: "mailto:#{@value}") }
31 end
32 rescue => error
3336 plain "!#{error.class}"
34 end
35end