Created
May 14, 2013 07:22
-
-
Save Wolfr/5574261 to your computer and use it in GitHub Desktop.
require
This file contains hidden or 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
| module Jekyll | |
| class FileExistsTag < Liquid::Tag | |
| def initialize(tag_name, text, tokens) | |
| super | |
| @text = text | |
| end | |
| def render(context) | |
| # ref https://gist.github.com/vanto/1455726 | |
| # pipe param through liquid to make additional replacements possible | |
| # url = Liquid::Template.parse(@text).render context | |
| # this returns true | |
| # "#{@text} #{File.exist?("images/reference_designs/page-detail.png")}" | |
| # this returns false | |
| # "#{@text} #{File.exist?("images/reference_designs/page-detail-this-does-not-exist.png")}" | |
| # some suggestion on twitter to use pathname | |
| # "#{@text} #{Pathname.exists?(filename) ? filename : 'not-found-of-zoiets'}" | |
| end | |
| end | |
| end | |
| Liquid::Template.register_tag('file_exists', Jekyll::FileExistsTag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment