jekyll_version_plugin 0.9.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +34 -0
- data/.rspec +3 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +92 -0
- data/Rakefile +8 -0
- data/jekyll_version_plugin.gemspec +22 -0
- data/lib/project_version_tag.rb +51 -0
- data/spec/project_version_tag_spec.rb +65 -0
- data/spec/spec_helper.rb +75 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4f212e4809aacf80791ca5e85082bd1000486bfa
|
4
|
+
data.tar.gz: 970b3ada7a49bb24e61836b10f48a15bf22bd3e6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4f18dfa10f299464dbe19c352fe72eb9459a6bf4d258af186be8f2a06ea8750d3f3d0eb66a9124263a824baba99adcf21120112ccad93b02a138c45a6ce46aad
|
7
|
+
data.tar.gz: b95383a0fe0b2e878f5d357da3ea13d31edc2b013fe9c20ad4c44acd3ba5d23f807118d91984ef001b8fed4ddea2dabe8016bbc3ab48b2ac96cc18e866d0d058
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
Gemfile.lock
|
30
|
+
.ruby-version
|
31
|
+
.ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Robert Murray
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
## jekyll-version-plugin
|
2
|
+
|
3
|
+
[](https://travis-ci.org/rob-murray/jekyll-version-plugin)
|
4
|
+
[](http://badge.fury.io/rb/jekyll-version-plugin)
|
5
|
+
|
6
|
+
### Description
|
7
|
+
|
8
|
+
A Liquid tag plugin for [Jekyll](http://jekyllrb.com/) that renders a version identifier for your Jekyll site sourced from the `git` repository containing your code. Great if you want to display the version of your project on your site dynamically each time your site is built.
|
9
|
+
|
10
|
+
Identify and highlight the build of your project by calling the tag from your Jekyll project.
|
11
|
+
|
12
|
+
```html
|
13
|
+
<p>Build: 3.0.0-5-ga189420</p>
|
14
|
+
```
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
<p>Build: {% project_version %}</p>
|
18
|
+
```
|
19
|
+
|
20
|
+
### Features
|
21
|
+
|
22
|
+
Stand back, hold onto your hats... the **jekyll-version-plugin** has 1x feature.
|
23
|
+
|
24
|
+
* Render a version of your project via `git`.
|
25
|
+
|
26
|
+
### Requirements
|
27
|
+
|
28
|
+
* Your project is version controlled in `git`.
|
29
|
+
|
30
|
+
### Usage
|
31
|
+
|
32
|
+
As mentioned by [Jekyll's documentation](http://jekyllrb.com/docs/plugins/#installing-a-plugin) you have two options; manually import the source file or require the plugin as a `gem`.
|
33
|
+
|
34
|
+
#### Require gem
|
35
|
+
|
36
|
+
Add the `jekyll-version-plugin` to your site `_config.yml` file for Jekyll to import the plugin as a gem.
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
gems: [jekyll-version-plugin]
|
40
|
+
```
|
41
|
+
|
42
|
+
#### Manual import
|
43
|
+
|
44
|
+
Just download the source file into your `_plugins` directory, e.g.
|
45
|
+
|
46
|
+
```bash
|
47
|
+
# Create the _plugins dir if needed and download project_version_tag plugin
|
48
|
+
$ mkdir -p _plugins && cd _plugins
|
49
|
+
$ wget https://raw.githubusercontent.com/rob-murray/jekyll-version-plugin/master/lib/project_version_tag.rb
|
50
|
+
```
|
51
|
+
|
52
|
+
#### Plugin tag usage
|
53
|
+
|
54
|
+
Wherever you want to display the version, just add the snippet below in your content and the version will be rendered when the Jekyll project is built.
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
{% project_version %}
|
58
|
+
```
|
59
|
+
|
60
|
+
This will simply output the version number, you can then apply your own styling as necessary. Or just `html` comment it out if you don't want it visible.
|
61
|
+
|
62
|
+
### Output
|
63
|
+
|
64
|
+
Happy path is a `git` repo with releases that are tagged, if this is the case then the output will be something like this;
|
65
|
+
|
66
|
+
`3.0.0-5-ga189420`
|
67
|
+
|
68
|
+
If the repository does not have any `tags` then it will grab the short sha of the last commit, for example;
|
69
|
+
|
70
|
+
`a189420`
|
71
|
+
|
72
|
+
If for any reason this fails then the output will just be a *sorry* message. Sorry about that.
|
73
|
+
|
74
|
+
`Sorry, could not read project version at the moment`
|
75
|
+
|
76
|
+
|
77
|
+
### Technical wizardry
|
78
|
+
|
79
|
+
The plugin just calls `git describe` - For more information see [git documentation](http://git-scm.com/docs/git-describe).
|
80
|
+
|
81
|
+
```bash
|
82
|
+
$ git describe --tags --long
|
83
|
+
```
|
84
|
+
|
85
|
+
### Contributions
|
86
|
+
|
87
|
+
Please use the GitHub pull-request mechanism to submit contributions.
|
88
|
+
|
89
|
+
### License
|
90
|
+
|
91
|
+
This project is available for use under the MIT software license.
|
92
|
+
See LICENSE
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'jekyll_version_plugin'
|
7
|
+
spec.version = '0.9.9'
|
8
|
+
spec.authors = ['Rob Murray']
|
9
|
+
spec.email = ['robmurray17@gmail.com']
|
10
|
+
spec.summary = %q{A Liquid tag plugin for Jekyll that renders a version identifier for your Jekyll site, sourced from the git repository.}
|
11
|
+
spec.homepage = 'https://github.com/rob-murray/jekyll-version-plugin'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ['lib']
|
18
|
+
|
19
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
20
|
+
spec.add_development_dependency 'rake'
|
21
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
22
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Jekyll
|
2
|
+
class ProjectVersionTag < Liquid::Tag
|
3
|
+
NO_GIT_MESSAGE = 'Oops, are you sure this is a git project?'
|
4
|
+
UNABLE_TO_PARSE_MESSAGE = 'Sorry, could not read project version at the moment'
|
5
|
+
|
6
|
+
def render(context)
|
7
|
+
if git_repo?
|
8
|
+
current_version.chomp
|
9
|
+
else
|
10
|
+
NO_GIT_MESSAGE
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def current_version
|
17
|
+
@_current_version ||= begin
|
18
|
+
# attempt to find the latest tag, falling back to last commit
|
19
|
+
version = git_describe || parse_head
|
20
|
+
|
21
|
+
version || UNABLE_TO_PARSE_MESSAGE
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def git_describe
|
26
|
+
tagged_version = %x{ git describe --tags }
|
27
|
+
|
28
|
+
if command_succeeded?
|
29
|
+
tagged_version
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def parse_head
|
34
|
+
head_commitish = %x{ git rev-parse --short HEAD }
|
35
|
+
|
36
|
+
if command_succeeded?
|
37
|
+
head_commitish
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def command_succeeded?
|
42
|
+
!$?.nil? && $?.success?
|
43
|
+
end
|
44
|
+
|
45
|
+
def git_repo?
|
46
|
+
system('git rev-parse')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
Liquid::Template.register_tag('project_version', Jekyll::ProjectVersionTag)
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Jekyll::ProjectVersionTag do
|
4
|
+
let(:git_test_command) { 'git rev-parse' }
|
5
|
+
let(:git_tag_command) { ' git describe --tags ' }
|
6
|
+
let(:git_last_commit_command) { ' git rev-parse --short HEAD ' }
|
7
|
+
let(:context) { nil }
|
8
|
+
|
9
|
+
subject { Jekyll::ProjectVersionTag.new }
|
10
|
+
|
11
|
+
before do
|
12
|
+
allow(subject).to receive(:system).and_return(true)
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'given no git repository' do
|
16
|
+
before do
|
17
|
+
allow(subject).to receive(:system).with(git_test_command).and_return(nil)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'returns an error message' do
|
21
|
+
expect(subject.render(context)).to match(/Oops/)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'given a git repository with no commits' do
|
26
|
+
before do
|
27
|
+
allow(subject).to receive(:`).with(git_last_commit_command).and_return(nil)
|
28
|
+
allow(subject).to receive(:`).with(git_tag_command).and_return(nil)
|
29
|
+
allow(subject).to receive(:command_succeeded?).and_return(true) # argh
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'returns an unable to read project message' do
|
33
|
+
expect(subject.render(context)).to match(/could not read project version/)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'given a git repository with a commit and no tag' do
|
38
|
+
before do
|
39
|
+
allow(subject).to receive(:`).with(git_last_commit_command).and_return('abcdefg')
|
40
|
+
allow(subject).to receive(:`).with(git_tag_command).and_return(nil)
|
41
|
+
allow(subject).to receive(:command_succeeded?).and_return(true) # argh
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'returns the last commit sha' do
|
45
|
+
expect(subject.render(context)).to eq('abcdefg')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'given a git repository with a commit and a tag' do
|
50
|
+
before do
|
51
|
+
allow(subject).to receive(:`).with(git_tag_command).and_return('v1.0.0')
|
52
|
+
allow(subject).to receive(:command_succeeded?).and_return(true) # argh
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'returns the last commit sha' do
|
56
|
+
expect(subject.render(context)).to eq('v1.0.0')
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'removes line ending from parsed value' do
|
60
|
+
allow(subject).to receive(:`).with(git_tag_command).and_return("v1.0.0\n")
|
61
|
+
|
62
|
+
expect(subject.render(context)).to eq('v1.0.0')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# Hack er stub Liquid classes and methods used in plugin
|
2
|
+
module Liquid
|
3
|
+
class Tag
|
4
|
+
end
|
5
|
+
class Template
|
6
|
+
def self.register_tag(foo, bar)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
project_root = File.dirname(File.absolute_path(__FILE__))
|
12
|
+
Dir.glob(project_root + '/../lib/*') { |file| require file }
|
13
|
+
|
14
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
15
|
+
RSpec.configure do |config|
|
16
|
+
# The settings below are suggested to provide a good initial experience
|
17
|
+
# with RSpec, but feel free to customize to your heart's content.
|
18
|
+
|
19
|
+
# These two settings work together to allow you to limit a spec run
|
20
|
+
# to individual examples or groups you care about by tagging them with
|
21
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
22
|
+
# get run.
|
23
|
+
config.filter_run :focus
|
24
|
+
config.run_all_when_everything_filtered = true
|
25
|
+
|
26
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
27
|
+
# file, and it's useful to allow more verbose output when running an
|
28
|
+
# individual spec file.
|
29
|
+
if config.files_to_run.one?
|
30
|
+
# Use the documentation formatter for detailed output,
|
31
|
+
# unless a formatter has already been configured
|
32
|
+
# (e.g. via a command-line flag).
|
33
|
+
config.default_formatter = 'doc'
|
34
|
+
end
|
35
|
+
|
36
|
+
# Print the 10 slowest examples and example groups at the
|
37
|
+
# end of the spec run, to help surface which specs are running
|
38
|
+
# particularly slow.
|
39
|
+
config.profile_examples = 10
|
40
|
+
|
41
|
+
# Run specs in random order to surface order dependencies. If you find an
|
42
|
+
# order dependency and want to debug it, you can fix the order by providing
|
43
|
+
# the seed, which is printed after each run.
|
44
|
+
# --seed 1234
|
45
|
+
config.order = :random
|
46
|
+
|
47
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
48
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
49
|
+
# test failures related to randomization by passing the same `--seed` value
|
50
|
+
# as the one that triggered the failure.
|
51
|
+
Kernel.srand config.seed
|
52
|
+
|
53
|
+
# rspec-expectations config goes here. You can use an alternate
|
54
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
55
|
+
# assertions if you prefer.
|
56
|
+
config.expect_with :rspec do |expectations|
|
57
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
58
|
+
# For more details, see:
|
59
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
60
|
+
expectations.syntax = :expect
|
61
|
+
end
|
62
|
+
|
63
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
64
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
65
|
+
config.mock_with :rspec do |mocks|
|
66
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
67
|
+
# For more details, see:
|
68
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
69
|
+
mocks.syntax = :expect
|
70
|
+
|
71
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
72
|
+
# a real object. This is generally recommended.
|
73
|
+
mocks.verify_partial_doubles = true
|
74
|
+
end
|
75
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll_version_plugin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.9
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rob Murray
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- robmurray17@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- jekyll_version_plugin.gemspec
|
70
|
+
- lib/project_version_tag.rb
|
71
|
+
- spec/project_version_tag_spec.rb
|
72
|
+
- spec/spec_helper.rb
|
73
|
+
homepage: https://github.com/rob-murray/jekyll-version-plugin
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.2.2
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: A Liquid tag plugin for Jekyll that renders a version identifier for your
|
97
|
+
Jekyll site, sourced from the git repository.
|
98
|
+
test_files:
|
99
|
+
- spec/project_version_tag_spec.rb
|
100
|
+
- spec/spec_helper.rb
|