Class: Jekyll::Tags::Link

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/ngage/jekyll/tags/link.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, relative_path, tokens) ⇒ Link

Returns a new instance of Link.



12
13
14
15
16
# File 'lib/ngage/jekyll/tags/link.rb', line 12

def initialize(tag_name, relative_path, tokens)
  super

  @relative_path = relative_path.strip
end

Class Method Details

.tag_nameObject



7
8
9
# File 'lib/ngage/jekyll/tags/link.rb', line 7

def tag_name
  name.split("::").last.downcase
end

Instance Method Details

#render(context) ⇒ Object

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ngage/jekyll/tags/link.rb', line 18

def render(context)
  site = context.registers[:site]

  liquid = site.liquid_renderer.file("(jekyll:link)")
  relative_path = liquid.parse(@relative_path).render(context)

  site.each_site_file do |item|
    return item.url if item.relative_path == relative_path
    # This takes care of the case for static files that have a leading /
    return item.url if item.relative_path == "/#{relative_path}"
  end

  raise ArgumentError, <<~MSG
    Could not find document '#{relative_path}' in tag '#{self.class.tag_name}'.

    Make sure the document exists and the path is correct.
  MSG
end