Sha256: 84077596c7cf3fc43310de44e091c9e716fa74562e37cac17f31e326c0c77730

Contents?: true

Size: 1.51 KB

Versions: 35

Compression:

Stored size: 1.51 KB

Contents

module PagesHelper
  def current_page
    @current_page
  end

  def part(name, opts = {}, &block)
    if @current_page
      schema = opts.delete(:schema) || PagePart

      klass = schema.is_a?(Class)  ? schema : "#{schema.to_s.camelize}PagePart".constantize
      p = klass.where(:name => "#{name}", :page_id => @current_page.id).first
      p ||= klass.create!(:name => "#{name}", :page_id =>  @current_page.id)

      if block_given?
        capture do
          block.call(p)
        end
      else
      p
      end

    end
  end

  def page_path_for(resource_or_page)
    page = resource_or_page.is_a?(Page) ? resource_or_page : page_by_resource(resource_or_page)
    path = page.try(:path)
    if path.blank?
      "#not-found"
    else
      path.gsub(/:[A-z_]+/) do |seg|
        meth = seg.gsub(/^:/, "")
        resource_or_page.send(meth)
      end
    end

  end

  def page_url_for(resource_or_page)
    "#{request.protocol}#{request.host_with_port}#{page_path_for(resource_or_page)}"
  end

  def current_page_resource()
    if current_page && current_page.resourceful?
      controller.instance_variable_get("@#{current_page.resource_type}")
    end
  end

  private

  def page_by_resource(resource)
    resource_type = resource.class.name.underscore

    if Fullstack::Cms.config.localize
      locale = resource.respond_to?(:locale) ? resource.send(:locale) : I18n.locale.to_s
      Page.find_by_resource_type_and_locale(resource_type, locale)

    else
      Page.find_by_resource_type(resource_type)
    end
  end

end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
fullstack-cms-0.4.6 app/helpers/pages_helper.rb
fullstack-cms-0.4.5 app/helpers/pages_helper.rb
fullstack-cms-0.4.4 app/helpers/pages_helper.rb
fullstack-cms-0.4.3 app/helpers/pages_helper.rb
fullstack-cms-0.4.2 app/helpers/pages_helper.rb
fullstack-cms-0.4.1 app/helpers/pages_helper.rb
fullstack-cms-0.3.39 app/helpers/pages_helper.rb
fullstack-cms-0.3.38 app/helpers/pages_helper.rb
fullstack-cms-0.3.37 app/helpers/pages_helper.rb
fullstack-cms-0.3.36 app/helpers/pages_helper.rb
fullstack-cms-0.3.35 app/helpers/pages_helper.rb
fullstack-cms-0.3.34 app/helpers/pages_helper.rb
fullstack-cms-0.3.33 app/helpers/pages_helper.rb
fullstack-cms-0.3.32 app/helpers/pages_helper.rb
fullstack-cms-0.3.31 app/helpers/pages_helper.rb
fullstack-cms-0.3.30 app/helpers/pages_helper.rb
fullstack-cms-0.3.29 app/helpers/pages_helper.rb
fullstack-cms-0.3.28 app/helpers/pages_helper.rb
fullstack-cms-0.3.27 app/helpers/pages_helper.rb
fullstack-cms-0.3.26 app/helpers/pages_helper.rb