jensljungblad / elemental_components

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

Attributes & Elements #9

Closed jensljungblad closed 6 years ago

jensljungblad commented 6 years ago

This PR fixes #6 and introduces a number of new features:

This allows for something like:

class Card < Components::Component
  attribute :id

  has_one :header
  has_many :sections do
    attribute :size
  end
end
<%= component "card", id: "card-1", do |c| %>
  <% c.header do %>
    A header with some <em>captured</em> content
  <% end %>
  <% c.sections size: "large" do %>
    A large captured section
  <% end %>
  <% c.sections size: "small" do %>
    A small captured section
  <% end %>
<% end %>

Or a navigation component:

class Navigation < Components::Component
  has_many :items do
    attribute :url
    attribute :active, default: false
  end
end
<%= component "navigation" do |c| %>
  <% c.items "Home", url: root_path %>
  <% c.items "Explore", url: explore_path, active: true %>
<% end %>

Also adds some overdue unit tests.

Todo