Skip to content

Instantly share code, notes, and snippets.

@wmoxam

wmoxam/_nav.ecr Secret

Created June 8, 2022 04:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wmoxam/c17f42b09ac646d15f03aabb70eaab79 to your computer and use it in GitHub Desktop.
Save wmoxam/c17f42b09ac646d15f03aabb70eaab79 to your computer and use it in GitHub Desktop.
<ul>
<% _this_nav = nav %>
<% _this_nav.children.each do |child| %>
<li class="<%= child.css_class %>">
<a href="<%= child.path %>"><%= child.name %></a>
<% nav = child %>
<%= render "src/views/_nav.ecr" %>
</li>
<% end %>
</ul>
<html>
<head>
<title>Test</title>
</head>
<body>
<div class="layout">
<div class="navigation">
<%= render "src/views/_nav.ecr" %>
</div>
</div>
</body>
</html>
class Nav
property name : String
property css_class : String
property path : String
property children : Array(Nav)
def initialize
@name = ""
@css_class = ""
@path = ""
@children = [] of Nav
end
end
equire "kemal"
require "./nav"
get "/" do
path = "/"
nav = Nav.new
nav.name = "root"
nav.css_class = "branch"
nav.path = "/names/root"
nav1 = Nav.new
nav1.name = "child1"
nav1.css_class = "branch"
nav1.path = "/names/root/child1"
nav2 = Nav.new
nav2.name = "child2"
nav2.css_class = "leaf"
nav2.path = "/names/root/child1/child2"
nav3 = Nav.new
nav3.name = "root"
nav3.css_class = "child3"
nav3.path = "/names/root/child3"
nav.children = [nav1, nav3]
nav1.children = [nav2]
render "src/views/index.ecr"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment