jekyll_version_plugin 1.0.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc5371b539ad99125d29732e6269b33d26a4b927
4
- data.tar.gz: ec641e5218d09f6e121778a610fd0f353ae00aca
3
+ metadata.gz: 68d8e97550c3b0f425535b32e072407663d37083
4
+ data.tar.gz: c9e3d192583b5832dbf5157c82cd561efb95ca0e
5
5
  SHA512:
6
- metadata.gz: d124e1673754cff8223959f88c58d1c0760f9b8bda923286c3fc114e6e2e6b2d31fbe3fe8678cf77e051b17eb46b6fc2492111aea92df68d1525d2758fc005e9
7
- data.tar.gz: ebac6aed07690cf48de721245c4fcdc75451908ed4f872003fbbf5b97d7ba6ee82f0975fcce0f711943651f81f8ab5baf6e0f686cfa2f7f7e66e9a1b9d700e92
6
+ metadata.gz: c3e7189e48cc678756333a86085dcd7fe9b7dd0b304f73468a7a0597fba596af056b8637137f05b1bea5ec253d5710e7c068dbe5255cb36422b134180afd66c8
7
+ data.tar.gz: 083a696156c02dd05fc1da7b5712241cb6f9dae531633f68c544580aab974e0bd1b8477faeb880f55d1c3a34e4b793192c6bfa825c80d91fef72f2201f4e6e84
@@ -1,9 +1,11 @@
1
1
  language: ruby
2
2
  cache: bundler
3
+ sudo: false
3
4
  rvm:
4
5
  - 1.9.3
5
6
  - 2.0.0
6
7
  - 2.1.0
7
8
  - 2.2.0
9
+ - 2.3.0
8
10
  - ruby-head
9
11
  script: 'bundle exec rake'
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
+ source "https://rubygems.org"
2
3
 
3
4
  # Specify your gem's dependencies in jekyll_version_plugin.gemspec
4
5
  gemspec
data/README.md CHANGED
@@ -5,35 +5,44 @@
5
5
 
6
6
  ### Description
7
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.
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 automatically each time your site is built.
9
9
 
10
10
  Identify and highlight the build of your project by calling the tag from your Jekyll project.
11
11
 
12
+ ##### This Jekyll view code will generate ...
13
+
14
+ Given a `git` repo with the latest tag of *3.0.0* and *5* commits since tagged, the commit `ga189420` being the latest.
15
+
12
16
  ```ruby
13
- # this Jekyll view code will generate ...
14
17
  <p>Build: {% project_version %}</p>
15
18
  ```
16
19
 
20
+ ##### This html
21
+
17
22
  ```html
18
- <!-- this html -->
19
23
  <p>Build: 3.0.0-5-ga189420</p>
20
24
  ```
21
25
 
22
26
 
23
27
  ### Features
24
28
 
25
- Stand back, hold onto your hats... the **jekyll-version-plugin** has 1x feature.
29
+ The **jekyll-version-plugin** has 1x feature with a few options;
26
30
 
27
31
  * Render a version of your project via `git`.
32
+ * Use the `git-describe` command with *long* or *short* option
33
+ * Use the `git rev-parse` on **HEAD** with *long* or *short* option
34
+
28
35
 
29
36
  ### Requirements
30
37
 
31
38
  * Your project is version controlled in `git`.
32
39
 
40
+
33
41
  ### Usage
34
42
 
35
43
  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`.
36
44
 
45
+
37
46
  #### Require gem
38
47
 
39
48
  Add the `jekyll_version_plugin` to your site `_config.yml` file for Jekyll to import the plugin as a gem.
@@ -42,6 +51,7 @@ Add the `jekyll_version_plugin` to your site `_config.yml` file for Jekyll to im
42
51
  gems: ['jekyll_version_plugin']
43
52
  ```
44
53
 
54
+
45
55
  #### Manual import
46
56
 
47
57
  Just download the source file into your `_plugins` directory, e.g.
@@ -49,29 +59,57 @@ Just download the source file into your `_plugins` directory, e.g.
49
59
  ```bash
50
60
  # Create the _plugins dir if needed and download project_version_tag plugin
51
61
  $ mkdir -p _plugins && cd _plugins
52
- $ wget https://raw.githubusercontent.com/rob-murray/jekyll-version-plugin/master/lib/project_version_tag.rb
62
+ $ wget https://raw.githubusercontent.com/rob-murray/jekyll-version-plugin/master/lib/jekyll_version_plugin.rb
53
63
  ```
