Skip to content

Instantly share code, notes, and snippets.

@mcfiredrill
Created March 27, 2012 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcfiredrill/2218698 to your computer and use it in GitHub Desktop.
Save mcfiredrill/2218698 to your computer and use it in GitHub Desktop.
static blog dealie to embed into sinatra
require 'yaml'
class BlogArticle
SUMMARY_SEPARATOR="READMORE"
attr_reader :date, :title, :tags, :page
def initialize(file)
f = File.read(file)
y = YAML.load(f.split("---\n")[1])
@title = y[:title]
@date = Date.parse y[:date]
@page = f.split("---\n")[2]
@tags = []
y[:tags].split(',').each do |t|
@tags << t
end
end
def body
@page.gsub(/SUMMARY_SEPARATOR/, '')
end
def url
end
def summary
return @page.split(SUMMARY_SEPARATOR).first
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment