Skip to content

Instantly share code, notes, and snippets.

@snewman
Created April 9, 2015 08:35
Show Gist options
  • Save snewman/64a8c8e7d3345a3356a2 to your computer and use it in GitHub Desktop.
Save snewman/64a8c8e7d3345a3356a2 to your computer and use it in GitHub Desktop.
Middleman function to link to pages that exist, or print out that they need to be written
def pattern_link(pattern_name, link_name = nil)
pages = sitemap.resources.select{ | page | page.url.start_with?('/patterns/') and page.data.title == pattern_name}
if pages.empty?
puts "Need to write a pattern for " + pattern_name
return '<span class="pending_pattern">' + pattern_name + '</span>'
else
if pages.length > 1
puts "Warning: more than one pattern page for " + pattern_name
end
page = pages[0]
if not link_name
link_name = pattern_name
end
title = page.data.category + " Pattern: " + pattern_name
return '<a href="' + page.url + '" title="' + title + '" class="pattern">' + link_name +' </a>'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment