Module: Mailpeek::WebHelpers

Defined in:
lib/mailpeek/web/helpers.rb

Overview

Private: WebHelpers

Instance Method Summary collapse

Instance Method Details

#current_pathObject



40
41
42
# File 'lib/mailpeek/web/helpers.rb', line 40

def current_path
  @current_path ||= request.path_info.gsub(%r{^\/}, '')
end

#emailsObject



11
12
13
14
15
16
17
18
19
20
21
22
# 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) ⇒ Object



44
45
46
47
48
49
50
51
52
# 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_versionObject



32
33
34
# File 'lib/mailpeek/web/helpers.rb', line 32

def product_version
  "v#{Mailpeek::VERSION}"
end

#query_stringObject



36
37
38
# File 'lib/mailpeek/web/helpers.rb', line 36

def query_string
  @query_string ||= request.query_string
end

#redirect_with_query(url) ⇒ Object



58
59
60
# File 'lib/mailpeek/web/helpers.rb', line 58

def redirect_with_query(url)
  redirect("#{url}?#{query_string}")
end

#root_pathObject



28
29
30
# File 'lib/mailpeek/web/helpers.rb', line 28

def root_path
  "#{env['SCRIPT_NAME']}/"
end

#simple_format(text) ⇒ Object



54
55
56
# File 'lib/mailpeek/web/helpers.rb', line 54

def simple_format(text)
  text.split("\n").join('<br />')
end

#unreadObject



24
25
26
# File 'lib/mailpeek/web/helpers.rb', line 24

def unread
  @unread ||= Mailpeek.unread
end