54
64
 
65
+
55
66
  #### Plugin tag usage
56
67
 
57
- 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.
68
+ The plugin can be called anywhere in your template with or without parameters;
69
+
70
+ ```ruby
71
+ {% project_version *params %}
72
+ {% project_version type format %}
73
+ ```
74
+
75
+ * **type** is what to use for versioning, either `tag` or `commit` - defaults to `tag`
76
+ * **format** is the format of the output, `short` or `long` - defaults to `short`
77
+
78
+ Wherever you want to display the version, just add one of the snippets below in your content and the version will be rendered when the Jekyll project is built.
79
+
58
80
 
59
81
  ```ruby
60
- {% project_version %}
82
+ # Default options of `tag short`
83
+ {% project_version %} # => will run `git describe --tags --always`
84
+
85
+ # To render a short tag description like `3.0.0`
86
+ {% project_version tag short %} # => will run `git describe --tags --always`
87
+
88
+ # To render a more details tag description like `3.0.0-5-ga189420`
89
+ {% project_version tag long %} # => will run `git describe --tags --always --long`
90
+
91
+ # To render a short commitish like `151ebce`
92
+ {% project_version commit short %} # => will run `git rev-parse --short HEAD`
93
+
94
+ # To render a longer commitsh like `151ebce149c5886bcf2923db18d73742901eb976`
95
+ {% project_version commit long %} # => will run `git rev-parse HEAD`
61
96
  ```
62
97
 
63
98
  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.
64
99
 
100
+
65
101
  ### Output
66
102
 
67
103
  Happy path is a `git` repo with releases that are tagged, if this is the case then the output will be something like this;
68
104
 
69
105
  `3.0.0` or `3.0.0-5-ga189420`
70
106
 
71
- If the repository does not have any `tags` then it will grab the short sha of the last commit, for example;
107
+ If you select the *commit* option then the output will be something like this;
72
108
 
73
109
  `a189420`
74
110
 
111
+ If you have selected the *tags* option and the repository does not have any `tags` then it will grab the short sha of the last commit, see above;
112
+
75
113
  If for any reason this fails then the output will just be a *sorry* message. Sorry about that.
76
114
 
77
115
  `Sorry, could not read project version at the moment`
@@ -79,16 +117,19 @@ If for any reason this fails then the output will just be a *sorry* message. Sor
79
117
 
80
118
  ### Technical wizardry
81
119
 
