jekyll-github-metadata 0.1.0 → 1.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: 7118e76a45b88b13ed74056081b4f8c770afe7eb
4
- data.tar.gz: 4c68fc503a1c8d070ec518af2c3cece4d21bd642
3
+ metadata.gz: f60e53e846b6f161a8da39e7ef1ac9ec787e3826
4
+ data.tar.gz: 4ff42a6cbabcc431ea0743ca537d2f31544152c2
5
5
  SHA512:
6
- metadata.gz: 1f392cde09024155ffd90de399a77ff4a58b9ce9d631b25c07c42c0dad43efa649b620a2285eadc92f956a49a35a4d0efbaf34317568d321000e50e26d85a71d
7
- data.tar.gz: 3347b15c29ebea89267d5388ae89b4b1be87a87b7f61e7686b69841a384389dea2df1818daaebc404508c5ca2696b49b7a9d091bb0bcf024401c03f43260ef4f
6
+ metadata.gz: 18cbe8b1812895dc605ffe583cac531c6d8814f1b68aca33908d36da605587d99801f0f874f0c0578f3a5c169098ac97c530b55b3af7527a3397663282a1db8a
7
+ data.tar.gz: 5952a5f8f42f1e6a144426834d078d10a0a6cd53632fe2e95012d52fa3502f3a8dc7e7b24bc604b62e75f6376ca6330c97904111482fd3e04d210449e0f88735
@@ -1,3 +1,5 @@
1
+ require 'octokit'
2
+
1
3
  module Jekyll
2
4
  module GitHubMetadata
3
5
  autoload :Client, 'jekyll-github-metadata/client'
@@ -39,13 +41,13 @@ module Jekyll
39
41
  end
40
42
 
41
43
  def register_value(key, value)
42
- values[key.to_s] = Value.new(value)
44
+ values[key.to_s] = Value.new(key.to_s, value)
43
45
  end
44
46
  end
45
47
 
46
48
  # Environment-Specific
47
49
  register_value('environment', proc { environment })
48
- register_value('hostname', proc { Pages.github_url })
50
+ register_value('hostname', proc { Pages.github_hostname })
49
51
  register_value('pages_hostname', proc { Pages.pages_hostname })
50
52
  register_value('api_url', proc { Pages.api_url })
51
53
 
@@ -58,7 +60,7 @@ module Jekyll
58
60
 
59
61
  # The Juicy Stuff
60
62
  register_value('public_repositories', proc { |c,r| c.list_repos(r.owner, "type" => "public") })
61
- register_value('organization_members', proc { |c,r| c.organization_public_members(owner) if r.organization_repository? })
63
+ register_value('organization_members', proc { |c,r| c.organization_public_members(r.owner) if r.organization_repository? })
62
64
  register_value('build_revision', proc { `git rev-parse HEAD`.strip })
63
65
  register_value('project_title', proc { |_,r| r.name })
64
66
  register_value('project_tagline', proc { |_,r| r.tagline })
@@ -80,6 +82,7 @@ module Jekyll
80
82
  register_value('show_downloads', proc { |_,r| r.show_downloads? })
81
83
  register_value('url', proc { |_,r| r.pages_url })
82
84
  register_value('contributors', proc { |c,r| c.contributors(r.nwo) })
85
+ register_value('releases', proc { |c,r| c.releases(r.nwo) })
83
86
  end
84
87
  end
85
88
 
@@ -2,7 +2,6 @@ module Jekyll
2
2
  module GitHubMetadata
3
3
  class Client
4
4
  def initialize(options = nil)
5
- require 'octokit'
6
5
  @client = build_octokit_client(options)
7
6
  end
8
7
 
@@ -15,8 +14,8 @@ module Jekyll
15
14
 
16
15
  def build_octokit_client(options = nil)
17
16
  options = options || Hash.new
18
- if ENV['JEKYLL_GITHUB_TOKEN']
19
- options.merge!(:access_token => ENV['JEKYLL_GITHUB_TOKEN'])
17
+ if ENV['JEKYLL_GITHUB_TOKEN'] || Octokit.access_token
18
+ options.merge!(:access_token => ENV['JEKYLL_GITHUB_TOKEN'] || Octokit.access_token)
20
19
  elsif File.exist?(File.join(ENV['HOME'], '.netrc')) && safe_require('netrc')
21
20
  options.merge!(:netrc => true)
22
21
  else
@@ -5,8 +5,16 @@ module Jekyll
5
5
  class GHPMetadataGenerator < Jekyll::Generator
6
6
  def generate(site)
7
7
  GitHubMetadata.repository = GitHubMetadata::Repository.new(site.config.fetch('repository'))
8
- site.config['github'] = GitHubMetadata.to_liquid
8
+ site.config['github'] =
9
+ case site.config['github']
10
+ when nil
11
+ GitHubMetadata.to_liquid
12
+ when Hash
13
+ Jekyll::Utils.deep_merge_hashes(GitHubMetadata.to_liquid, site.config['github'])
14
+ else
15
+ site.config['github']
16
+ end
9
17
  end
