Sha256: 6e78a02b30b21545235785b07f27851d315bfb0ffcfeac5dd94cc072f2a4099a

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

module PagesHelper
  def link_to_locale(link_name, locale, page=nil)
    if page
      link_to link_name, url_to_page(page, locale.to_s)
    elsif request.fullpath.match(/^\/\w{2}\/.*/)
      link_to link_name, request.fullpath.gsub(/^\/(\w{2})\//, "/#{locale.code}/")
    else
      link_to link_name, "/#{locale.code}"
    end
  end

  def link_to_search_result(result)
    if result.is_a? ActiveadminSelleoCms::Page
      "#{link_to result.breadcrumb, result.url} #{link_to "(e)", edit_admin_page_path(result.id), target: '_blank' if current_user}".html_safe
    end
  end

  def url_to_page(page, locale=I18n.locale)
    return "#" unless page
    _locale = I18n.locale
    I18n.locale = locale
    _url = page.url
    I18n.locale = _locale
    return _url
  end

  def link_to_page(page, link_name=nil)
    link_to (link_name || page.title), page.url
  end

  def s(name)
    section = ActiveadminSelleoCms::Section.where(name: name).first_or_create
    body = section.body.to_s
    body = "" if body.match /<p>\s*<\/p>/
    body += link_to(t("active_admin.cms.edit"), edit_admin_section_path(section)) if current_user and current_user.respond_to? :admin? and current_user.admin?
    body.html_safe
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
activeadmin-selleo-cms-0.0.23 app/helpers/pages_helper.rb
activeadmin-selleo-cms-0.0.22 app/helpers/pages_helper.rb
activeadmin-selleo-cms-0.0.21 app/helpers/pages_helper.rb