Sha256: 7373933e6023f170fe0d07e8bbd60a8ee925749c90105edcf987a32ec8bca476

Contents?: true

Size: 1.94 KB

Versions: 18

Compression:

Stored size: 1.94 KB

Contents

module PagesHelper
  def current_page
  #   page = @page
  #   yield @page if block_given?
  # 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.children.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.roots
    end
    yield pages if block_given? && pages.length > 0
    pages
  end

  def homepage
    Kuhsaft::Page.roots.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

  def read_more_link(id)
    link_to(id, :'data-toggle' => 'collapse', :'data-target' => id, :class => 'collapsed button button-read-more') do
      @content = content_tag(:p, t('kuhsaft.text_bricks.text_brick.read_more'), :class => 'read-more-text')
      @content << content_tag(:p, t('kuhsaft.text_bricks.text_brick.read_less'), :class => 'read-less-text')
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
kuhsaft-1.6.0 app/helpers/pages_helper.rb
kuhsaft-1.5.0 app/helpers/pages_helper.rb
kuhsaft-1.4.3 app/helpers/pages_helper.rb
kuhsaft-1.4.2 app/helpers/pages_helper.rb
kuhsaft-1.4.1 app/helpers/pages_helper.rb
kuhsaft-1.4.0 app/helpers/pages_helper.rb
kuhsaft-1.3.1 app/helpers/pages_helper.rb
kuhsaft-1.2.15 app/helpers/pages_helper.rb
kuhsaft-1.2.14 app/helpers/pages_helper.rb
kuhsaft-1.2.13 app/helpers/pages_helper.rb
kuhsaft-1.2.12 app/helpers/pages_helper.rb
kuhsaft-1.2.11 app/helpers/pages_helper.rb
kuhsaft-1.2.10 app/helpers/pages_helper.rb
kuhsaft-1.2.9 app/helpers/pages_helper.rb
kuhsaft-1.2.8 app/helpers/pages_helper.rb
kuhsaft-1.2.7 app/helpers/pages_helper.rb
kuhsaft-1.2.6 app/helpers/pages_helper.rb
kuhsaft-1.2.5 app/helpers/pages_helper.rb