Module: Neruda::OrgFileClassMethods

Included in:
OrgFile
Defined in:
lib/neruda/org_file/class_methods.rb

Overview

This module holds class methods for the OrgFile class.

Instance Method Summary collapse

Instance Method Details

#html_file(file_name) ⇒ Object



6
7
8
9
10
11
# File 'lib/neruda/org_file/class_methods.rb', line 6

def html_file(file_name)
  return nil if file_name.nil?
  path = Neruda::OrgFile.target_for_source(file_name)
  pubfolder = Neruda::Config.settings['public_folder']
  path.sub(/^#{pubfolder}\//, '/')
end

#html_file_with_domain(file_name) ⇒ Object



13
14
15
16
# File 'lib/neruda/org_file/class_methods.rb', line 13

def html_file_with_domain(file_name)
  return nil if file_name.nil?
  Neruda::Config.settings['domain'] + html_file(file_name)
end

#slug(title) ⇒ Object



35
36
37
38
39
# File 'lib/neruda/org_file/class_methods.rb', line 35

def slug(title)
  title.downcase.gsub(' ', '-')
       .encode('ascii', fallback: ->(k) { translit(k) })
       .gsub(/[^\w-]/, '').gsub(/-$/, '')
end

#source_for_target(file_name) ⇒ Object



18
19
20
21
22
23
# File 'lib/neruda/org_file/class_methods.rb', line 18

def source_for_target(file_name)
  # file_name may be frozen...
  src = file_name.sub(/\.html$/, '.org')
  pubfolder = Neruda::Config.settings['public_folder']
  src.sub(/^#{pubfolder}\//, 'src/')
end

#target_for_source(file_name) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/neruda/org_file/class_methods.rb', line 25

def target_for_source(file_name)
  # file_name may be frozen...
  target = file_name.sub(/\.org$/, '.html')
  pubfolder = Neruda::Config.settings['public_folder']
  return target.sub(/^src\//, "#{pubfolder}/") if /^src\//.match?(target)
  subfolder = File.basename(File.dirname(target))
  leaf = File.basename(target)
  "#{pubfolder}/#{subfolder}/#{leaf}"
end