Skip to content

Instantly share code, notes, and snippets.

@mikejarema
Forked from davidpaulsson/render_time.rb
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikejarema/2c31b9641bbb5a8fee94 to your computer and use it in GitHub Desktop.
Save mikejarema/2c31b9641bbb5a8fee94 to your computer and use it in GitHub Desktop.
# An example Jekyll Liquid tag. Utilizes the new plugin system.
#
# 1. Make a _plugins directory in your jekyll site, and put this class in a file there.
# 2. In anyone of your pages, you can use the 'render_time' liquid tag like so:
# {% render_time %} => November 27, 2014
#
# Or with a custom date format (format here: http://apidock.com/ruby/DateTime/strftime):
# {% render_time %b %d, %Y at %l:%M%P %} => Nov 27, 2014 at 4:38pm
module Jekyll
class RenderTimeTag < Liquid::Tag
DEFAULT_FORMAT = "%B %d, %Y"
def initialize(tag_name, text, tokens)
super
@format = (text && text.length > 0) ? text : DEFAULT_FORMAT
end
def render(context)
Time.now.strftime(@format)
end
end
end
Liquid::Template.register_tag('render_time', Jekyll::RenderTimeTag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment