Module: Mint::Helpers

Defined in:
lib/mint/helpers.rb

Class Method Summary collapse

Class Method Details

.drop_pathname(pathname, levels_to_drop) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/mint/helpers.rb', line 5

def self.drop_pathname(pathname, levels_to_drop)
  parts = pathname.to_s.split('/').reject(&:empty?)
  if levels_to_drop >= parts.length
    pathname
  else
    dropped_parts = parts.drop(levels_to_drop)
    if dropped_parts.empty?
      Pathname.new('.')
    else
      Pathname.new(dropped_parts.join('/'))
    end
  end
end

.extract_title_from_file(file_path) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mint/helpers.rb', line 19

def self.extract_title_from_file(file_path)
  content = File.read(file_path.to_s)
  
  # Check for Title metadata in Markdown front matter
  if content =~ /^---\n.*?^title:\s*(.+)$/m
    return $1.strip.gsub(/^["']|["']$/, '')
  end
  
  # Check for first markdown heading  
  if content =~ /^#\s+(.+)$/
    return $1.strip
  end
  
  # Fall back to upcased filename with underscores/hyphens converted to spaces
  file_path.basename('.*').to_s.tr('_-', ' ').upcase
end