jekyll-github-metadata 1.1.0 → 1.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 53e700215c67954ca3037fddd6766fcd6e6c86f7
4
- data.tar.gz: 5041bdbf06942910b6520d46176edae8c97a5184
3
+ metadata.gz: 552e948d80c87cc232d4e5174c01b67865d39d80
4
+ data.tar.gz: f0616b53308ff040e37ae03579447188d960070b
5
5
  SHA512:
6
- metadata.gz: b10f6f1f148b3792ba1806c58c28a20bdf99e1621acfc8650c9e543d2b361f4f0ff1fe65385c3130b97aa13690738bd0e348bf7595f382dbdb9b45f29f7befee
7
- data.tar.gz: 2fb3576ef8e5713f77f2821443faf3182d2a77a288501d8cf672cdef0a9bca9b315522cf05c9f36462b1406b80348fb83fe2d02e317d46557c219464deb2fdb0
6
+ metadata.gz: a7121114126260d7ab0863786f2f2f4700cb81017f7225b40ee36dadddbb4654d49e2bf1db75cd5f14e1447624554cbe8b5f79e11a9adf6c923f07dcc604db9e
7
+ data.tar.gz: 5a94679c3e92759b9929f0c3f44e15745f2e8eefa9e3268d24b3e5bc5274473760823d7f8ca2b4d6d9978aecffbeae26a14cd7c2b2404d1ea5f9266429ffd515
@@ -1,7 +1,10 @@
1
+ require 'jekyll'
1
2
  require 'octokit'
2
3
 
3
4
  module Jekyll
4
5
  module GitHubMetadata
6
+ NoRepositoryError = Class.new(Jekyll::Errors::FatalException)
7
+
5
8
  autoload :Client, 'jekyll-github-metadata/client'
6
9
  autoload :Pages, 'jekyll-github-metadata/pages'
7
10
  autoload :Repository, 'jekyll-github-metadata/repository'
@@ -28,6 +31,11 @@ module Jekyll
28
31
  @values = Hash.new
29
32
  end
30
33
 
34
+ def reset!
35
+ clear_values!
36
+ @client = nil
37
+ end
38
+
31
39
  def [](key)
32
40
  values[key.to_s]
33
41
  end
@@ -43,46 +51,59 @@ module Jekyll
43
51
  def register_value(key, value)
44
52
  values[key.to_s] = Value.new(key.to_s, value)
45
53
  end
54
+
55
+ # Reset our values hash.
56
+ def init!
57
+ reset!
58
+
59
+ # Environment-Specific
60
+ register_value('environment', proc { environment })
61
+ register_value('hostname', proc { Pages.github_hostname })
62
+ register_value('pages_env', proc { Pages.env })
63
+ register_value('pages_hostname', proc { Pages.pages_hostname })
64
+ register_value('api_url', proc { Pages.api_url })
65
+ register_value('help_url', proc { Pages.help_url })
66
+
67
+ register_value('versions', proc {
68
+ begin
69
+ require 'github-pages'
70
+ GitHubPages.versions
71
+ rescue LoadError; Hash.new end
72
+ })
73
+
74
+ # The Juicy Stuff
75
+ register_value('public_repositories', proc { |c,r| c.list_repos(r.owner, "type" => "public") })
76
+ register_value('organization_members', proc { |c,r|
77
+ c.organization_public_members(r.owner) if r.organization_repository?
78
+ })
79
+ register_value('build_revision', proc {
80
+ ENV['JEKYLL_BUILD_REVISION'] || `git rev-parse HEAD`.strip
81
+ })
82
+ register_value('project_title', proc { |_,r| r.name })
83
+ register_value('project_tagline', proc { |_,r| r.tagline })
84
+ register_value('owner_name', proc { |_,r| r.owner })
85
+ register_value('owner_url', proc { |_,r| r.owner_url })
86
+ register_value('owner_gravatar_url', proc { |_,r| r.owner_gravatar_url })
87
+ register_value('repository_url', proc { |_,r| r.repository_url })
88
+ register_value('repository_nwo', proc { |_,r| r.nwo })
89
+ register_value('repository_name', proc { |_,r| r.name})
90
+ register_value('zip_url', proc { |_,r| r.zip_url })
91
+ register_value('tar_url', proc { |_,r| r.tar_url })
92
+ register_value('clone_url', proc { |_,r| r.repo_clone_url })
93
+ register_value('releases_url', proc { |_,r| r.releases_url })
94
+ register_value('issues_url', proc { |_,r| r.issues_url })
95
+ register_value('wiki_url', proc { |_,r| r.wiki_url })
96
+ register_value('language', proc { |_,r| r.language })
97
+ register_value('is_user_page', proc { |_,r| r.user_page? })
98
+ register_value('is_project_page', proc { |_,r| r.project_page? })
99
+ register_value('show_downloads', proc { |_,r| r.show_downloads? })
100
+ register_value('url', proc { |_,r| r.pages_url })
101
+ register_value('contributors', proc { |c,r| c.contributors(r.nwo) })
102
+ register_value('releases', proc { |c,r| c.releases(r.nwo) })
103
+ end
46
104
  end
