Created
May 11, 2016 14:49
-
-
Save Loschcode/74df1062f0460df3c515221b7b48d3e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# HTML | |
<ul> | |
<% Category.roots.each do |category| %> | |
<li class="col-md-2"> | |
<a href="#"><%= category.name %></a> | |
<% if !category.children.empty? %> | |
<ul> | |
<%= category.decorate.draw_tree %> <!-- TODO : refacto this, here we have very bad decorator methodology /!\ !--> | |
</ul> | |
<% end %> | |
</li> | |
<% end %> | |
</ul> | |
# DECORATOR | |
def draw_tree | |
=begin | |
children.each_with_object({}) do |child, memo| | |
memo[:name] = child.children.any? ? child.decorate.draw_tree : {} | |
end | |
=end | |
children.inject("") do |memo, child| # We should refacto this code and put the HTML in a view | |
memo << "<li class=\"dir\"><a href=\"#\">#{child.name}</a>" | |
memo << "<ul>#{child.decorate.draw_tree}</ul>" if not child.children.empty? | |
memo << "</li>" | |
end.html_safe | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment