Sha256: 9dc7a9c340d0824cce6f2eba410dcaff1eb783aaf36ee681610c4d7c61d71453

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 KB

Contents

# Unlike other scoped classes, there is no site association in the Page class. Instead, Site has a homepage association and Page has some retrieval methods that turn a page request into site information.

module MultiSite::PageExtensions
  def self.included(base)
    base.class_eval {
      alias_method_chain :url, :sites
      mattr_accessor :current_site
      has_one :site, :foreign_key => "homepage_id", :dependent => :nullify
    }
    base.extend ClassMethods
    class << base
      def find_by_path(path, live=true)
        root = homepage
        raise Page::MissingRootPageError unless root
        root.find_by_path(path, live)
      end
      def current_site
        @current_site ||= Site.default
      end
      def current_site=(site)
        @current_site = site
      end
    end
  end
  
  module ClassMethods
    def homepage
      if current_site.is_a?(Site)
        homepage = self.current_site.homepage
      end
      homepage ||= find_by_parent_id(nil)
    end
  end
  
  def url_with_sites
    if parent
      parent.child_url(self)
    else
      "/"
    end
  end
  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
trusty-multi-site-extension-1.0.4 lib/multi_site/page_extensions.rb
trusty-multi-site-extension-1.0.3 lib/multi_site/page_extensions.rb
trusty-multi-site-extension-1.0.2 lib/multi_site/page_extensions.rb
trusty-multi-site-extension-1.0.1 lib/multi_site/page_extensions.rb
trusty-multi-site-extension-1.0.0 lib/multi_site/page_extensions.rb