Class: Bridgetown::Tags::PostUrl
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Bridgetown::Tags::PostUrl
- Includes:
- Filters::URLFilters
- Defined in:
- bridgetown-core/lib/bridgetown-core/tags/post_url.rb
Instance Method Summary collapse
-
#initialize(tag_name, post, tokens) ⇒ PostUrl
constructor
A new instance of PostUrl.
-
#render(context) ⇒ Object
Methods included from Filters::URLFilters
#absolute_url, #in_locale, #relative_url, #strip_extname, #strip_index
Constructor Details
#initialize(tag_name, post, tokens) ⇒ PostUrl
Returns a new instance of PostUrl.
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'bridgetown-core/lib/bridgetown-core/tags/post_url.rb', line 39 def initialize(tag_name, post, tokens) super @orig_post = post.strip begin @post = PostComparer.new(@orig_post) rescue StandardError => e raise Bridgetown::Errors::PostURLError, <<~MSG Could not parse name of post "#{@orig_post}" in tag 'post_url'. Make sure the post exists and the name is correct. #{e.class}: #{e.} MSG end end |
Instance Method Details
#render(context) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'bridgetown-core/lib/bridgetown-core/tags/post_url.rb', line 53 def render(context) @context = context site = context.registers[:site] site.collections.posts.resources.each do |document| return relative_url(document) if @post == document next end raise Bridgetown::Errors::PostURLError, <<~MSG Could not find post "#{@orig_post}" in tag 'post_url'. Make sure the post exists and the name is correct. MSG end |