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
- Host: GitHub
- URL: https://github.com/serradura/rails-components
- Owner: serradura
- Created: 2018-03-01T04:23:03.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-07-20T16:34:10.000Z (about 7 years ago)
- Last Synced: 2025-02-04T15:49:27.204Z (8 months ago)
- Topics: components, frontend-components, functional-programming-principles, rails, ruby, ruby-on-rails
- Language: Ruby
- Size: 34.2 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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/