Module: PagesHelper
- Defined in:
- app/helpers/pages_helper.rb
Instance Method Summary collapse
- #editing? ⇒ Boolean
- #link_to_locale(link_name, locale, page = nil) ⇒ Object
- #link_to_page(page, link_name = nil, options = {}) ⇒ Object
- #link_to_search_result(result) ⇒ Object
- #locales(options = {}, &block) ⇒ Object
- #menu(options = {}) ⇒ Object
- #root ⇒ Object
- #s(name) ⇒ Object
- #switch_editing ⇒ Object
- #url_to_page(page, locale = I18n.locale) ⇒ Object
- #with_host(relative_path) ⇒ Object
Instance Method Details
#editing? ⇒ Boolean
85 86 87 |
# File 'app/helpers/pages_helper.rb', line 85 def editing? current_user and params[:editing]=="true" end |
#link_to_locale(link_name, locale, page = nil) ⇒ Object
2 3 4 5 6 7 8 9 10 |
# File 'app/helpers/pages_helper.rb', line 2 def link_to_locale(link_name, locale, page=nil) if page link_to link_name, with_host(url_to_page(page, locale.to_s)) elsif request.fullpath.match(/^\/\w{2}\/.*/) link_to link_name, with_host(request.fullpath.gsub(/^\/(\w{2})\//, "/#{locale.code}/")) else link_to link_name, with_host("/#{locale.code}") end end |
#link_to_page(page, link_name = nil, options = {}) ⇒ Object
31 32 33 |
# File 'app/helpers/pages_helper.rb', line 31 def link_to_page(page, link_name=nil, ={}) link_to (link_name || page.title), with_host(page.url), end |
#link_to_search_result(result) ⇒ Object
16 17 18 19 20 |
# File 'app/helpers/pages_helper.rb', line 16 def link_to_search_result(result) if result.is_a? ActiveadminSelleoCms::Page "#{link_to result., with_host(result.url)} #{link_to "(e)", edit_admin_page_path(result.id), target: '_blank' if current_user}".html_safe end end |
#locales(options = {}, &block) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/helpers/pages_helper.rb', line 59 def locales(={}, &block) [:ul] ||= {} [:li] ||= {} locales_scope = ActiveadminSelleoCms::Locale.enabled locales_scope = locales_scope.exclude(I18n.locale) unless [:current_locale] content_tag :ul, class: [:ul][:class] do locales_scope.collect{ |locale| classes = [[:li][:class], [:li][:selected]].compact.join(" ") if locale == I18n.locale if block_given? concat(content_tag :li, yield(locale), class: classes) else concat(content_tag :li, link_to_locale(locale.code.to_s.upcase, locale, @page), class: classes) end } end end |
#menu(options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/helpers/pages_helper.rb', line 43 def (={}) [:ul] ||= {} [:li] ||= {} content_tag :ul, class: [:ul][:class] do ActiveadminSelleoCms::Page.published..where(parent_id: [:root]).reorder("lft ASC").collect{ |page| classes = [[:li][:class], [:li][:selected]].compact.join(" ") if page == @page if block_given? concat(content_tag :li, yield(page), class: classes) else concat(content_tag :li, link_to_page(page), class: classes) end } end end |
#root ⇒ Object
77 78 79 |
# File 'app/helpers/pages_helper.rb', line 77 def root page_path(I18n.locale, ActiveadminSelleoCms::Page.root) end |
#s(name) ⇒ Object
35 36 37 38 39 40 41 |
# File 'app/helpers/pages_helper.rb', line 35 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 |
#switch_editing ⇒ Object
81 82 83 |
# File 'app/helpers/pages_helper.rb', line 81 def switch_editing params[:editing] ? request.url.sub(/\?editing=[^&]*/, '?').sub(/\&editing=[^&]*/, '').sub(/\?$/,'') : request.url+'?editing=true' end |
#url_to_page(page, locale = I18n.locale) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'app/helpers/pages_helper.rb', line 22 def url_to_page(page, locale=I18n.locale) return "#" unless page _locale = I18n.locale I18n.locale = locale _url = with_host(page.url) I18n.locale = _locale return _url end |
#with_host(relative_path) ⇒ Object
12 13 14 |
# File 'app/helpers/pages_helper.rb', line 12 def with_host(relative_path) relative_path.match(/http/) ? relative_path : "#{request.protocol}#{request.host_with_port}#{relative_path}" end |