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. | |
| 5 | 1 | class AttributeShapes < Phlex::HTML |
| 6 | 1 | SHAPES = %i[title href src id class style data interpolated interpolated_only interpolated_href splat mixed conditional tokens nested prefixed_href].freeze |
| 7 | ||
| 8 | 1 | def initialize(shape, value) |
| 9 | 200 | @shape = shape |
| 10 | 200 | @value = value |
| 11 | end | |
| 12 | ||
| 13 | 1 | def view_template |
| 14 | 100 | case @shapeelse never taken |
| 15 | 9 | in :title then div(title: @value) |
| 16 | 4 | in :href then a(href: @value) |
| 17 | 6 | in :src then img(src: @value) |
| 18 | 7 | in :id then div(id: @value) |
| 19 | 9 | in :class then div(class: @value) |
| 20 | 5 | in :style then div(style: @value) |
| 21 | 8 | in :data then div(data: @value) |
| 22 | 10 | in :interpolated then div(title: "a #{@value}") { "x" } |
| 23 | 3 | in :interpolated_only then div(title: "#{@value}") { "x" } # rubocop:disable Style/RedundantInterpolation |
| 24 | 3 | in :interpolated_href then a(href: "#{@value}/") |
| 25 | 4 | in :splat then div(**@value) |
| 26 | 6 | in :mixed then a(id: "x", href: @value, class: ["a", @value], data: { value: @value }) |
| 27 | 6 | in :conditional then a(href: (@value ? "/yes" : "javascript:no()"), title: (@value ? "yes" : nil)) |
| 28 | 21 | in :tokens then div(class: ["a", ("b" if @value), (@value ? :c_d : nil)], title: @value) { "x" }else never takenelse never taken |
| 29 | 13 | in :nested then div(data: { a: "x", b: @value, c_d: @value }, aria: { label: @value }) { "x" } |
| 30 | 13 | in :prefixed_href then a(href: "/posts/#{@value}", title: "mailto:#{@value}") { a(href: "mailto:#{@value}") } |
| 31 | end | |
| 32 | rescue => error | |
| 33 | 36 | plain "!#{error.class}" |
| 34 | end | |
| 35 | end |