82
- The plugin just calls `git describe` - For more information see [git documentation](http://git-scm.com/docs/git-describe).
120
+ The plugin just calls `git describe` or `git rev-parse HEAD` - For more information see [git-describe](http://git-scm.com/docs/git-describe) and [git rev-parse](https://git-scm.com/docs/git-rev-parse).
83
121
 
84
122
  ```bash
85
123
  $ git describe --tags --long
124
+ $ git rev-parse --short HEAD
86
125
  ```
87
126
 
127
+
88
128
  ### Contributions
89
129
 
90
130
  Please use the GitHub pull-request mechanism to submit contributions.
91
131
 
132
+
92
133
  ### License
93
134
 
94
135
  This project is available for use under the MIT software license.
data/Rakefile CHANGED
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
1
2
  require "bundler/gem_tasks"
2
- require 'rspec/core'
3
- require 'rspec/core/rake_task'
3
+ require "rspec/core"
4
+ require "rspec/core/rake_task"
4
5
 
5
- task :default => :spec
6
+ task default: :spec
6
7
 
7
8
  desc "Run all specs in spec directory (excluding plugin specs)"
8
9
  RSpec::Core::RakeTask.new(:spec)
@@ -1,22 +1,24 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
2
+ # frozen_string_literal: true
3
+ lib = File.expand_path("../lib", __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
 
5
6
  Gem::Specification.new do |spec|
6
- spec.name = 'jekyll_version_plugin'
7
- spec.version = '1.0.2'
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'
7
+ spec.name = "jekyll_version_plugin"
8
+ spec.version = "2.0.0"
9
+ spec.authors = ["Rob Murray"]
10
+ spec.email = ["robmurray17@gmail.com"]
11
+ spec.summary = "A Liquid tag plugin for Jekyll that renders a version identifier for your Jekyll site, sourced from the git repository."
12
+ spec.homepage = "https://github.com/rob-murray/jekyll-version-plugin"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 1.9.3"
13
15
 
14
16
  spec.files = `git ls-files -z`.split("\x0")
15
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
- spec.require_paths = ['lib']
19
+ spec.require_paths = ["lib"]
18
20
 
19
- spec.add_development_dependency 'bundler', '~> 1.6'
20
- spec.add_development_dependency 'rake'
21
- spec.add_development_dependency 'rspec', '~> 3.0'
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", "~> 3.5"
22
24
  end
@@ -1,2 +1,104 @@
1
- # Want to use a different name for the tag class than the gem name :)
2
- require 'project_version_tag'
1
+ # frozen_string_literal: true
2
+ module Jekyll
3
+ module VersionPlugin
4
+ # A Jekyll Tag type that renders a version identifier for your Jekyll site
5
+ # sourced from the `git` repository containing your code.
6
+ #
7
+ class Tag < Liquid::Tag
8
+ NO_GIT_MESSAGE = "Oops, are you sure this is a git project?".freeze
9
+ UNABLE_TO_PARSE_MESSAGE = "Sorry, could not read the project version at the moment".freeze
10
+ OPTION_NOT_SPECIFIED = nil
11
+ PARAMS = [:type, :format].freeze
12
+
13
+ attr_writer :system_wrapper # for testing
14
+
15
+ # A wrapper around system calls; mock/stub this in testing
16
+ class SystemWrapper
17
+ def run(command)
18
+ `#{command}`
19
+ end
20
+
21
+ def command_succeeded?
22
+ !$?.nil? && $?.success?
23
+ end
24
+
25
+ def git_repo?
26
+ system("git rev-parse")
27
+ end
28
+ end
29
+
30
+ def initialize(_name, params, _tokens)
31
+ super
32
+ args = params.split(/\s+/).map(&:strip)
33
+ # TODO: When min Ruby version is >=2.1 just use `to_h`
34
+ @params = Hash[PARAMS.zip(args)]
35
+ end
36
+
37
+ def render(_context)
38
+ if git_repo?
39
+ current_version.chomp
40
+ else
41
+ NO_GIT_MESSAGE
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ attr_reader :params
48
+
49
+ # for testing
50
+ def system_wrapper
51
+ @system_wrapper ||= SystemWrapper.new
52
+ end
53
+
54
+ def current_version
55
+ @_current_version ||= begin
56
+ version = case params.fetch(:type, "tag")
57
+ when "tag", OPTION_NOT_SPECIFIED
58
+ git_describe || parse_head
59
+ when "commit"
60
+ parse_head
61
+ end
62
+
63
+ version || UNABLE_TO_PARSE_MESSAGE
64
+ end
65
+ end
66
+
67
+ def git_describe
68
+ tagged_version = case params.fetch(:format, "short")
69
+ when "short", OPTION_NOT_SPECIFIED
70
+ run("git describe --tags --always")
71
+ when "long"
72
+ run("git describe --tags --always --long")
73
+ end
74
+
75
+ tagged_version if command_succeeded?
76
+ end
77
+
78
+ def parse_head
79
+ head_commitish = case params.fetch(:format, "short")
80
+ when "short", OPTION_NOT_SPECIFIED
81
+ run("git rev-parse --short HEAD")
82
+ when "long"
83
+ run("git rev-parse HEAD")
84
+ end
85
+
86
+ head_commitish if command_succeeded?
87
+ end
88
+
89
+ def run(command)
90
+ system_wrapper.run(command)
91
+ end
92
+
93
+ def git_repo?
94
+ system_wrapper.git_repo?
95
+ end
96
+
97
+ def command_succeeded?
98
+ system_wrapper.command_succeeded?
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ Liquid::Template.register_tag("project_version", Jekyll::VersionPlugin::Tag)
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+ # Basic integration example - run code against a dummy repo
3
+ #
4
+ # * Requires git configured on the machine.
5
+ #
6
+ # Create a tmp dir and create a dummy git repo, run code at various stages,
7
+ # eg no commits, a commit, a tag, etc.
8
+ #
9
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
10
+ require_relative "./support/jekyll_template"
11
+ require "jekyll_version_plugin"
12
+ require "tmpdir"
13
+
14
+ RUN_OPTIONS = [
15
+ "",
16
+ "tag short",
17
+ "tag long",
18
+ "commit short",
19
+ "commit long"
20
+ ].freeze
21
+
22
+ def run_code_with_options(message)
23
+ say_with_colour message, :green
24
+
25
+ RUN_OPTIONS.each do |options|
26
+ say_with_colour "Running with options: '#{options}'", :blue
27
+ tag = Jekyll::VersionPlugin::Tag.new(nil, options, nil)
28
+ say_with_colour tag.render(nil), :yellow
29
+ end
30
+ end
31
+
32
+ COLOUR_MAP = {
33
+ red: 31,
34
+ green: 32,
35
+ yellow: 33,
36
+ blue: 34
37
+ }.freeze
38
+
39
+ def say_with_colour(text, colour_name)
40
+ colour_code = COLOUR_MAP.fetch(colour_name)
41
+ puts "\e[#{colour_code}m#{text}\e[0m"
42
+ end
43
+
44
+ def run_commands(message)
45
+ say_with_colour message, :red
46
+ yield
47
+ end
48
+
49
+ def main
50
+ Dir.mktmpdir("jekyll_version_plugin_test") do |dir|
51
+ say_with_colour "Created temp dir: #{dir}", :red
52
+ Dir.chdir(dir) do
53
+ run_code_with_options ">> Without git repo"
54
+
55
+ run_commands("** Creating git repo") { `git init .` }
56
+
57
+ run_code_with_options ">> With git repo"
58
+
59
+ run_commands("** Adding file") do
60
+ File.open("test-file.txt", "w") do |f|
61
+ f.write("this is some text\n")
62
+ end
63
+ `git add -A`
64
+ `git commit -m"first commit"`
65
+ end
66
+
67
+ run_code_with_options ">> With a commit"
68
+
69
+ run_commands("** Creating tag") { `git tag -a v1 -m"first tag"` }
70
+
71
+ run_code_with_options ">> With tag"
72
+
73
+ run_commands("** Updating file") do
74
+ File.open("test-file.txt", "w") do |f|
75
+ f.write("this is some more text\n")
76
+ end
77
+ `git add -A`
78
+ `git commit -m"another commit"`
79
+ end
80
+
81
+ run_code_with_options ">> With a commit after the tag"
82
+
83
+ run_commands("** Creating tag again") { `git tag -a v2 -m"second tag"` }
84
+
85
+ run_code_with_options ">> With a commit after the tag"
86
+ end
87
+ end
88
+ end
89
+
90
+ if __FILE__ == $PROGRAM_NAME
91
+ say_with_colour "Running integration tests...", :red
92
+ main
93
+ end
@@ -0,0 +1,214 @@
1
+ # frozen_string_literal: true
2
+ RSpec.describe Jekyll::VersionPlugin::Tag do
3
+ GIT_LAST_COMMIT_COMMAND = "git rev-parse --short HEAD"
4
+
5
+ GIT_DEFAULT_COMMAND = "git describe --tags --always"
6
+
7
+ GIT_TAG_LONG_COMMAND = "git describe --tags --always --long"
8
+ GIT_TAG_SHORT_COMMAND = "git describe --tags --always"
9
+ GIT_COMMIT_LONG_COMMAND = "git rev-parse HEAD"
10
+ GIT_COMMIT_SHORT_COMMAND = "git rev-parse --short HEAD"
11
+ let(:context) { double.as_null_object }
12
+
13
+ subject { described_class.new(nil, options, nil) }
14
+ let(:system_double) { double }
15
+ let(:options) { "" }
16
+
17
+ before do
18
+ subject.system_wrapper = system_double
19
+ end
20
+
21
+ describe "Parsing options" do
22
+ before do
23
+ with_git_repo
24
+ end
25
+
26
+ context "with no options" do
27
+ let(:options) { "" }
28
+
29
+ it "use default command" do
30
+ allow_call_to_succeed do
31
+ expect(system_double).to receive(:run).with(GIT_DEFAULT_COMMAND).and_return("hash")
32
+ end
33
+
34
+ subject.render(context)
35
+ end
36
+ end
37
+
38
+ context "with tag type" do
39
+ context "with no format" do
40
+ let(:options) { "tag" }
41
+
42
+ it "use default command" do
43
+ allow_call_to_succeed do
44
+ expect(system_double).to receive(:run).with(GIT_DEFAULT_COMMAND).and_return("hash")
45
+ end
46
+
47
+ subject.render(context)
48
+ end
49
+ end
50
+
51
+ context "with long format" do
52
+ let(:options) { "tag long" }
53
+
54
+ it "use correct command" do
55
+ allow_call_to_succeed do
56
+ expect(system_double).to receive(:run).with(GIT_TAG_LONG_COMMAND).and_return("hash")
57
+ end
58
+
59
+ subject.render(context)
60
+ end
61
+ end
62
+
63
+ context "with short format" do
64
+ let(:options) { "tag short" }
65
+
66
+ it "use correct command" do
67
+ allow_call_to_succeed do
68
+ expect(system_double).to receive(:run).with(GIT_TAG_SHORT_COMMAND).and_return("hash")
69
+ end
70
+
71
+ subject.render(context)
72
+ end
73
+ end
74
+
75
+ context "with no tag" do
76
+ let(:options) { "tag short" }
77
+
78
+ it "falls back to head command" do
79
+ do_not_allow_call_to_succeed do
80
+ allow(system_double).to receive(:run).with(GIT_TAG_SHORT_COMMAND)
81
+ end
82
+
83
+ allow_call_to_succeed do
84
+ allow(system_double).to receive(:run).with(GIT_COMMIT_SHORT_COMMAND).and_return("hash")
85
+ end
86
+
87
+ subject.render(context)
88
+ end
89
+ end
90
+ end
91
+
92
+ context "with commit type" do
93
+ context "with no format" do
94
+ let(:options) { "commit" }
95
+
96
+ it "use default command" do
97
+ allow_call_to_succeed do
98
+ expect(system_double).to receive(:run).with(GIT_COMMIT_SHORT_COMMAND).and_return("hash")
99
+ end
100
+
101
+ subject.render(context)
102
+ end
103
+ end
104
+
105
+ context "with long format" do
106
+ let(:options) { "commit short" }
107
+
108
+ it "use correct command" do
109
+ allow_call_to_succeed do
110
+ expect(system_double).to receive(:run).with(GIT_COMMIT_SHORT_COMMAND).and_return("hash")
111
+ end
112
+
113
+ subject.render(context)
114
+ end
115
+ end
116
+
117
+ context "with short format" do
118
+ let(:options) { "commit long" }
119
+
120
+ it "use correct command" do
121
+ allow_call_to_succeed do
122
+ expect(system_double).to receive(:run).with(GIT_COMMIT_LONG_COMMAND).and_return("hash")
123
+ end
124
+
125
+ subject.render(context)
126
+ end
127
+ end
128
+ end
129
+ end
130
+
131
+ describe "return message" do
132
+ context "no git repository" do
133
+ before do
134
+ allow(system_double).to receive(:git_repo?).and_return(false)
135
+ end
136
+
137
+ it "returns an error message" do
138
+ expect(subject.render(context)).to match(/Oops/)
139
+ end
140
+ end
141
+
142
+ context "a git repository with no commits" do
143
+ before do
144
+ with_git_repo
145
+ do_not_allow_call_to_succeed do
146
+ allow(system_double).to receive(:run).with(GIT_DEFAULT_COMMAND).and_return(false)
147
+ end
148
+
149
+ do_not_allow_call_to_succeed do
150
+ allow(system_double).to receive(:run).with(GIT_LAST_COMMIT_COMMAND).and_return(false)
151
+ end
152
+ end
153
+
154
+ it "returns an unable to read project message" do
155
+ expect(subject.render(context)).to match(/could not read the project version/)
156
+ end
157
+ end
158
+
159
+ context "with tag type" do
160
+ before do
161
+ with_git_repo
162
+ end
163
+ let(:options) { "tag" }
164
+
165
+ it "returns response" do
166
+ allow_call_to_succeed do
167
+ allow(system_double).to receive(:run).with(GIT_DEFAULT_COMMAND).and_return("tag-hash")
168
+ end
169
+
170
+ expect(subject.render(context)).to eq "tag-hash"
171
+ end
172
+ end
173
+
174
+ context "with commit type" do
175
+ before do
176
+ with_git_repo
177
+ end
178
+ let(:options) { "commit" }
179
+
180
+ it "returns response" do
181
+ allow_call_to_succeed do
182
+ allow(system_double).to receive(:run).with(GIT_COMMIT_SHORT_COMMAND).and_return("commit-hash")
183
+ end
184
+
185
+ expect(subject.render(context)).to eq "commit-hash"
186
+ end
187
+ end
188
+
189
+ it "removes line ending from parsed value" do
190
+ with_git_repo
191
+ allow_call_to_succeed do
192
+ allow(system_double).to receive(:run).with(GIT_DEFAULT_COMMAND).and_return("tag-hash\n")
193
+ end
194
+
195
+ expect(subject.render(context)).to eq "tag-hash"
196
+ end
197
+ end
198
+
199
+ private
200
+
201
+ def with_git_repo
202
+ allow(system_double).to receive(:git_repo?).and_return(true)
203
+ end
204
+
205
+ def allow_call_to_succeed
206
+ yield
207
+ allow(system_double).to receive(:command_succeeded?).and_return(true)
208
+ end
209
+
210
+ def do_not_allow_call_to_succeed
211
+ yield
212
+ allow(system_double).to receive(:command_succeeded?).and_return(false)
213
+ end
214
+ end
@@ -1,75 +1,22 @@
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 }
1
+ # frozen_string_literal: true
2
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
3
+ require "support/jekyll_template"
4
+ require "jekyll_version_plugin"
13
5
 
14
6
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
15
7
  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
8
  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
9
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
61
10
  end
62
11
 
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
12
  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
13
  mocks.verify_partial_doubles = true
74
14
  end
15
+ config.shared_context_metadata_behavior = :apply_to_host_groups
16
+ config.filter_run_when_matching :focus
17
+ config.disable_monkey_patching!
18
+ config.warnings = true
19
+ config.default_formatter = "doc" if config.files_to_run.one?
20
+ config.order = :random
21
+ Kernel.srand config.seed
75
22
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ # Hack ...or stub Liquid classes and methods used in plugin
3
+ module Liquid
4
+ class Tag
5
+ def initialize(*_); end
6
+ end
7
+
8
+ class Template
9
+ def self.register_tag(*_); end
10
+ end
11
+ end
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_version_plugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Murray
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-10 00:00:00.000000000 Z
11
+ date: 2016-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.6'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: '3.5'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
54
+ version: '3.5'
55
55
  description:
56
56
  email:
57
57
  - robmurray17@gmail.com
@@ -59,18 +59,19 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - ".gitignore"
63
- - ".rspec"
64
- - ".travis.yml"
62
+ - .gitignore
63
+ - .rspec
64
+ - .travis.yml
65
65
  - Gemfile
66
66
  - LICENSE
67
67
  - README.md
68
68
  - Rakefile
69
69
  - jekyll_version_plugin.gemspec
70
70
  - lib/jekyll_version_plugin.rb
71
- - lib/project_version_tag.rb
72
- - spec/project_version_tag_spec.rb
71
+ - spec/integration_test.rb
72
+ - spec/jekyll_version_plugin_tag_spec.rb
73
73
  - spec/spec_helper.rb
74
+ - spec/support/jekyll_template.rb
74
75
  homepage: https://github.com/rob-murray/jekyll-version-plugin
75
76
  licenses:
76
77
  - MIT
@@ -81,21 +82,23 @@ require_paths:
81
82
  - lib
82
83
  required_ruby_version: !ruby/object:Gem::Requirement
83
84
  requirements:
84
- - - ">="
85
+ - - '>='
85
86
  - !ruby/object:Gem::Version
86
- version: '0'
87
+ version: 1.9.3
87
88
  required_rubygems_version: !ruby/object:Gem::Requirement
88
89
  requirements:
89
- - - ">="
90
+ - - '>='
90
91
  - !ruby/object:Gem::Version
91
92
  version: '0'
92
93
  requirements: []
93
94
  rubyforge_project:
94
- rubygems_version: 2.4.6
95
+ rubygems_version: 2.0.14.1
95
96
  signing_key:
96
97
  specification_version: 4
97
98
  summary: A Liquid tag plugin for Jekyll that renders a version identifier for your
98
99
  Jekyll site, sourced from the git repository.
99
100
  test_files:
100
- - spec/project_version_tag_spec.rb
101
+ - spec/integration_test.rb
102
+ - spec/jekyll_version_plugin_tag_spec.rb
101
103
  - spec/spec_helper.rb
104
+ - spec/support/jekyll_template.rb
@@ -1,51 +0,0 @@
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 --always }
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)
@@ -1,65 +0,0 @@
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 --always ' }
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)
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)
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)
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