class Staticpress::Content::Page
Attributes
full_slug[R]
Public Class Methods
all()
click to toggle source
# File lib/staticpress/content/page.rb, line 45 def self.all all_but_posts = if (posts_dir = Staticpress.blog_path + config.posts_source_path).directory? (Staticpress.blog_path + config.source_path).children - [ posts_dir ] else (Staticpress.blog_path + config.source_path).children end gather_resources_from all_but_posts end
create(format, title, path = nil)
click to toggle source
# File lib/staticpress/content/page.rb, line 59 def self.create(format, title, path = nil) name = title.gsub(/ /, '-').downcase filename = "#{name}.#{format}" destination = Staticpress.blog_path + config.source_path + (path ? path : '').sub(/^\//, '') + filename FileUtils.mkdir_p destination.dirname destination.open('w') { |f| f.write template } end
extract_slug(path)
click to toggle source
# File lib/staticpress/content/page.rb, line 69 def self.extract_slug(path) base_path = Staticpress.blog_path + config.source_path supported = find_supported_extensions(path) extension = supported.empty? ? '' : "\\.#{supported.reverse.join('\.')}" if match = /^#{base_path}\/(?<slug>.+)#{extension}$/.match(path.to_s) basename = extensionless_basename Pathname(config.index_file) match[:slug].sub(/.*(\/?#{basename})$/, '') end end
find_by_path(path)
click to toggle source
# File lib/staticpress/content/page.rb, line 80 def self.find_by_path(path) new :slug => extract_slug(path) if path.file? end
new(params = {})
click to toggle source
Calls superclass method
Staticpress::Content::Base::new
# File lib/staticpress/content/page.rb, line 12 def initialize(params = {}) super source_path = Staticpress.blog_path + config.source_path @full_slug = params[:slug] @template_types = find_supported_extensions(source_path + full_slug) unless template_path.file? @full_slug = [ params[:slug], extensionless_basename(Pathname(config.index_file)) ].reject(&:empty?).join('/') @template_types = find_supported_extensions(source_path + full_slug) end end
published()
click to toggle source
# File lib/staticpress/content/page.rb, line 55 def self.published all.select &:published? end
template()
click to toggle source
# File lib/staticpress/content/page.rb, line 84 def self.template <<-TEMPLATE in page TEMPLATE end
Public Instance Methods
preferred_layout_names()
click to toggle source
# File lib/staticpress/content/page.rb, line 37 def preferred_layout_names [meta.layout, :page] end
save()
click to toggle source
# File lib/staticpress/content/page.rb, line 29 def save save! end
static?()
click to toggle source
# File lib/staticpress/content/page.rb, line 33 def static? (Staticpress.blog_path + config.source_path + params[:slug]).file? end
template_path()
click to toggle source
# File lib/staticpress/content/page.rb, line 41 def template_path Staticpress.blog_path + config.source_path + "#{full_slug}#{template_extension}" end