<commit_before>class Application < Merb::Controller
  before :ensure_authenticated

  def ensure_has_data_entry_privileges
    raise NotPrivileged unless session.user.data_entry_operator? || session.user.mis_manager? || session.user.admin?
  end

  def ensure_has_mis_manager_privileges
    raise NotPrivileged unless session.user.mis_manager? || session.user.admin?
  end

  def ensure_has_admin_privileges
    raise NotPrivileged unless session.user.admin?
  end
end



# small monkey patch, real patch is submitted to extlib/merb/dm, hoping for inclusion soon
class Date
  def inspect
    "<Date: #{self.to_s}>"
  end
end
<commit_msg>added render_to_pdf function in application controller<commit_after>class Application < Merb::Controller
  before :ensure_authenticated

  def ensure_has_data_entry_privileges
    raise NotPrivileged unless session.user.data_entry_operator? || session.user.mis_manager? || session.user.admin?
  end

  def ensure_has_mis_manager_privileges
    raise NotPrivileged unless session.user.mis_manager? || session.user.admin?
  end

  def ensure_has_admin_privileges
    raise NotPrivileged unless session.user.admin?
  end

  def render_to_pdf(options = nil)
    data = render_to_string(options)
    pdf = PDF::HTMLDoc.new
    pdf.set_option :bodycolor, :white
    pdf.set_option :toc, false
    pdf.set_option :portrait, true
    pdf.set_option :links, false
    pdf.set_option :webpage, true
    pdf.set_option :left, '2cm'
    pdf.set_option :right, '2cm'
    pdf << data
    pdf.generate
  end
end


# small monkey patch, real patch is submitted to extlib/merb/dm, hoping for inclusion soon
class Date
  def inspect
    "<Date: #{self.to_s}>"
  end
end

{'fraction_non_alphanumeric': 0.0763765541740675, 'fraction_numerical': 0.0011841326228537595, 'mean_word_length': 4.264797507788162, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5900041', 'n_tokens_mistral': 556, 'n_tokens_neox': 536, 'n_words': 139}