jekyll-github-metadata 2.8.0 → 2.9.1

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: 05f4959dbacc7ebac3d2b1cf7a4fb1519435a152
4
- data.tar.gz: 455bde265c66f2a7186c3044888732c71fac386e
3
+ metadata.gz: f30ae34c0ecef4f7a5ef2cb3669d9c1f9204ff17
4
+ data.tar.gz: 7f81b7ca161a562b966012f6aae369ef2957e88c
5
5
  SHA512:
6
- metadata.gz: 941b07182ad3d4173d0fdb54a43cfc2e045188d6ef93efa2a125a301e75c05df4c898de2c28103e06757546a0a8c25d1bd98022d4f325cbc4e0db178d45b78c6
7
- data.tar.gz: cff03608fe4bdbaafa1b6dc9b9eaaa00130a5541b72cd67e699dd9a2f5d83c0a35f54e1aeb05c1107ce5d4706ddd809fd1b784e8353c55107e47cd1e062017d1
6
+ metadata.gz: d898b20ea3034666929654dc6e1a437f29dbce86e5a18b14dc948024d60505c7a7b7c5dddaedd6bf91ae11b8c1f9fff2dc0e3a758e1f06998da6bd5c2c1d23f9
7
+ data.tar.gz: e1a149c71cb64d2369e61490409518e291cdbabae217271b5c7f706144303b81f6457d3b76ca9e133455cd4d77cb68d82ac853581722b811bc9051cd417a59c5
@@ -0,0 +1,102 @@
1
+ module Jekyll
2
+ module GitHubMetadata
3
+ class EditLinkTag < Liquid::Tag
4
+ attr_reader :context
5
+
6
+ # Defines an instance method that delegates to a hash's key
7
+ #
8
+ # hash_method - a symbol representing the instance method to delegate to. The
9
+ # instance method should return a hash or respond to #[]
10
+ # key - the key to call within the hash
11
+ # method - (optional) the instance method the key should be aliased to.
12
+ # If not specified, defaults to the hash key
13
+ # default - (optional) value to return if value is nil (defaults to nil)
14
+ #
15
+ # Returns a symbol representing the instance method
16
+ def self.def_hash_delegator(hash_method, key, method, default = nil)
17
+ define_method(method) do
18
+ hash = send(hash_method)
19
+ if hash.respond_to? :[]
20
+ hash[key.to_s] || default
21
+ else
22
+ default
23
+ end
24
+ end
25
+ end
26
+
27
+ MISSING_DATA_MSG = "Cannot generate edit URLs due to missing site.github data".freeze
28
+ LINK_TEXT_REGEX = %r!(?:\"(.*)\"|'(.*)')!
29
+
30
+ extend Forwardable
31
+ private def_hash_delegator :site, :github, :site_github, {}
32
+ private def_hash_delegator :site_github, :repository_url, :repository_url
33
+ private def_hash_delegator :site_github, :source, :source, {}
34
+ private def_hash_delegator :source, :branch, :branch
35
+ private def_hash_delegator :source, :path, :source_path
36
+ private def_hash_delegator :page, :path, :page_path
37
+
38
+ def render(context)
39
+ @context = context
40
+ if link_text
41
+ link
42
+ else
43
+ uri.to_s
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def link_text
50
+ @link_text ||= begin
51
+ matches = @markup.match LINK_TEXT_REGEX
52
+ matches[1] || matches[2] if matches
53
+ end
54
+ end
55
+
56
+ def link
57
+ "<a href=\"#{uri}\">#{link_text}</a>"
58
+ end
59
+
60
+ def uri
61
+ if parts.any?(&:nil?)
62
+ Jekyll.logger.warn "JekyllEditLink: ", MISSING_DATA_MSG
63
+ ""
64
+ else
65
+ Addressable::URI.join(*parts_normalized).normalize
66
+ end
67
+ end
68
+
69
+ def parts
70
+ @parts ||= [repository_url, "edit/", branch, source_path, page_path]
71
+ end
72
+
73
+ def parts_normalized
74
+ @parts_normalized ||= parts.map.with_index do |part, index|
75
+ part = remove_leading_slash(part.to_s)
76
+ part = ensure_trailing_slash(part) unless index == parts.length - 1
77
+ ensure_not_just_a_slash(part)
78
+ end
79
+ end
80
+
81
+ def page
82
+ @page ||= context.registers[:page]
83
+ end
84
+
85
+ def site
86
+ @site ||= context.registers[:site].site_payload["site"]
87
+ end
88
+
89
+ def remove_leading_slash(part)
90
+ part.start_with?("/") ? part[1..-1] : part
91
+ end
92
+
93
+ def ensure_trailing_slash(part)
94
+ part.end_with?("/") ? part : "#{part}/"
95
+ end
96
+
97
+ def ensure_not_just_a_slash(part)
98
+ part == "/" ? "" : part
99
+ end
100
+ end
101
+ end
102
+ end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module GitHubMetadata
3
- VERSION = "2.8.0".freeze
3
+ VERSION = "2.9.1".freeze
4
4
  end
5
5
  end
@@ -1,4 +1,5 @@
1
1
  require "octokit"
2
+ require "liquid"
2
3
  require "logger"
3
4
 
4
5
  if defined?(Jekyll) && Jekyll.respond_to?(:env) && Jekyll.env == "development"
@@ -19,6 +20,7 @@ module Jekyll
19
20
 
20
21
  module GitHubMetadata
21
22
  autoload :Client, "jekyll-github-metadata/client"
23
+ autoload :EditLinkTag, "jekyll-github-metadata/edit-link-tag"
22
24
  autoload :MetadataDrop, "jekyll-github-metadata/metadata_drop"
23
25
  autoload :Pages, "jekyll-github-metadata/pages"
24
26
  autoload :Repository, "jekyll-github-metadata/repository"
@@ -83,3 +85,5 @@ module Jekyll
83
85
  end
84
86
  end
85
87
  end
88
+
89
+ Liquid::Template.register_tag("github_edit_link", Jekyll::GitHubMetadata::EditLinkTag)
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: 2.8.0
4
+ version: 2.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Parker Moore
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-15 00:00:00.000000000 Z
11
+ date: 2017-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -123,6 +123,7 @@ extra_rdoc_files: []
123
123
  files:
124
124
  - lib/jekyll-github-metadata.rb
125
125
  - lib/jekyll-github-metadata/client.rb
126
+ - lib/jekyll-github-metadata/edit-link-tag.rb
126
127
  - lib/jekyll-github-metadata/metadata_drop.rb
127
128
  - lib/jekyll-github-metadata/pages.rb
128
129
  - lib/jekyll-github-metadata/repository.rb