Last active
December 12, 2015 06:39
-
-
Save boyvanamstel/4730804 to your computer and use it in GitHub Desktop.
Add an active state to your Octopress menu items
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
# This is the Danger Cove Active Menu plugin | |
# | |
# Installation: | |
# Place this file in your plugin directory. | |
# | |
# Usage: | |
# class="{% dcactivemenu checkfor.html [/another] %}" | |
# | |
# Returns 'active' when the checkfor.html occurs in the page.url | |
# | |
# Author: [email protected] | |
# Twitter: @dangercove | |
# | |
module Jekyll | |
class DCActiveMenu < Liquid::Tag | |
@check_for = nil | |
def initialize(tag_name, params, tokens) | |
@check_for = params.split(" ") | |
super | |
end | |
def render(context) | |
page_url = context.environments.first["page"]["url"] | |
if @check_for.count < 1 | |
return "Error processing input, expected syntax: {% dcactivemenu checkfor.html [/other.html] %}" | |
end | |
output = "" | |
for url in @check_for | |
if page_url.match(/^#{url.strip}/) | |
output = "active" | |
end | |
end | |
output | |
end | |
end | |
end | |
Liquid::Template.register_tag('dcactivemenu', Jekyll::DCActiveMenu) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment