Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to specify commit type
- Loading branch information
Robert Murray
committed
Aug 28, 2016
1 parent
433a6f6
commit 35d85e3
Showing
12 changed files
with
505 additions
and
208 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
language: ruby | ||
cache: bundler | ||
sudo: false | ||
rvm: | ||
- 1.9.3 | ||
- 2.0.0 | ||
- 2.1.0 | ||
- 2.2.0 | ||
- 2.3.0 | ||
- ruby-head | ||
script: 'bundle exec rake' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
source 'https://rubygems.org' | ||
# frozen_string_literal: true | ||
source "https://rubygems.org" | ||
|
||
# Specify your gem's dependencies in jekyll_version_plugin.gemspec | ||
gemspec |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
# frozen_string_literal: true | ||
require "bundler/gem_tasks" | ||
require 'rspec/core' | ||
require 'rspec/core/rake_task' | ||
require "rspec/core" | ||
require "rspec/core/rake_task" | ||
|
||
task :default => :spec | ||
task default: :spec | ||
|
||
desc "Run all specs in spec directory (excluding plugin specs)" | ||
RSpec::Core::RakeTask.new(:spec) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,24 @@ | ||
# coding: utf-8 | ||
lib = File.expand_path('../lib', __FILE__) | ||
# frozen_string_literal: true | ||
lib = File.expand_path("../lib", __FILE__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = 'jekyll_version_plugin' | ||
spec.version = '1.0.2' | ||
spec.authors = ['Rob Murray'] | ||
spec.email = ['robmurray17@gmail.com'] | ||
spec.summary = %q{A Liquid tag plugin for Jekyll that renders a version identifier for your Jekyll site, sourced from the git repository.} | ||
spec.homepage = 'https://github.com/rob-murray/jekyll-version-plugin' | ||
spec.license = 'MIT' | ||
spec.name = "jekyll_version_plugin" | ||
spec.version = "1.0.2" | ||
spec.authors = ["Rob Murray"] | ||
spec.email = ["robmurray17@gmail.com"] | ||
spec.summary = "A Liquid tag plugin for Jekyll that renders a version identifier for your Jekyll site, sourced from the git repository." | ||
spec.homepage = "https://github.com/rob-murray/jekyll-version-plugin" | ||
spec.license = "MIT" | ||
spec.required_ruby_version = ">= 1.9.3" | ||
|
||
spec.files = `git ls-files -z`.split("\x0") | ||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } | ||
spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) | ||
spec.require_paths = ['lib'] | ||
spec.require_paths = ["lib"] | ||
|
||
spec.add_development_dependency 'bundler', '~> 1.6' | ||
spec.add_development_dependency 'rake' | ||
spec.add_development_dependency 'rspec', '~> 3.0' | ||
spec.add_development_dependency "bundler", "~> 1.6" | ||
spec.add_development_dependency "rake" | ||
spec.add_development_dependency "rspec", "~> 3.5" | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,103 @@ | ||
# Want to use a different name for the tag class than the gem name :) | ||
require 'project_version_tag' | ||
# frozen_string_literal: true | ||
module Jekyll | ||
module VersionPlugin | ||
# A Jekyll Tag type that renders a version identifier for your Jekyll site | ||
# sourced from the `git` repository containing your code. | ||
# | ||
class Tag < Liquid::Tag | ||
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 | ||
|
||
attr_writer :system_wrapper # for testing | ||
|
||
# A wrapper around system calls; mock/stub this in testing | ||
class SystemWrapper | ||
def run(command) | ||
`#{command}` | ||
end | ||
|
||
def command_succeeded? | ||
!$?.nil? && $?.success? | ||
end | ||
|
||
def git_repo? | ||
system("git rev-parse") | ||
end | ||
end | ||
|
||
def initialize(_name, params, _tokens) | ||
super | ||
args = params.split(/\s+/).map(&:strip) | ||
# TODO: When min Ruby version is >=2.0 just use `to_h` | ||
@params = Hash[[:type, :format].zip(args)] | ||
end | ||
|
||
def render(_context) | ||
if git_repo? | ||
current_version.chomp | ||
else | ||
NO_GIT_MESSAGE | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :params | ||
|
||
# for testing | ||
def system_wrapper | ||
@system_wrapper ||= SystemWrapper.new | ||
end | ||
|
||
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 | ||
|
||
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 | ||
|
||
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 | ||
|
||
def run(command) | ||
system_wrapper.run(command) | ||
end | ||
|
||
def git_repo? | ||
system_wrapper.git_repo? | ||
end | ||
|
||
def command_succeeded? | ||
system_wrapper.command_succeeded? | ||
end | ||
end | ||
end | ||
end | ||
|
||
Liquid::Template.register_tag("project_version", Jekyll::VersionPlugin::Tag) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.