module Asciidoctor::Helpers

def basename filename, drop_ext = nil

Returns the String filename with leading directories removed and, if specified, the extension removed

# => "tiger"
Helpers.basename 'images/tiger.png', '.png'

# => "tiger"
Helpers.basename 'images/tiger.png', true

Examples

or an explicit String extension to drop (default: nil).
drop_ext - A Boolean flag indicating whether to drop the extension
filename - The String file name to process.

Public: Retrieves the basename of the filename, optionally removing the extension, if present
def basename filename, drop_ext = nil
  if drop_ext
    ::File.basename filename, (drop_ext == true ? (extname filename) : drop_ext)
  else
    ::File.basename filename
  end
end