Class: Jekyll::VersionPlugin::Tag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll_version_plugin.rb

Overview

A Jekyll Tag type that renders a version identifier for your Jekyll site sourced from the ‘git` repository containing your code.

Defined Under Namespace

Classes: SystemWrapper

Constant Summary collapse

NO_GIT_MESSAGE =
"Oops, are you sure this is a git project?".freeze
UNABLE_TO_PARSE_MESSAGE =
"Sorry, could not read the project version at the moment".freeze
OPTION_NOT_SPECIFIED =
nil
PARAMS =
[:type, :format].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_name, params, _tokens) ⇒ Tag

Returns a new instance of Tag.



30
31
32
33
34
35
# 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

Instance Attribute Details

#system_wrapper=(value) ⇒ Object

for testing



13
14
15
# File 'lib/jekyll_version_plugin.rb', line 13

def system_wrapper=(value)
  @system_wrapper = value
end

Instance Method Details

#render(_context) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/jekyll_version_plugin.rb', line 37

def render(_context)
  if git_repo?
    current_version.chomp
  else
    NO_GIT_MESSAGE
  end
end