Sha256: fb3fd6cdbe1ef3d7e25fcad1e0e977a5ef73cc67fd3a358d766d5bc4a1f51454

Contents?: true

Size: 1.72 KB

Versions: 22

Compression:

Stored size: 1.72 KB

Contents

module PagesHelper
  def current_page
    lang = Kuhsaft::Page.current_translation_locale
    page = Kuhsaft::Page.find(@page.id).localized_pages.where('locale = ?', lang).first.page
    page.translation
    yield page if block_given?
    page
  rescue
  end
  
  def current_page_path(lang=nil)
    if @page.present?
      '/' + Kuhsaft::Page.find(@page.id).localized_pages.where('locale = ?', lang).first.url
    else
      root_path
    end
  rescue
    root_path
  end

  def asset_for id
    Kuhsaft::Asset.find(id)
  end
  
  def render_markdown text
    RDiscount.new(text).to_html if text.present?
  end

  def navigation_for options
    if options.is_a?(Hash) && slug = options.delete(:slug)
      pages = Kuhsaft::LocalizedPage.navigation(slug).first.page.childs.current_locale.published rescue []
    elsif (options.is_a?(Fixnum) && id = options) ||  id = options.delete(:id)
      pages = Kuhsaft::Page.published.where('parent_id = ?', id)
    elsif options.nil?
      pages = Kuhsaft::Page.published.root_pages
    end
    yield pages if block_given? && pages.length > 0
    pages
  end
  
  def homepage
    Kuhsaft::Page.root_pages.first
  end
  
  def page_for_level num
    input = controller.current_url if controller.respond_to? :current_url
    input ||= params[:url].presence || ''
    url = input.split('/').take(num + 1).join('/') unless input.blank?
    page = Kuhsaft::Page.find_by_url(url)
    yield page if block_given?
    page
  rescue
  end

  def active_page_class page
    input = controller.current_url if controller.respond_to? :current_url
    input ||= params[:url].presence || ''
    input.include?(page.url.to_s) ? :active : nil
  end

  def current_page_class page
    :current if active_page_class(page) == :active
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
kuhsaft-0.2.legacy4 app/helpers/pages_helper.rb
kuhsaft-0.3.4.legacy3 app/helpers/pages_helper.rb
kuhsaft-0.2.legacy3 app/helpers/pages_helper.rb
kuhsaft-0.2.legacy2 app/helpers/pages_helper.rb
kuhsaft-0.2.legacy app/helpers/pages_helper.rb
kuhsaft-0.3.4.legacy2 app/helpers/pages_helper.rb
kuhsaft-0.3.4.legacy app/helpers/pages_helper.rb
kuhsaft-0.3.6 app/helpers/pages_helper.rb
kuhsaft-0.3.5 app/helpers/pages_helper.rb
kuhsaft-0.3.4 app/helpers/pages_helper.rb
kuhsaft-0.3.4.rc2 app/helpers/pages_helper.rb
kuhsaft-0.3.4.rc1 app/helpers/pages_helper.rb
kuhsaft-0.3.3 app/helpers/pages_helper.rb
kuhsaft-0.3.2 app/helpers/pages_helper.rb
kuhsaft-0.2.5 app/helpers/pages_helper.rb
kuhsaft-0.2.4 app/helpers/pages_helper.rb
kuhsaft-0.2.3 app/helpers/pages_helper.rb
kuhsaft-0.3.1 app/helpers/pages_helper.rb
kuhsaft-0.3.0 app/helpers/pages_helper.rb
kuhsaft-0.2.2 app/helpers/pages_helper.rb