def short_date(s)
  return if s.nil?
  Date.parse(s).strftime("%e %b %Y")
end

def cleanup(s)
  return if s.nil?
  s.sub!('Unknown', '')
  s.sub!('Not Available', '')
  s.sub!('Not Applicable', '')
  s = "<span class=grant>#{s}</span>" if s.match(/(approve|grant|permitted)/i)
  s = "<span class=refuse>#{s}</span>" if s.match(/refus/i)
  s
end

def slug(s)
  s.downcase.gsub(' ', '-')
end

def authority_url(authority_name)
  "/authorities/#{slug(authority_name)}/"
end

def download_button(filename, label='Download CSV data')
  "<a class=button href=#{filename} download=#{filename}>#{label}</a>"
end