10
18
  end
11
19
  end
12
- end
20
+ end
@@ -7,15 +7,24 @@ module Jekyll
7
7
  end
8
8
 
9
9
  def api_url
10
- 'https://api.github.com'
10
+ trim_last_slash(ENV['PAGES_API_URL'] || Octokit.api_endpoint || 'https://api.github.com')
11
11
  end
12
12
 
13
- def github_url
14
- 'github.com'
13
+ def github_hostname
14
+ trim_last_slash(ENV['PAGES_GITHUB_HOSTNAME'] || Octokit.web_endpoint || 'https://github.com')
15
15
  end
16
16
 
17
17
  def pages_hostname
18
- 'github.io'
18
+ trim_last_slash(ENV.fetch('PAGES_PAGES_HOSTNAME', 'github.io'))
19
+ end
20
+
21
+ private
22
+ def trim_last_slash(url)
23
+ if url[-1] == "/"
24
+ url[0..-2]
25
+ else
26
+ url
27
+ end
19
28
  end
20
29
  end
21
30
  end
@@ -17,7 +17,7 @@ module Jekyll
17
17
  end
18
18
 
19
19
  def repo_info
20
- @repo_into ||= (Value.new(proc { |c| c.repository(nwo) }).render || Hash.new)
20
+ @repo_info ||= (Value.new(proc { |c| c.repository(nwo) }).render || Hash.new)
21
21
  end
22
22
 
23
23
  def language
@@ -29,7 +29,7 @@ module Jekyll
29
29
  end
30
30
 
31
31
  def owner_url
32
- "#{Pages.github_url}/#{owner}"
32
+ "#{Pages.github_hostname}/#{owner}"
33
33
  end
34
34
 
35
35
  def owner_gravatar_url
@@ -41,7 +41,7 @@ module Jekyll
41
41
  end
42
42
 
43
43
  def repository_url
44
- "#{Pages.github_url}/#{nwo}"
44
+ "#{Pages.github_hostname}/#{nwo}"
45
45
  end
46
46
 
47
47
  def zip_url
@@ -103,12 +103,12 @@ module Jekyll
103
103
  if cname || primary?
104
104
  "http://#{domain}"
105
105
  else
106
- File.join("http://#{domain}", name)
106
+ File.join("http://#{domain}", name, "")
107
107
  end
108
108
  end
109
109
 
110
110
  def cname
111
- @cname ||= (Value.new(proc { |c| c.pages(nwo) }).render || {'cname' => nil})['cname']
111
+ @cname ||= (Value.new('cname', proc { |c| c.pages(nwo) }).render || {'cname' => nil})['cname']
112
112
  end
113
113
 
114
114
  def domain
@@ -3,10 +3,19 @@ require 'json'
3
3
  module Jekyll
4
4
  module GitHubMetadata
5
5
  class Value
6
- attr_reader :value
6
+ attr_reader :key, :value
7
7
 
8
- def initialize(value)
9
- @value = value
8
+ def initialize(*args)
9
+ case args.size
10
+ when 1
11
+ @key = '{anonymous}'
12
+ @value = args.first
13
+ when 2
14
+ @key = args.first.to_s
15
+ @value = args.last
16
+ else
17
+ raise ArgumentError.new("#{args.size} args given but expected 1 or 2")
18
+ end
10
19
  end
11
20
 
12
21
  def render
@@ -25,6 +34,9 @@ module Jekyll
25
34
  @value
26
35
  end
27
36
  @value = Sanitizer.sanitize(@value)
37
+ rescue RuntimeError, NameError => e
38
+ Jekyll.logger.error "GitHubMetadata:", "Error processing value '#{key}':"
39
+ raise e
28
40
  end
29
41
 
30
42
  def to_s
@@ -37,8 +49,14 @@ module Jekyll
37
49
 
38
50
  def to_liquid
39
51
  case render
52
+ when nil
53
+ nil
54
+ when true, false
55
+ value
56
+ when Hash
57
+ value
40
58
  when String, Numeric, Array
41
- render
59
+ value
42
60
  else
43
61
  to_json
44
62
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module GitHubMetadata
3
- VERSION = '0.1.0'
3
+ VERSION = '1.0.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-github-metadata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Parker Moore
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-20 00:00:00.000000000 Z
11
+ date: 2015-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.3'
19
+ version: '4.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.3'
26
+ version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: netrc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -70,14 +84,14 @@ dependencies:
70
84
  name: jekyll
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - "~>"
87
+ - - ">="
74
88
  - !ruby/object:Gem::Version
75
89
  version: '2.0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - "~>"
94
+ - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '2.0'
83
97
  description:
@@ -115,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
129
  version: '0'
116
130
  requirements: []
117
131
  rubyforge_project:
118
- rubygems_version: 2.2.2
132
+ rubygems_version: 2.2.3
119
133
  signing_key:
120
134
  specification_version: 4
121
135
  summary: The site.github namespace