File: new_inline_component.rb

package info (click to toggle)
ruby-view-component 4.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,832 kB
  • sloc: ruby: 8,385; sh: 166; makefile: 4
file content (30 lines) | stat: -rw-r--r-- 535 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

class Performance::NewInlineComponent < ViewComponent::Base
  class NestedComponent < ViewComponent::Base
    def initialize(name:)
      @name = name
    end

    erb_template <<~ERB
      <p>nested hello #{@name}</p>
    ERB
  end

  def initialize(name:)
    @name = name
  end

  erb_template <<~ERB
    <h1>hello #{@name}</h1>
    <%=
      safe_join(
        [
          content,
          50.times.map { render NestedComponent.new(name: @name) }
        ],
        "\n\n"
      )
    %>
  ERB
end