Sha256: d7f4b59b87b0456b39852c253dcc2acb31be691f7883a42beaac439af05cb05d

Contents?: true

Size: 1.61 KB

Versions: 28

Compression:

Stored size: 1.61 KB

Contents

module RocketCMS
  module Models
    module Page
      extend ActiveSupport::Concern
      include RocketCMS::Model
      include Enableable
      include Seoable
      include ManualSlug

      include RocketCMS.orm_specific('Page')

      if RocketCMS.configuration.search_enabled
        include RocketCMS::ElasticSearch
      end
        
      included do
        has_and_belongs_to_many :menus, inverse_of: :pages
        before_validation do
          self.fullpath = "/pages/#{slug}" if self.fullpath.blank?
        end
        validates_uniqueness_of :fullpath
        validates_presence_of :name
        manual_slug :name
      end

      def get_fullpath
        redirect.blank? ? fullpath : redirect
      end

      def has_content?
        @content_used.nil? && !content.blank?
      end

      def page_content
        if @content_used.nil?
          @content_used = true
          if content.nil?
            ''
          else
            content.gsub(/\{\{(.*?)\}\}/) do
              Settings.get($1).val
            end
          end
        else
          ''
        end
      end

      def is_current?(url)
        if fullpath == '/'
          url == '/'
        else
          url.match(clean_regexp)
        end
      end
      
      def clean_regexp
        if regexp.blank?
          /^#{Regexp.escape(fullpath)}$/
        else
          begin
            /#{regexp}/
          rescue
            # not a valid regexp - treat as literal search string
            /#{Regexp.escape(regexp)}/
          end
        end
      end
      
      def nav_options
        {highlights_on: clean_regexp}
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
rocket_cms-0.6.16 lib/rocket_cms/models/page.rb
rocket_cms-0.6.15 lib/rocket_cms/models/page.rb
rocket_cms-0.6.14 lib/rocket_cms/models/page.rb
rocket_cms-0.6.13 lib/rocket_cms/models/page.rb
rocket_cms-0.6.12 lib/rocket_cms/models/page.rb
rocket_cms-0.6.11 lib/rocket_cms/models/page.rb
rocket_cms-0.6.10 lib/rocket_cms/models/page.rb
rocket_cms-0.6.9 lib/rocket_cms/models/page.rb
rocket_cms-0.6.8 lib/rocket_cms/models/page.rb
rocket_cms-0.6.7 lib/rocket_cms/models/page.rb
rocket_cms-0.6.6 lib/rocket_cms/models/page.rb
rocket_cms-0.6.5 lib/rocket_cms/models/page.rb
rocket_cms-0.6.4 lib/rocket_cms/models/page.rb
rocket_cms-0.6.3 lib/rocket_cms/models/page.rb
rocket_cms-0.6.2 lib/rocket_cms/models/page.rb
rocket_cms-0.6.1 lib/rocket_cms/models/page.rb
rocket_cms-0.6.0 lib/rocket_cms/models/page.rb
rocket_cms-0.5.24 lib/rocket_cms/models/page.rb
rocket_cms-0.5.23 lib/rocket_cms/models/page.rb
rocket_cms-0.5.22 lib/rocket_cms/models/page.rb