jekyll-git_metadata 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 84e075d40c99adec303ec67563ac8c95c9d14027
4
+ data.tar.gz: 33c02709deea74dd3f1c36d16b2a9d45974d8146
5
+ SHA512:
6
+ metadata.gz: cc811eeb6b0f2a1349df70eba61715ed429f5761fd2bfcb39c75c4deb3beebf28c7c074db8de9fbc4dfc78d558f30ce22d24bfe244594f1ba43d2c9d24208ae6
7
+ data.tar.gz: 89fdf17ad935f296fc5f699ceec19018419c9332427f69daeec608dd5c0ab16383fe7d86174a42cb0074d451f5452c1002de13c6f3cbba46c5e5761c07ac4440
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jekyll-git_metadata.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ivan Tse
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Jekyll::GitMetadata
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'jekyll-git_metadata'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install jekyll-git_metadata
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/ivantsepp/jekyll-git_metadata/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jekyll/git_metadata/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jekyll-git_metadata"
8
+ spec.version = Jekyll::GitMetadata::VERSION
9
+ spec.authors = ["Ivan Tse"]
10
+ spec.email = ["ivan.tse1@gmail.com"]
11
+ spec.summary = %q{Expose Git metadata to Jekyll.}
12
+ spec.description = %q{Get access to Git information in your Jekyll templates}
13
+ spec.homepage = "https://github.com/ivantsepp/jekyll-git_metadata"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "jekyll", '~> 2.0'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1 @@
1
+ require 'jekyll/git_metadata'
@@ -0,0 +1,8 @@
1
+ require 'jekyll/git_metadata/version'
2
+ require 'jekyll/git_metadata/generator'
3
+
4
+ module Jekyll
5
+ module GitMetadata
6
+
7
+ end
8
+ end
@@ -0,0 +1,105 @@
1
+ require 'rbconfig'
2
+
3
+ module Jekyll
4
+ module GitMetadata
5
+ class Generator < Jekyll::Generator
6
+
7
+ safe true
8
+
9
+ def generate(site)
10
+ raise "Git is not installed" unless git_installed?
11
+
12
+ Dir.chdir(site.source) do
13
+ site.config['git'] = site_data
14
+ site.pages.each do |page|
15
+ page.data['git'] = page_data(page.relative_path)
16
+ end
17
+ site.posts.each do |page|
18
+ page.data['git'] = page_data(page.relative_path)
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ def site_data
25
+ authors = self.authors
26
+ lines = self.lines
27
+ {
28
+ 'project_name' => project_name,
29
+ 'files_count' => files_count,
30
+ 'authors' => authors,
31
+ 'total_commits' => authors.inject(0) { |sum, h| sum += h['commits'] },
32
+ 'total_additions' => lines.inject(0) { |sum, h| sum += h['additions'] },
33
+ 'total_subtractions' => lines.inject(0) { |sum, h| sum += h['subtractions'] },
34
+ 'first_commit' => commit(lines.last['sha']),
35
+ 'last_commit' => commit(lines.first['sha'])
36
+ }
37
+ end
38
+
39
+ def page_data(relative_path)
40
+ authors = self.authors(relative_path)
41
+ lines = self.lines(relative_path)
42
+ {
43
+ 'authors' => authors,
44
+ 'total_commits' => authors.inject(0) { |sum, h| sum += h['commits'] },
45
+ 'total_additions' => lines.inject(0) { |sum, h| sum += h['additions'] },
46
+ 'total_subtractions' => lines.inject(0) { |sum, h| sum += h['subtractions'] },
47
+ 'first_commit' => commit(lines.last['sha']),
48
+ 'last_commit' => commit(lines.first['sha'])
49
+ }
50
+ end
51
+
52
+ def authors(file = nil)
53
+ results = []
54
+ cmd = 'git shortlog -se'
55
+ cmd << " -- #{file}" if file
56
+ result = %x{#{cmd}}
57
+ result.lines.each do |line|
58
+ commits, name, email = line.scan(/(.*)\t(.*)<(.*)>/).first.map(&:strip)
59
+ results << { 'commits' => commits.to_i, 'name' => name, 'email' => email }
60
+ end
61
+ results
62
+ end
63
+
64
+ def lines(file = nil)
65
+ cmd = "git log --numstat --format='%h'"
66
+ cmd << " -- #{file}" if file
67
+ result = %x{#{cmd}}
68
+ results = result.scan(/(.*)\n\n(.*)\t(.*)\t(.*)\n/)
69
+ results.map { |a| a[1] = a[1].to_i; a[2] = a[2].to_i }
70
+ results.map do |line|
71
+ { 'sha' => line[0], 'additions' => line[1], 'subtractions' => line[2], 'file' => line[3] }
72
+ end
73
+ end
74
+
75
+ def commit(sha)
76
+ result = %x{git show --format=fuller -q #{sha}}
77
+ author_name, author_email, author_date, commit_name, commit_email, commit_date, message = result
78
+ .scan(/.*Author:(.*)<(.*)>\nAuthorDate:(.*)\nCommit:(.*)<(.*)>\nCommitDate:(.*)\n\n(.*)/)
79
+ .first
80
+ .map(&:strip)
81
+ {
82
+ 'author_name' => author_name,
83
+ 'author_email' => author_email,
84
+ 'author_date' => author_date,
85
+ 'commit_name' => commit_name,
86
+ 'commit_date' => commit_date,
87
+ 'message' => message
88
+ }
89
+ end
90
+
91
+ def project_name
92
+ File.basename(%x{git rev-parse --show-toplevel}.strip)
93
+ end
94
+
95
+ def files_count
96
+ %x{ git ls-tree -r HEAD | wc -l }.strip.to_i
97
+ end
98
+
99
+ def git_installed?
100
+ void = RbConfig::CONFIG['host_os'] =~ /msdos|mswin|djgpp|mingw/ ? 'NUL' : '/dev/null'
101
+ system "git --version >>#{void} 2>&1"
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,5 @@
1
+ module Jekyll
2
+ module GitMetadata
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-git_metadata
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ivan Tse
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Get access to Git information in your Jekyll templates
56
+ email:
57
+ - ivan.tse1@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - jekyll-git_metadata.gemspec
68
+ - lib/jekyll-git_metadata.rb
69
+ - lib/jekyll/git_metadata.rb
70
+ - lib/jekyll/git_metadata/generator.rb
71
+ - lib/jekyll/git_metadata/version.rb
72
+ homepage: https://github.com/ivantsepp/jekyll-git_metadata
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Expose Git metadata to Jekyll.
96
+ test_files: []