jensljungblad / elemental_components

Simple view components for Rails 5.1+
MIT License
76 stars 5 forks source link

Support any number of element levels, including no elements #15

Closed jensljungblad closed 6 years ago

jensljungblad commented 6 years ago

This is a suggestion for a slightly different API that would allow 1) capture HTML even when you have no elements and b) support any number of nested elements.

Scenario 1: No elements

<%= component "card" do %>
  foo
<% end %>
component.value == "foo"

Scenario 2: Single element

<%= component "card" do |c| %>
  <% c.header "foo" %>
<% end %>
component.value == ""
component.header.value == "foo"

Scenario 3: Nested element

<%= component "card" do |c| %>
  <% c.header do |cc| %>
    <% cc.left "foo" %>
  <% end %>
<% end %>
component.value == ""
component.header.value == ""
component.header.left.value == "foo"

Scenario 4: Nested element + element value

<%= component "card" do |c| %>
  <% c.header do |cc| %>
    <% cc.left "foo" %>
    bar
  <% end %>
<% end %>
component.value == ""
component.header.value == "bar"
component.header.left.value == "foo"