An open API service indexing awesome lists of open source software.

https://github.com/serradura/rails-components


https://github.com/serradura/rails-components

components frontend-components functional-programming-principles rails ruby ruby-on-rails

Last synced: 6 months ago
JSON representation

Awesome Lists containing this project

README

          

Component-Based Rails App
=========================

Test the below examples in `app/blogs/index.html.erb`.

**#1 PORO helper components**

```erb

<%= safe_join @blogs.map(&method(:blogs_table_row)) %>

```

```erb

<% @blogs.each do |blog| %>
<%= blogs_table_row(blog) %>
<% end %>

```

```erb

<% @blogs.each_with_index do |blog, index| %>
<%=
blogs_table_row blog, -> do
content_tag(:strong, "Ahoy #{'!' * (index+1)}")
end
%>
<% end %>

```

**#2 Rails partial components**

```erb

<% @blogs.each do |blog| %>
<%= component(:row, blog: blog) %>
<% end %>

```

```erb

<% @blogs.each_with_index do |blog, index| %>
<%= component(:row, blog: blog) do %>
Ahoy<%= '!' * (index+1) %>
<% end %>
<% end %>

```

Extras:
-------

Test the following snippets in `rails console`:

```ruby
tags = Components::Tags.new(helper)

tags.br
#=> "
"

tags.br style: 'margin-top: 10px'
#=> "
"

tags.ul
#=> "

    "

    tags.ul [1,2,3].map &tags.method(:li)
    #=> "


    • 1

    • 2

    • 3

    "
    ```

    Related resources:
    ------------------
    * https://www.innoq.com/en/blog/rails-frontend-components
    * https://goiabada.blog/rails-components-faedd412ce19
    * https://www.igvita.com/2007/03/15/block-helpers-and-dry-views-in-rails/
    * http://blog.plataformatec.com.br/2011/04/default-views-in-rails-3-0-with-custom-resolvers/