Module: Mailpeek::WebHelpers
- Defined in:
- lib/mailpeek/web/helpers.rb
Overview
Private: WebHelpers
Instance Method Summary collapse
- #current_path ⇒ Object
- #emails ⇒ Object
- #h(text) ⇒ Object
- #product_version ⇒ Object
- #query_string ⇒ Object
- #redirect_with_query(url) ⇒ Object
- #root_path ⇒ Object
- #simple_format(text) ⇒ Object
- #unread ⇒ Object
Instance Method Details
#current_path ⇒ Object
40 41 42 |
# File 'lib/mailpeek/web/helpers.rb', line 40 def current_path @current_path ||= request.path_info.gsub(%r{^\/}, '') end |
#emails ⇒ Object
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..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 ⇒ Object
32 33 34 |
# File 'lib/mailpeek/web/helpers.rb', line 32 def product_version "v#{Mailpeek::VERSION}" end |
#query_string ⇒ Object
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_path ⇒ Object
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 |