Module: JekyllBasenameDirnameName

Defined in:
lib/jekyll_basename_dirname.rb

Overview

Jekyll filters for working with paths.

Author:

  • Copyright 2020 Michael Slinn

Constant Summary collapse

PLUGIN_NAME =
'jekyll_basename_dirname'.freeze

Instance Method Summary collapse

Instance Method Details

#basename(filepath) ⇒ String

Filters a string containing a path.

Examples:

Extracts ‘filename.ext’ from the path

{{ 'blah/blah/filename.ext' | basename }}

Returns:

  • (String)

    the filename extracted from the path, including the filetype.



18
19
20
# File 'lib/jekyll_basename_dirname.rb', line 18

def basename(filepath)
  File.basename(filepath)
end

#basename_without_extension(filepath) ⇒ Object

Filters a string containing a path.

Examples:

Extracts ‘filename’ from the path.

{{ 'blah/blah/filename.ext' | basename_without_extension }}

Returns:

  • the filename without the extension.



34
35
36
# File 'lib/jekyll_basename_dirname.rb', line 34

def basename_without_extension(filepath)
  File.basename(filepath).split('.')[0...-1].join('.')
end

#dirname(filepath) ⇒ String

Filters a string containing a path.

Examples:

Extracts ‘blah/blah’ from the path.

{{ 'blah/blah/filename.ext' | dirname }}

Returns:

  • (String)

    the portion of th path before the filename and extension.



26
27
28
# File 'lib/jekyll_basename_dirname.rb', line 26

def dirname(filepath)
  File.dirname(filepath)
end

#wbr(filepath) ⇒ Object

Filters a string containing a path so long paths wrap in an HTML page. Returns:

blah/<wbr>/blah/<wbr>filename.ext

Examples:

{{ 'blah/blah/filename.ext' | wbr }}

Returns:

  • the path with ‘<wbr>’ inserted after every slash.



44
45
46
# File 'lib/jekyll_basename_dirname.rb', line 44

def wbr(filepath)
  filepath.gsub '/', '/<wbr>'
end