47
105
 
48
- # Environment-Specific
49
- register_value('environment', proc { environment })
50
- register_value('hostname', proc { Pages.github_hostname })
51
- register_value('pages_hostname', proc { Pages.pages_hostname })
52
- register_value('api_url', proc { Pages.api_url })
53
-
54
- register_value('versions', proc {
55
- begin
56
- require 'github-pages'
57
- GitHubPages.versions
58
- rescue LoadError; Hash.new end
59
- })
60
-
61
- # The Juicy Stuff
62
- register_value('public_repositories', proc { |c,r| c.list_repos(r.owner, "type" => "public") })
63
- register_value('organization_members', proc { |c,r| c.organization_public_members(r.owner) if r.organization_repository? })
64
- register_value('build_revision', proc { `git rev-parse HEAD`.strip })
65
- register_value('project_title', proc { |_,r| r.name })
66
- register_value('project_tagline', proc { |_,r| r.tagline })
67
- register_value('owner_name', proc { |_,r| r.owner })
68
- register_value('owner_url', proc { |_,r| r.owner_url })
69
- register_value('owner_gravatar_url', proc { |_,r| r.owner_gravatar_url })
70
- register_value('repository_url', proc { |_,r| r.repository_url })
71
- register_value('repository_nwo', proc { |_,r| r.nwo })
72
- register_value('repository_name', proc { |_,r| r.name})
73
- register_value('zip_url', proc { |_,r| r.zip_url })
74
- register_value('tar_url', proc { |_,r| r.tar_url })
75
- register_value('clone_url', proc { |_,r| r.repo_clone_url })
76
- register_value('releases_url', proc { |_,r| r.releases_url })
77
- register_value('issues_url', proc { |_,r| r.issues_url })
78
- register_value('wiki_url', proc { |_,r| r.wiki_url })
79
- register_value('language', proc { |_,r| r.language })
80
- register_value('is_user_page', proc { |_,r| r.user_page? })
81
- register_value('is_project_page', proc { |_,r| r.project_page? })
82
- register_value('show_downloads', proc { |_,r| r.show_downloads? })
83
- register_value('url', proc { |_,r| r.pages_url })
84
- register_value('contributors', proc { |c,r| c.contributors(r.nwo) })
85
- register_value('releases', proc { |c,r| c.releases(r.nwo) })
106
+ init!
86
107
  end
87
108
  end
88
109
 
@@ -16,7 +16,7 @@ module Jekyll
16
16
  options = options || Hash.new
17
17
  if ENV['JEKYLL_GITHUB_TOKEN'] || Octokit.access_token
18
18
  options.merge!(:access_token => ENV['JEKYLL_GITHUB_TOKEN'] || Octokit.access_token)
19
- elsif File.exist?(File.join(ENV['HOME'], '.netrc')) && safe_require('netrc')
19
+ elsif !ENV['NO_NETRC'] && File.exist?(File.join(ENV['HOME'], '.netrc')) && safe_require('netrc')
20
20
  options.merge!(:netrc => true)
21
21
  else
22
22
  Jekyll.logger.warn "GitHubMetadata:", "No GitHub API authentication could be found." +
@@ -4,7 +4,9 @@ module Jekyll
4
4
  module GitHubMetadata
5
5
  class GHPMetadataGenerator < Jekyll::Generator
6
6
  def generate(site)
