Sha256: d90a619b1a63a1c93599404638e9d5565c38cb278d29ae0c37a91c72d8f0a176

Contents?: true

Size: 1.25 KB

Versions: 11

Compression:

Stored size: 1.25 KB

Contents

module Cms
  class PageTemplate < Cms::DynamicView

    validates_format_of :name, :with => /\A[a-z]+[a-z0-9_]*\Z/, :message => "can only contain lowercase letters, numbers and underscores and must begin with a lowercase letter"

    def file_path
      File.join(self.class.file_path, file_name)
    end

    def self.relative_path
      File.join("layouts", "templates")
    end

    def self.file_path
      File.join(base_path, relative_path)
    end

    def self.display_name(file_name)
      name, format, handler = file_name.split('.')
      content_type = handler ? "#{format}/#{handler}" : "#{format}"
      "#{name.titleize} (#{content_type})"
    end

    # This is a combination of file system page templates
    # and database page templates
    def self.options
      file_system_templates = ActionController::Base.view_paths.map { |p| Dir["#{p}/#{relative_path}/*"] }.flatten.map { |f| File.basename(f) }
      page_templates = file_system_templates + all.map { |t| t.file_name }
      page_templates.map { |f| [display_name(f), f] }.sort.uniq
    end

    def partial?
      false
    end

    def placeholder
      "subpage"
    end

    # Generates hint for editing
    def hint
      "No spaces allowed. Must start with lowercase letter."
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
browsercms-artirix-4.0.4 app/models/cms/page_template.rb
browsercms-artirix-4.0.3.3 app/models/cms/page_template.rb
browsercms-artirix-4.0.3.2 app/models/cms/page_template.rb
browsercms-artirix-4.0.3.1 app/models/cms/page_template.rb
browsercms-artirix-4.0.3 app/models/cms/page_template.rb
browsercms-artirix-4.0.2 app/models/cms/page_template.rb
browsercms-artirix-4.0.1.1 app/models/cms/page_template.rb
browsercms-artirix-4.0.0.rc1.art4 app/models/cms/page_template.rb
browsercms-4.0.0.rc1 app/models/cms/page_template.rb
browsercms-4.0.0.beta app/models/cms/page_template.rb
browsercms-4.0.0.alpha app/models/cms/page_template.rb