Skip to content

Instantly share code, notes, and snippets.

@marcaddeo
Created May 23, 2015 16:33
Show Gist options
  • Save marcaddeo/54882de6cbdc6ecea0aa to your computer and use it in GitHub Desktop.
Save marcaddeo/54882de6cbdc6ecea0aa to your computer and use it in GitHub Desktop.
Nav Menu
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="Marc Addeo">
<%= if assigns[:title] do %>
<title><%= @title %> | marc.cx</title>
<% else %>
<title>marc.cx</title>
<% end %>
<link href="http://fonts.googleapis.com/css?family=Inconsolata:400,700|Open+Sans:300italic,400italic,700,300,800,400" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link rel="stylesheet" href="<%= static_path(@conn, "/css/solarized_dark.css") %>">
<link rel="stylesheet" href="<%= static_path(@conn, "/css/app.css") %>">
</head>
<body>
<header>
<div class="container">
<div class="header">
<nav>
<ul class="nav nav-pills pull-right">
<%= for item <- navigation(@conn) do %>
<li role="presentation" ><a href="<%= item.href %>"><%= item.text %></a></li>
<%= end %>
</nav>
<a href="<%= page_path(@conn, :index) %>" class="title text-muted">marc.cx</a>
</div>
</div>
</header>
<%= @inner %>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script src="<%= static_path(@conn, "/js/highlight.pack.js") %>"></script>
<script src="<%= static_path(@conn, "/js/app.js") %>"></script>
<script>require("web/static/js/app")</script>
<script>hljs.initHighlightingOnLoad();</script>
</body>
</html>
defmodule MarcCx.LayoutView do
use MarcCx.Web, :view
def navigation(conn) do
nav = %{
:index => %{:text => 'Home', :href => page_path(conn, :index), :active => false},
:about => %{:text => 'About', :href => page_path(conn, :about), :active => false},
:github => %{:text => 'Github', :href => 'https://github.com/marcaddeo', :active => false}
}
active = case conn.path_info do
[] -> :index
["about"] -> :about
["article" | _] -> :article
_ -> :unknown
end
if Dict.has_key?(nav, active) do
nav = Dict.update!(nav, active, fn (item) -> %{item | :active => true} end)
end
nav
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment