Skip to content

Instantly share code, notes, and snippets.

@garrett
Last active December 24, 2015 09:29
Show Gist options
  • Save garrett/6777662 to your computer and use it in GitHub Desktop.
Save garrett/6777662 to your computer and use it in GitHub Desktop.
middleman navbar from yaml
-# If data_source isn't specified in locals, then default to "navigation"
-#
-# Example for custom data_source:
-#
-# = partial :navbar, locals: { data_source: "navigation" }
-#
- data_source ||= "navigation"
-# Additional classes are also supported on the navbar
-#
-# Example:
-#
-# = partial :navbar, locals: { nav_class: "navbar_inverse" }
-#
- nav_class ||= "navbar-default"
-# Unless specified, the link for any brand used is /
-#
- brand_link ||= "/"
-# Navigation is automatically rendered from ../../data/{DATA_SOURCE}.yml
-# There is support for one-level depth.
-# Top level items should start with a "-"; second-level should be indented.
-#
-# Exmaple:
-#
-# - Foo: "foo_link"
-# - Bar: "optional_fallback_link_for_nojavascript"
-# Baz: "baz_link"
-# Baz2: "baz2_link"
-#
-# Foo is a normal link.
-# Bar is a dropdown title (with an optional link — it can be empty), as it has children
-# Baz and Baz2 are children links to Bar.
- if data.has_key? data_source
%nav.navbar(role="navigation" class="#{nav_class}")
.navbar-header
%button.navbar-toggle(data-toggle="collapse" data-target=".navbar-ex1-collapse")
%span.sr-only
Toggle navigation
- 3.times do
%span.icon-bar
- if defined? brand
%a.navbar-brand(href=brand_link)
= brand
.collapse.navbar-collapse.navbar-ex1-collapse
- data[data_source].each do |item|
%ul.nav.navbar-nav
- if item.is_a?(String)
%p.navbar-text= item
- elsif item.count == 1
- item.each do |text, link|
- if link
%li= link_to text, link
- else
%p.navbar-text= text
- else
%li.dropdown
%a.dropdown-toggle(data-toggle="dropdown" href="#{item.first[1] || '#'}")
= item.first[0]
%span.caret
%ul.dropdown-menu
- item.each do |text, link|
- unless text == item.first[0]
%li= link_to text, link
- home: "/"
- Menu1: "optional_nojs_fallback_link"
boo: "#bleh"
boo2: "#bleh"
- Menu w/o link:
boo: "#bleh"
- Blog: blog
- text string
- text string w/o a link:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment