class Jekyll::GitHubMetadata::EditLinkTag
Constants
- LINK_TEXT_REGEX
- MISSING_DATA_MSG
Attributes
context[R]
Public Class Methods
def_hash_delegator(hash_method, key, method, default = nil)
click to toggle source
Defines an instance method that delegates to a hash’s key
hash_method - a symbol representing the instance method to delegate to. The
instance method should return a hash or respond to #[]
key - the key to call within the hash method - (optional) the instance method the key should be aliased to.
If not specified, defaults to the hash key
default - (optional) value to return if value is nil (defaults to nil)
Returns a symbol representing the instance method
# File lib/jekyll-github-metadata/edit-link-tag.rb, line 18 def self.def_hash_delegator(hash_method, key, method, default = nil) define_method(method) do hash = send(hash_method) if hash.respond_to? :[] hash[key.to_s] || default else default end end end
Public Instance Methods
render(context)
click to toggle source
# File lib/jekyll-github-metadata/edit-link-tag.rb, line 40 def render(context) @context = context if link_text link else uri.to_s end end
Private Instance Methods
ensure_not_just_a_slash(part)
click to toggle source
# File lib/jekyll-github-metadata/edit-link-tag.rb, line 120 def ensure_not_just_a_slash(part) part == "/" ? "" : part end
ensure_trailing_slash(part)
click to toggle source
# File lib/jekyll-github-metadata/edit-link-tag.rb, line 116 def ensure_trailing_slash(part) part.end_with?("/") ? part : "#{part}/" end
link()
click to toggle source
# File lib/jekyll-github-metadata/edit-link-tag.rb, line 58 def link "<a href=\"#{uri}\">#{link_text}</a>" end
link_text()
click to toggle source
# File lib/jekyll-github-metadata/edit-link-tag.rb, line 51 def link_text @link_text ||= begin matches = @markup.match LINK_TEXT_REGEX matches[1] || matches[2] if matches end end
memoize_conditionally() { || ... }
click to toggle source
Utility function for compatibility with Jekyll
4.0
# File lib/jekyll-github-metadata/edit-link-tag.rb, line 90 def memoize_conditionally if renderer_cached? yield else dispatcher = "@#{caller_locations(1..1).first.label}".to_sym if instance_variable_defined?(dispatcher) instance_variable_get(dispatcher) else instance_variable_set(dispatcher, yield) end end end
page()
click to toggle source
# File lib/jekyll-github-metadata/edit-link-tag.rb, line 85 def page memoize_conditionally { context.registers[:page] } end
parts()
click to toggle source
# File lib/jekyll-github-metadata/edit-link-tag.rb, line 71 def parts memoize_conditionally { [repository_url, "edit/", branch, source_path, page_path] } end
parts_normalized()
click to toggle source
# File lib/jekyll-github-metadata/edit-link-tag.rb, line 75 def parts_normalized memoize_conditionally do parts.map.with_index do |part, index| part = remove_leading_slash(part.to_s) part = ensure_trailing_slash(part) unless index == parts.length - 1 ensure_not_just_a_slash(part) end end end
remove_leading_slash(part)
click to toggle source
# File lib/jekyll-github-metadata/edit-link-tag.rb, line 112 def remove_leading_slash(part) part.start_with?("/") ? part[1..-1] : part end
renderer_cached?()
click to toggle source
Utility function to detect Jekyll
4.0
# File lib/jekyll-github-metadata/edit-link-tag.rb, line 104 def renderer_cached? @renderer_cached ||= context.registers[:site].liquid_renderer.respond_to?(:cache) end
site()
click to toggle source
# File lib/jekyll-github-metadata/edit-link-tag.rb, line 108 def site @site ||= context.registers[:site].site_payload["site"] end
uri()
click to toggle source
# File lib/jekyll-github-metadata/edit-link-tag.rb, line 62 def uri if parts.any?(&:nil?) Jekyll.logger.warn "JekyllEditLink: ", MISSING_DATA_MSG "" else Addressable::URI.join(*parts_normalized).normalize end end