7
- GitHubMetadata.repository = GitHubMetadata::Repository.new(site.config.fetch('repository'))
7
+ Jekyll.logger.debug "Generator:", "Calling GHPMetadataGenerator"
8
+ GitHubMetadata.repository = GitHubMetadata::Repository.new(nwo(site))
9
+ GitHubMetadata.init!
8
10
  site.config['github'] =
9
11
  case site.config['github']
10
12
  when nil
@@ -15,6 +17,15 @@ module Jekyll
15
17
  site.config['github']
16
18
  end
17
19
  end
20
+
21
+ def nwo(site)
22
+ ENV['PAGES_REPO_NWO'] || \
23
+ site.config['repository'] || \
24
+ proc {
25
+ raise GitHubMetadata::NoRepositoryError, "No repo name found. "
26
+ "Specify using PAGES_REPO_NWO or 'repository' in your configuration."
27
+ }.call
28
+ end
18
29
  end
19
30
  end
20
31
  end
@@ -2,23 +2,48 @@ module Jekyll
2
2
  module GitHubMetadata
3
3
  class Pages
4
4
  class << self
5
+ DEFAULTS = {
6
+ 'PAGES_ENV' => 'dotcom'.freeze,
7
+ 'PAGES_API_URL' => 'https://api.github.com'.freeze,
8
+ 'PAGES_HELP_URL' => 'https://help.github.com'.freeze,
9
+ 'PAGES_GITHUB_HOSTNAME' => 'https://github.com'.freeze,
10
+ 'PAGES_PAGES_HOSTNAME' => 'github.io'.freeze,
11
+ 'SSL' => 'false'.freeze
12
+ }.freeze
13
+
14
+ def ssl?
15
+ env_var('SSL').eql? 'true'
16
+ end
17
+
18
+ def scheme
19
+ ssl? ? "https" : "http"
20
+ end
21
+
5
22
  def env
6
- ENV.fetch('PAGES_ENV', 'dotcom')
23
+ env_var 'PAGES_ENV'
7
24
  end
8
25
 
9
26
  def api_url
10
- trim_last_slash(ENV['PAGES_API_URL'] || Octokit.api_endpoint || 'https://api.github.com')
27
+ trim_last_slash env_var('PAGES_API_URL', Octokit.api_endpoint)
28
+ end
29
+
30
+ def help_url
31
+ trim_last_slash env_var('PAGES_HELP_URL')
11
32
  end
12
33
 
13
34
  def github_hostname
14
- trim_last_slash(ENV['PAGES_GITHUB_HOSTNAME'] || Octokit.web_endpoint || 'https://github.com')
35
+ trim_last_slash env_var('PAGES_GITHUB_HOSTNAME', Octokit.web_endpoint)
15
36
  end
16
37
 
17
38
  def pages_hostname
18
- trim_last_slash(ENV.fetch('PAGES_PAGES_HOSTNAME', 'github.io'))
39
+ trim_last_slash env_var('PAGES_PAGES_HOSTNAME')
19
40
  end
20
41
 
21
42
  private
43
+ def env_var(key, intermediate_default = nil)
44
+ !ENV[key].to_s.empty? ? ENV[key] : (intermediate_default || DEFAULTS[key])
45
+ end
46
+
22
47
  def trim_last_slash(url)
23
48
  if url[-1] == "/"
24
49
  url[0..-2]
@@ -101,9 +101,9 @@ module Jekyll
101
101
 
102
102
  def pages_url
103
103
  if cname || primary?
104
- "http://#{domain}"
104
+ "#{Pages.scheme}://#{domain}"
105
105
  else
106
- File.join("http://#{domain}", name, "")
106
+ URI.join("#{Pages.scheme}://#{domain}", "#{name}/")
107
107
  end
108
108
  end
109
109
 
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module GitHubMetadata
3
- VERSION = '1.1.0'
3
+ VERSION = '1.2.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: 1.1.0
4
+ version: 1.2.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: 2015-09-08 00:00:00.000000000 Z
11
+ date: 2016-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  version: '0'
130
130
  requirements: []
131
131
  rubyforge_project:
132
- rubygems_version: 2.2.3
132
+ rubygems_version: 2.5.1
133
133
  signing_key:
134
134
  specification_version: 4
135
135
  summary: The site.github namespace