front matter test case and further support

This commit is contained in:
Thomas Reynolds 2011-07-06 22:56:20 -07:00
parent ca5921a72e
commit edb60cd83a
5 changed files with 23 additions and 18 deletions

View file

@ -1,7 +1,7 @@
Feature: Local Data API
In order to abstract content from structure
Scenario: Rendering html with the feature enabled
Scenario: Rendering html
Given the Server is running
When I go to "/data.html"
Then I should see "One:Two"

View file

@ -1,7 +0,0 @@
---
layout: false
title: No title
---
<%= data.page.title %>
<%= data.page.inspect %>

View file

@ -0,0 +1,6 @@
---
layout: false
title: This is the title
---
h1= data.page.title

View file

@ -9,18 +9,21 @@ module Middleman::CoreExtensions::FrontMatter
::Tilt::register RDiscountTemplate, 'markdown', 'mkd', 'md'
::Tilt::register RedClothTemplate, 'textile'
::Tilt::register ERBTemplate, 'erb', 'rhtml'
::Tilt::register ErubisTemplate, 'erb', 'rhtml', 'erubis'
::Tilt::register SlimTemplate, 'slim'
::Tilt::register HamlTemplate, 'haml'
app.before do
result = resolve_template(request.path_info, :raise_exceptions => false)
if result
extensionless_path, template_engine = result
full_file_path = "#{extensionless_path}.#{template_engine}"
system_path = File.join(settings.views, full_file_path)
data, content = app.parse_front_matter(File.read(system_path))
request['custom_options'] = {}
%w(layout layout_engine).each do |opt|
if data.has_key?(opt)
options[opt.to_sym] = data.delete(opt)
request['custom_options'][opt.to_sym] = data.delete(opt)
end
end
@ -57,22 +60,23 @@ module Middleman::CoreExtensions::FrontMatter
end
end
# MARKDOWN
class RDiscountTemplate < ::Tilt::RDiscountTemplate
include Middleman::CoreExtensions::FrontMatter::YamlAware
end
# TEXTILE
class RedClothTemplate < ::Tilt::RedClothTemplate
include Middleman::CoreExtensions::FrontMatter::YamlAware
end
# ERb
class ERBTemplate < ::Tilt::ERBTemplate
include Middleman::CoreExtensions::FrontMatter::YamlAware
end
class HamlTemplate < ::Tilt::HamlTemplate
include Middleman::CoreExtensions::FrontMatter::YamlAware
end
class ErubisTemplate < ::Tilt::ErubisTemplate
class SlimTemplate < ::Slim::Template
include Middleman::CoreExtensions::FrontMatter::YamlAware
end
end

View file

@ -43,12 +43,12 @@ module Middleman
# Activate Yaml Data package
register Middleman::CoreExtensions::Data
# Parse YAML from templates
register Middleman::CoreExtensions::FrontMatter
# with_layout and page routing
register Middleman::CoreExtensions::Routing
# Parse YAML from templates
register Middleman::CoreExtensions::FrontMatter
set :default_extensions, [
:lorem
]
@ -92,6 +92,8 @@ module Middleman
private
# Internal method to look for templates and evaluate them if found
def process_request(options={})
options.merge!(request['custom_options'] || {})
old_layout = settings.current_layout
settings.layout(options[:layout]) if !options[:layout].nil?
layout = settings.fetch_layout_path.to_sym