fix frontmatter test
This commit is contained in:
parent
ef89be163d
commit
dc231e42fb
1 changed files with 32 additions and 30 deletions
|
@ -22,44 +22,46 @@ module Middleman::CoreExtensions::FrontMatter
|
||||||
::Tilt::register HamlTemplate, 'haml'
|
::Tilt::register HamlTemplate, 'haml'
|
||||||
::Tilt.prefer(HamlTemplate)
|
::Tilt.prefer(HamlTemplate)
|
||||||
|
|
||||||
app.before do
|
app.after_feature_init do
|
||||||
result = resolve_template(request.path_info, :raise_exceptions => false)
|
app.before do
|
||||||
|
result = resolve_template(request.path_info, :raise_exceptions => false)
|
||||||
if result && Tilt.mappings.has_key?(result[1].to_s)
|
|
||||||
extensionless_path, template_engine = result
|
if result && Tilt.mappings.has_key?(result[1].to_s)
|
||||||
full_file_path = "#{extensionless_path}.#{template_engine}"
|
extensionless_path, template_engine = result
|
||||||
system_path = File.join(settings.views, full_file_path)
|
full_file_path = "#{extensionless_path}.#{template_engine}"
|
||||||
data, content = app.parse_front_matter(File.read(system_path))
|
system_path = File.join(settings.views, full_file_path)
|
||||||
|
data, content = app.parse_front_matter(File.read(system_path))
|
||||||
|
|
||||||
request['custom_options'] = {}
|
request['custom_options'] = {}
|
||||||
%w(layout layout_engine).each do |opt|
|
%w(layout layout_engine).each do |opt|
|
||||||
if data.has_key?(opt)
|
if data.has_key?(opt)
|
||||||
request['custom_options'][opt.to_sym] = data.delete(opt)
|
request['custom_options'][opt.to_sym] = data.delete(opt)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# Forward remaining data to helpers
|
# Forward remaining data to helpers
|
||||||
app.data_content("page", data)
|
app.data_content("page", data)
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
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
|
end
|
||||||
|
|
||||||
content = content.split(yaml_regex).last
|
|
||||||
end
|
end
|
||||||
|
|
||||||
data ||= {}
|
|
||||||
[data, content]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
|
|
Loading…
Add table
Reference in a new issue