class Jekyll::VersionPlugin::Tag
A Jekyll
Tag
type that renders a version identifier for your Jekyll
site sourced from the `git` repository containing your code.
Constants
- NO_GIT_MESSAGE
- OPTION_NOT_SPECIFIED
- PARAMS
- UNABLE_TO_PARSE_MESSAGE
Attributes
params[R]
system_wrapper[W]
Public Class Methods
new(_name, params, _tokens)
click to toggle source
Calls superclass method
# File lib/jekyll_version_plugin.rb, line 30 def initialize(_name, params, _tokens) super args = params.split(/\s+/).map(&:strip) # TODO: When min Ruby version is >=2.1 just use `to_h` @params = Hash[PARAMS.zip(args)] end
Public Instance Methods
render(_context)
click to toggle source
# File lib/jekyll_version_plugin.rb, line 37 def render(_context) if git_repo? current_version.chomp else NO_GIT_MESSAGE end end
Private Instance Methods
command_succeeded?()
click to toggle source
# File lib/jekyll_version_plugin.rb, line 97 def command_succeeded? system_wrapper.command_succeeded? end
current_version()
click to toggle source
# File lib/jekyll_version_plugin.rb, line 54 def current_version @_current_version ||= begin version = case params.fetch(:type, "tag") when "tag", OPTION_NOT_SPECIFIED git_describe || parse_head when "commit" parse_head end version || UNABLE_TO_PARSE_MESSAGE end end
git_describe()
click to toggle source
# File lib/jekyll_version_plugin.rb, line 67 def git_describe tagged_version = case params.fetch(:format, "short") when "short", OPTION_NOT_SPECIFIED run("git describe --tags --always") when "long" run("git describe --tags --always --long") end tagged_version if command_succeeded? end
git_repo?()
click to toggle source
# File lib/jekyll_version_plugin.rb, line 93 def git_repo? system_wrapper.git_repo? end
parse_head()
click to toggle source
# File lib/jekyll_version_plugin.rb, line 78 def parse_head head_commitish = case params.fetch(:format, "short") when "short", OPTION_NOT_SPECIFIED run("git rev-parse --short HEAD") when "long" run("git rev-parse HEAD") end head_commitish if command_succeeded? end
run(command)
click to toggle source
# File lib/jekyll_version_plugin.rb, line 89 def run(command) system_wrapper.run(command) end
system_wrapper()
click to toggle source
for testing
# File lib/jekyll_version_plugin.rb, line 50 def system_wrapper @system_wrapper ||= SystemWrapper.new end