class Staticpress::Content::Post
Public Class Methods
all()
click to toggle source
# File lib/staticpress/content/post.rb, line 45 def self.all if (posts_dir = Staticpress.blog_path + config.posts_source_path).directory? posts_dir.children.map { |post| find_by_path post } else [] end end
create(format, title)
click to toggle source
# File lib/staticpress/content/post.rb, line 57 def self.create(format, title) now = Time.now.utc created_on = "#{now.year}-#{'%02d' % now.month}-#{'%02d' % now.day}" name = title.gsub(/ /, '-').downcase filename = "#{created_on}-#{name}.#{format}" destination = Staticpress.blog_path + config.posts_source_path + filename FileUtils.mkdir_p destination.dirname destination.open('w') { |f| f.write template } end
find_by_path(path)
click to toggle source
# File lib/staticpress/content/post.rb, line 69 def self.find_by_path(path) if path.file? stubs = Staticpress::Route::REGEX_STUBS regex = /#{stubs[:year].regex}-#{stubs[:month].regex}-#{stubs[:day].regex}-#{stubs[:title].regex}\.(.+)/ if filename_parts = path.basename.to_s.match(regex) new hash_from_match_data(filename_parts) end end end
new(params)
click to toggle source
Calls superclass method
Staticpress::Content::Base::new
# File lib/staticpress/content/post.rb, line 5 def initialize(params) super # FIXME calculate template_path @template_types = find_supported_extensions template_path end
published()
click to toggle source
# File lib/staticpress/content/post.rb, line 53 def self.published all.select &:published? end
template()
click to toggle source
# File lib/staticpress/content/post.rb, line 80 def self.template now = Time.now.utc <<-TEMPLATE --- created_at: #{now} --- in post TEMPLATE end
Public Instance Methods
<=>(other)
click to toggle source
Calls superclass method
# File lib/staticpress/content/post.rb, line 11 def <=>(other) other.respond_to?(:created_at) ? (created_at <=> other.created_at) : super end
created_at()
click to toggle source
# File lib/staticpress/content/post.rb, line 15 def created_at meta.created_at ? meta.created_at.utc : created_on end
created_on()
click to toggle source
# File lib/staticpress/content/post.rb, line 19 def created_on Time.utc params[:year], params[:month], params[:day] end
preferred_layout_names()
click to toggle source
# File lib/staticpress/content/post.rb, line 23 def preferred_layout_names [meta.layout, :post] end
template_path()
click to toggle source
# File lib/staticpress/content/post.rb, line 27 def template_path name = [ params[:year], params[:month], params[:day], "#{params[:title]}#{template_extension}" ].join('-') Staticpress.blog_path + config.posts_source_path + name end
title()
click to toggle source
# File lib/staticpress/content/post.rb, line 37 def title if meta.title meta.title else titleize(params[:title]) end end