Class: Jekyll::PageUrl
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::PageUrl
- Defined in:
- lib/jekyll-pageurl.rb
Instance Method Summary collapse
-
#initialize(tag_name, text, tokens) ⇒ PageUrl
constructor
A new instance of PageUrl.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, text, tokens) ⇒ PageUrl
Returns a new instance of PageUrl.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/jekyll-pageurl.rb', line 3 def initialize(tag_name, text, tokens) super values = text.split(',') @link = nil @url = nil if(values.length != 1) raise ArgumentError.new <<-eos wrong format "#{@text}" in tag 'page_url'. eos end @url = values[0].strip 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
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/jekyll-pageurl.rb', line 28 def render(context) site = context.registers[:site] site.each_site_file do |p| url = site.config["baseurl"] if site.config["baseurl"] == "" url = site.config["url"] end if @link == p.relative_path if @anchor != nil full_url= url + p.url + "/#" + @anchor else full_url= url + p.url end return "#{ full_url }" end end raise ArgumentError.new <<-eos Could not find page "#{@link}" in tag 'page_url'. Make sure the post exists and the name and date is correct. eos end |