Class: Jekyll::PageLink

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll-pagelink.rb

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, text, tokens) ⇒ PageLink



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/jekyll-pagelink.rb', line 3

def initialize(tag_name, text, tokens)
    super
    values = text.split(',')
    @hrefText = nil
    @link = nil
    @url = nil

    if values.length == 1
        @url = values[0].strip
    else
        @hrefText = values[0].strip
        @url = values[1].strip
    end

    urlvalues = @url.split('#')
         
    if urlvalues.length == 1
        @link = urlvalues[0].strip
    else
        @link = urlvalues[0].strip
        @anchor = urlvalues[1].strip
    end
end

Instance Method Details

#render(context) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/jekyll-pagelink.rb', line 27

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

    site.each_site_file do |p|


        if @link == p.relative_path 
            if @anchor != nil
                full_url=  site.config["baseurl"] +  p.url + "/#" + @anchor
            else
                full_url=  site.config["baseurl"] +  p.url
            end
            title = @hrefText
            if @hrefText == nil
                title = p.data["title"]  
            end
            return "<a href=\"#{ full_url }\">#{ title }</a>"
        end
    end
    raise ArgumentError.new "        Could not find page \"\#{@link}\" in tag 'page_link'.\n        Make sure the post exists and the name and date is correct.\n        eos\nend\n"