Sha256: 9dc691db886de88c159b74e03a2ee45a6bd4328094e6be0a0043fc11bd5cbd9d
Contents?: true
Size: 1.05 KB
Versions: 3
Compression:
Stored size: 1.05 KB
Contents
module Jekyll class ProjectVersionTag < Liquid::Tag NO_GIT_MESSAGE = 'Oops, are you sure this is a git project?' UNABLE_TO_PARSE_MESSAGE = 'Sorry, could not read project version at the moment' def render(context) if git_repo? current_version.chomp else NO_GIT_MESSAGE end end private def current_version @_current_version ||= begin # attempt to find the latest tag, falling back to last commit version = git_describe || parse_head version || UNABLE_TO_PARSE_MESSAGE end end def git_describe tagged_version = %x{ git describe --tags } if command_succeeded? tagged_version end end def parse_head head_commitish = %x{ git rev-parse --short HEAD } if command_succeeded? head_commitish end end def command_succeeded? !$?.nil? && $?.success? end def git_repo? system('git rev-parse') end end end Liquid::Template.register_tag('project_version', Jekyll::ProjectVersionTag)
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
jekyll_version_plugin-1.0.1 | lib/project_version_tag.rb |
jekyll_version_plugin-1.0.0 | lib/project_version_tag.rb |
jekyll_version_plugin-0.9.9 | lib/project_version_tag.rb |