Module: SapeHelper

Defined in:
lib/app/helpers/sape_helper.rb

Instance Method Summary collapse

Instance Method Details



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/app/helpers/sape_helper.rb', line 25

def sape_context_links(text, site_host = request.host)
  request.original_fullpath.chomp!("/") if request.original_fullpath.last == "/" && request.original_fullpath != '/'
  SapeLink.where(page: request.original_fullpath, link_type: "context", site_host: site_host).each do |link|
    text.sub!(link.anchor, link.raw_link)
  end

  if SapeConfig.bot_ips(site_host).include?(request.remote_addr)
    "<sape_index>" + text + "</sape_index>" + SapeConfig.check_code(site_host)
  else
    text
  end.html_safe
rescue Exception => e
  "<!-- ERROR: #{e.message} -->".html_safe
end


14
15
16
17
18
19
20
21
22
23
# File 'lib/app/helpers/sape_helper.rb', line 14

def sape_links(site_host = request.host)
  request.original_fullpath.chomp!("/") if request.original_fullpath.last == "/" && request.original_fullpath != '/'
  links = SapeLink.where(page: request.original_fullpath, link_type: "simple", site_host: site_host).
           pluck(:raw_link).
           join(SapeConfig.delimiter(site_host))

  (SapeConfig.bot_ips(site_host).include?(request.remote_addr) ? (links + SapeConfig.check_code(site_host)) : links).html_safe
rescue Exception => e
  "<!-- ERROR: #{e.message} -->".html_safe
end


2
3
4
5
6
7
8
9
10
11
12
# File 'lib/app/helpers/sape_helper.rb', line 2

def sape_links_block(site_host = request.host)
  request.original_fullpath.chomp!("/") if request.original_fullpath.last == "/" && request.original_fullpath != '/'
  options = { links: SapeLink.where(page: request.original_fullpath, link_type: "simple", site_host: site_host) }
  if SapeConfig.bot_ips(site_host).include?(request.remote_addr)
    options.merge!(check_code: SapeConfig.check_code(site_host))
  end

  render template: 'sape/links', locals: options
rescue Exception => e
  "<!-- ERROR: #{e.message} -->".html_safe
end