SongsDir = 'songs' SrcDir = 'src' BuildDir = 'public' TmpDir = 'tmp' TemplatesDir = 'templates' def song filename File.join SongsDir, filename end def build filename File.join BuildDir, filename end def tmp filename File.join TmpDir, filename end def src filename File.join SrcDir, filename end def song_lyrics song_id song "#{song_id}.txt" end def song_ly song_id song "#{song_id}.ly" end def song_meta song_id song "#{song_id}.yaml" end def song_partial_tex song_id song "#{song_id}-partial.tex" end def song_tex song_id song "#{song_id}.tex" end def song_sheet_pdf song_id song "#{song_id}.cropped.pdf" end def song_tmp_svg song_id song "#{song_id}.cropped.svg" end def song_pdf song_id song "#{song_id}.pdf" end def song_sheet_svg song_id song "#{song_id}.svg" end def song_svg song_id song "#{song_id}.svg" end def song_html song_id song "#{song_id}.html" end def template filename ERB.new(File.read(filename), trim_mode: '-') end def template_file filename File.join TemplatesDir, filename end def tex_template name template(template_file "#{name}.tex.erb") end def html_template name template(template_file "#{name}.html.erb") end def page_template html_template 'template' end def path_to asset_id P.path_to asset_id end def normalize title title.downcase.gsub /[[:punct:]]|[[:space:]]/, '' end def indexify title alphabet = "aąbcćdeęfghijklłmnńoóprsśtuwyzźż".chars normalized = normalize title normalized.chars.map do |c| index = alphabet.find_index c if index.nil? raise "Letter not in alphabet: #{c}" end index end end def polish_compare a, b indices_a = indexify a indices_b = indexify b indices_a <=> indices_b end