class Statikaj::Article

Public Class Methods

new(obj, config) click to toggle source
# File lib/statikaj/article.rb, line 7
def initialize obj, config
  @obj, @config = obj, config
  self.load
end

Public Instance Methods

[](key) click to toggle source
Calls superclass method
# File lib/statikaj/article.rb, line 35
def [] key
  self.load unless self.tainted?
  super
end
author() click to toggle source
# File lib/statikaj/article.rb, line 70
def author
  self[:author]
end
body() click to toggle source
# File lib/statikaj/article.rb, line 54
def body
  markdown self[:body].sub("~~~", '')
end
category() click to toggle source
# File lib/statikaj/article.rb, line 74
def category
  self[:category]
end
date() click to toggle source
# File lib/statikaj/article.rb, line 66
def date
  self[:date]
end
load() click to toggle source
# File lib/statikaj/article.rb, line 20
def load
  data = if @obj.is_a? String
      meta, self[:body] = File.read(@obj).split(/\n\n/, 2)
      @obj =~ /\/(\d{4}-\d{2}-\d{2})[^\/]*$/
      ($1 ? {:date => $1} : {}).merge(YAML.load(meta))
    elsif @obj.is_a? Hash
      @obj
    end.inject({}) {|h, (k,v)| h.merge(k.to_sym => v) }

  self.taint
  self.update data
  self[:date] = Time.parse(self[:date].gsub('/', '-')) rescue Time.now
  self
end
markdown(text) click to toggle source
# File lib/statikaj/article.rb, line 16
def markdown(text)
  Kramdown::Document.new(text).to_html
end
path() click to toggle source
# File lib/statikaj/article.rb, line 58
def path
  "/#{slug}"
end
render(source) click to toggle source
# File lib/statikaj/article.rb, line 12
def render(source)
  ERB.new(File.read(source.join("templates/pages/article.rhtml"))).result(binding)
end
slug() click to toggle source
# File lib/statikaj/article.rb, line 40
def slug
  self[:slug] || self[:title].slugize
end
summary() click to toggle source
# File lib/statikaj/article.rb, line 44
def summary
  sum = self[:body].split("~~~").first
  markdown(sum.length == self[:body].length ? sum : sum.strip.sub(/\.\Z/, '…'))
end
title() click to toggle source
# File lib/statikaj/article.rb, line 62
def title
  self[:title] || "an article"
end
to_html() click to toggle source
Calls superclass method
# File lib/statikaj/article.rb, line 78
def to_html
  self.load; super(:article, @config)
end
Also aliased as: to_s
to_s()
Alias for: to_html
url() click to toggle source
# File lib/statikaj/article.rb, line 49
def url
  "http://#{(@config[:url].sub("http://", '') + self.path).squeeze('/')}"
end
Also aliased as: permalink