2011-06-06 14:39:57 -04:00
|
|
|
require "yaml"
|
|
|
|
require "tilt"
|
|
|
|
|
|
|
|
module Middleman::Features::FrontMatter
|
|
|
|
class << self
|
|
|
|
def registered(app)
|
|
|
|
app.extend ClassMethods
|
2011-06-08 00:44:10 -04:00
|
|
|
|
2011-06-14 16:54:59 -04:00
|
|
|
::Tilt::register MarukuTemplate, 'markdown', 'mkd', 'md'
|
2011-06-08 00:44:10 -04:00
|
|
|
::Tilt::register MarukuTemplate, 'markdown', 'mkd', 'md'
|
|
|
|
::Tilt::register KramdownTemplate, 'markdown', 'mkd', 'md'
|
|
|
|
::Tilt::register BlueClothTemplate, 'markdown', 'mkd', 'md'
|
|
|
|
::Tilt::register RedcarpetTemplate, 'markdown', 'mkd', 'md'
|
|
|
|
::Tilt::register RDiscountTemplate, 'markdown', 'mkd', 'md'
|
|
|
|
::Tilt::register RedClothTemplate, 'textile'
|
2011-06-14 16:54:59 -04:00
|
|
|
::Tilt::register ERBTemplate, 'erb', 'rhtml'
|
|
|
|
::Tilt::register ErubisTemplate, 'erb', 'rhtml', 'erubis'
|
2011-06-06 14:39:57 -04:00
|
|
|
end
|
|
|
|
alias :included :registered
|
|
|
|
end
|
|
|
|
|
|
|
|
module ClassMethods
|
|
|
|
def parse_front_matter(content)
|
|
|
|
yaml_regex = /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
|
|
|
|
if content =~ yaml_regex
|
|
|
|
begin
|
|
|
|
data = YAML.load($1)
|
|
|
|
rescue => e
|
|
|
|
puts "YAML Exception: #{e.message}"
|
|
|
|
end
|
|
|
|
|
|
|
|
content = content.split(yaml_regex).last
|
|
|
|
end
|
|
|
|
|
|
|
|
data ||= {}
|
|
|
|
[data, content]
|
|
|
|
end
|
|
|
|
end
|
2011-06-08 00:44:10 -04:00
|
|
|
|
|
|
|
module YamlAware
|
|
|
|
def prepare
|
|
|
|
options, @data = Middleman::Server.parse_front_matter(@data)
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
2011-06-06 14:39:57 -04:00
|
|
|
|
2011-06-27 16:10:09 -04:00
|
|
|
# MARKDOWN
|
2011-06-08 00:44:10 -04:00
|
|
|
class RDiscountTemplate < ::Tilt::RDiscountTemplate
|
|
|
|
include Middleman::Features::FrontMatter::YamlAware
|
|
|
|
end
|
|
|
|
|
|
|
|
# TEXTILE
|
|
|
|
class RedClothTemplate < ::Tilt::RedClothTemplate
|
|
|
|
include Middleman::Features::FrontMatter::YamlAware
|
|
|
|
end
|
2011-06-14 16:54:59 -04:00
|
|
|
|
|
|
|
# ERb
|
|
|
|
class ERBTemplate < ::Tilt::ERBTemplate
|
|
|
|
include Middleman::Features::FrontMatter::YamlAware
|
|
|
|
end
|
|
|
|
|
|
|
|
class ErubisTemplate < ::Tilt::ErubisTemplate
|
|
|
|
include Middleman::Features::FrontMatter::YamlAware
|
|
|
|
end
|
2011-06-08 00:44:10 -04:00
|
|
|
end
|