class Jekyll::FilePath
Public Class Methods
new(tag_name, markup, tokens)
click to toggle source
Calls superclass method
# File lib/jekyll-filepath.rb, line 5 def initialize(tag_name, markup, tokens) @markup = markup.strip super end
Public Instance Methods
render(context)
click to toggle source
# File lib/jekyll-filepath.rb, line 10 def render(context) if @markup.empty? return "Expected syntax {% filepath [filename] %}" end rawFilename = Liquid::Template.parse(@markup).render context filename = rawFilename.gsub(/^("|')|("|')$/, '') path = "" page = context.environments.first["page"] if page["id"] context.registers[:site].posts.docs.each do |post| if post.id == page["id"] path = "#{post.relative_path}".gsub(/_posts/, '').gsub(/.md/, '') end end else path = page["url"] end path = File.dirname(path) if path =~ /\.\w+$/ "/files/#{path}/#{filename}".gsub(/\/{2,}/, '/') end