Sha256: 010fc810222312d113007d2f61cd2d758394d84577c86102e09e89da92576db1

Contents?: true

Size: 1.53 KB

Versions: 9

Compression:

Stored size: 1.53 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.find_or_create_by_name_and_page_id("#{name}", @current_page)
      
      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
  
  def home?
    request.path == "/"
  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

9 entries across 9 versions & 1 rubygems

Version Path
fullstack-cms-0.2.13 app/helpers/pages_helper.rb
fullstack-cms-0.2.12 app/helpers/pages_helper.rb
fullstack-cms-0.2.11 app/helpers/pages_helper.rb
fullstack-cms-0.2.10 app/helpers/pages_helper.rb
fullstack-cms-0.2.9 app/helpers/pages_helper.rb
fullstack-cms-0.2.8 app/helpers/pages_helper.rb
fullstack-cms-0.2.7 app/helpers/pages_helper.rb
fullstack-cms-0.2.6 app/helpers/pages_helper.rb
fullstack-cms-0.2.5 app/helpers/pages_helper.rb