module Mailpeek::WebHelpers

Private: WebHelpers

Public Instance Methods

current_path() click to toggle source
# File lib/mailpeek/web/helpers.rb, line 40
def current_path
  @current_path ||= request.path_info.gsub(%r{^\/}, '')
end
emails() click to toggle source
# File lib/mailpeek/web/helpers.rb, line 11
def emails
  return @emails if @emails

  @emails = Mailpeek.emails

  if params[:q].present?
    @emails = @emails.select { |x| x.match?(params[:q]) }
  end

  @total_count = emails.size
  @emails = @emails.first((params[:per] || 20).to_i)
end
h(text) click to toggle source
# File lib/mailpeek/web/helpers.rb, line 44
def h(text)
  ::Rack::Utils.escape_html(text)
rescue ArgumentError => e
  raise unless e.message.eql?('invalid byte sequence in UTF-8')

  text.encode!('UTF-16', 'UTF-8', invalid: :replace, replace: '')
      .encode!('UTF-8', 'UTF-16')
  retry
end
product_version() click to toggle source
# File lib/mailpeek/web/helpers.rb, line 32
def product_version
  "v#{Mailpeek::VERSION}"
end
query_string() click to toggle source
# File lib/mailpeek/web/helpers.rb, line 36
def query_string
  @query_string ||= request.query_string
end
redirect_with_query(url) click to toggle source
# File lib/mailpeek/web/helpers.rb, line 58
def redirect_with_query(url)
  redirect("#{url}?#{query_string}")
end
root_path() click to toggle source
# File lib/mailpeek/web/helpers.rb, line 28
def root_path
  "#{env['SCRIPT_NAME']}/"
end
simple_format(text) click to toggle source
# File lib/mailpeek/web/helpers.rb, line 54
def simple_format(text)
  text.split("\n").join('<br />')
end
unread() click to toggle source
# File lib/mailpeek/web/helpers.rb, line 24
def unread
  @unread ||= Mailpeek.unread
end