Skip to content

Commit

Permalink
revamp menu navigation generation
Browse files Browse the repository at this point in the history
  • Loading branch information
bloy committed Mar 2, 2014
1 parent 7805cec commit 89fe488
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 36 deletions.
21 changes: 0 additions & 21 deletions data/navigation.yml
@@ -1,22 +1 @@
site_title: Mike Bloy
main:
- id: index
title: Intro
url: /

- id: professional
title: Professional
url: /professional.html

- id: personal
title: Personal
url: /personal.html

- id: resume
title: Resume
url: /resume.html

- id: colophon
title: Colophon
url: /colophon.html

99 changes: 89 additions & 10 deletions helpers/nav_link_helpers.rb
@@ -1,17 +1,96 @@
module NavLinkHelpers
def nav_link(link)
content_tag(:li, {:id => "nav_#{link[:id]}"}) do
link_to(link[:title], link[:url],
title: (link[:extended_title] ? link[:extended_title] : link[:title]))
def main_menu_items
resources = sitemap.where(:menu => true).all
resources.map{ |resource| NavMenuItem.new(resource) }.sort
end

def social_menu_items
[ EmailMenuItem.new(data.contact.email) ] +
data.contact.social.map{|item| SocialMenuItem.new(item) }
end

def menu_item(item)
li_opts = {}
li_opts[:id] = "nav_#{item.html_id}" if item.html_id
content_tag(:li, li_opts) do
link_to(item.name, item.link, title: item.title)
end
end

end


class SocialMenuItem
def initialize(item)
@item = item
end

def name
@item[:title]
end

def title
@item[:extended_title] || @item[:title]
end

def link
@item[:url]
end

def html_id
@item[:id]
end
end


class EmailMenuItem < SocialMenuItem
def initialize(email)
@item = {
id: 'email',
title: 'Email',
extended_title: "Email: #{email}",
url: "mailto:#{email}"
}
end
end


class NavMenuItem
def initialize(resource)
@resource = resource
end

def name
if @resource.data.link && @resource.data.link.name
@resource.data.link.name
else
title
end
end

def email_nav_link
email = data.contact.email
nav_link(id: 'email',
title: 'Email',
extended_title: "Email: #{email}",
url: "mailto:#{email}")
def title
if @resource.data.link && @resource.data.link.title
@resource.data.link.title
elsif @resource.data.title
@resource.data.title
else
@resource.path.gsub(/#{@resource.ext}$/, '')
end
end

def link
@resource.url
end

def weight
@resource.data.weight.to_i
end

def <=>(other)
[weight, name] <=> [other.weight, other.name]
end

def html_id
@resource.path.gsub(/#{@resource.ext}$/, '')
end
end
2 changes: 2 additions & 0 deletions source/colophon.html.markdown
@@ -1,5 +1,7 @@
---
title: Colophon
menu: true
weight: 10
---
This site was written by hand in [VIM][vim], and designed directly in the
browser. It uses [jQuery][jquery] for behavior, but does not require javascript
Expand Down
6 changes: 6 additions & 0 deletions source/index.html.markdown
@@ -1,3 +1,9 @@
---
menu: true
weight: -1
link:
title: Introduction
---
I'm Mike Bloy. You either know me, or have heard of me, or Google has dropped
you here in a freak search engine accident.

Expand Down
9 changes: 4 additions & 5 deletions source/layouts/layout.erb
Expand Up @@ -6,8 +6,8 @@
<div id="page_content">
<nav id="content_links" class="nav_links">
<ul role="navigation">
<% data.navigation.main.each do |link| %>
<%= nav_link link %>
<% main_menu_items.each do |item| %>
<%= menu_item item %>
<% end %>
</ul>
</nav>
Expand All @@ -19,9 +19,8 @@

<nav id="social_links" class="nav_links">
<ul role="navigation">
<%= email_nav_link %>
<% data.contact.social.each do |social| %>
<%= nav_link social %>
<% social_menu_items.each do |item| %>
<%= menu_item item %>
<% end %>
</ul>
</nav>
Expand Down
1 change: 1 addition & 0 deletions source/personal.html.markdown
@@ -1,5 +1,6 @@
---
title: Personal
menu: true
---
I am a husband and father, with a wonderful wife and a school-age son.
My hobbies include photography, bicycling, tabletop and computer
Expand Down
2 changes: 2 additions & 0 deletions source/professional.html.markdown
@@ -1,5 +1,7 @@
---
title: Professional
menu: true
weight: -1
---
I'm a developer, linux consultant, web standards advocate, and
version control guru.
Expand Down
2 changes: 2 additions & 0 deletions source/resume.html.erb
@@ -1,5 +1,7 @@
---
layout: false
menu: true
title: Resume
---
<!DOCTYPE html>
<!-- /ht Paul Irish - http://front.ie/j5OMXi -->
Expand Down

0 comments on commit 89fe488

Please sign in to comment.